-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Do note merge] [Request for comments] Lint codebase using standard (#…
…334) * Add standard as linter to npm test * Run standard --fix to fix most problems automatically * Fix manual linting issues without logic changes * Use strict equals to pass linting * Ignore _SpecRunner.html generated file from testing * Silence no new side effect eslint linting This indicates an issue with our module pattern wherein we don't need to be using a class pattern for some of our code since there's no returned instance that is being used. If this is the case that there are public methods exposed on an instance we should test those... * Add linting note to README
- Loading branch information
1 parent
cded78c
commit ca84786
Showing
38 changed files
with
2,230 additions
and
2,150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ node_modules/ | |
.sass-cache | ||
npm-debug.log | ||
spec/stylesheets | ||
_SpecRunner.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,69 @@ | ||
(function(global) { | ||
"use strict"; | ||
(function (global) { | ||
'use strict' | ||
|
||
var GOVUK = global.GOVUK || {}; | ||
var GOVUK = global.GOVUK || {} | ||
|
||
// For usage and initialisation see: | ||
// https://github.com/alphagov/govuk_frontend_toolkit/blob/master/docs/analytics.md#create-an-analytics-tracker | ||
|
||
var Analytics = function(config) { | ||
this.trackers = []; | ||
if (typeof config.universalId != 'undefined') { | ||
var universalId = config.universalId; | ||
delete config.universalId; | ||
this.trackers.push(new GOVUK.GoogleAnalyticsUniversalTracker(universalId, config)); | ||
var Analytics = function (config) { | ||
this.trackers = [] | ||
if (typeof config.universalId !== 'undefined') { | ||
var universalId = config.universalId | ||
delete config.universalId | ||
this.trackers.push(new GOVUK.GoogleAnalyticsUniversalTracker(universalId, config)) | ||
} | ||
}; | ||
} | ||
|
||
Analytics.prototype.sendToTrackers = function(method, args) { | ||
Analytics.prototype.sendToTrackers = function (method, args) { | ||
for (var i = 0, l = this.trackers.length; i < l; i++) { | ||
var tracker = this.trackers[i], | ||
fn = tracker[method]; | ||
var tracker = this.trackers[i] | ||
var fn = tracker[method] | ||
|
||
if (typeof fn === "function") { | ||
fn.apply(tracker, args); | ||
if (typeof fn === 'function') { | ||
fn.apply(tracker, args) | ||
} | ||
} | ||
}; | ||
} | ||
|
||
Analytics.load = function() { | ||
GOVUK.GoogleAnalyticsUniversalTracker.load(); | ||
}; | ||
Analytics.load = function () { | ||
GOVUK.GoogleAnalyticsUniversalTracker.load() | ||
} | ||
|
||
Analytics.prototype.trackPageview = function(path, title, options) { | ||
this.sendToTrackers('trackPageview', arguments); | ||
}; | ||
Analytics.prototype.trackPageview = function (path, title, options) { | ||
this.sendToTrackers('trackPageview', arguments) | ||
} | ||
|
||
/* | ||
https://developers.google.com/analytics/devguides/collection/analyticsjs/events | ||
options.label – Useful for categorizing events (eg nav buttons) | ||
options.value – Values must be non-negative. Useful to pass counts | ||
options.nonInteraction – Prevent event from impacting bounce rate | ||
*/ | ||
Analytics.prototype.trackEvent = function(category, action, options) { | ||
this.sendToTrackers('trackEvent', arguments); | ||
}; | ||
Analytics.prototype.trackEvent = function (category, action, options) { | ||
this.sendToTrackers('trackEvent', arguments) | ||
} | ||
|
||
Analytics.prototype.trackShare = function(network) { | ||
this.sendToTrackers('trackSocial', [network, 'share', location.pathname]); | ||
}; | ||
Analytics.prototype.trackShare = function (network) { | ||
this.sendToTrackers('trackSocial', [network, 'share', global.location.pathname]) | ||
} | ||
|
||
/* | ||
The custom dimension index must be configured within the | ||
Universal Analytics profile | ||
*/ | ||
Analytics.prototype.setDimension = function(index, value) { | ||
this.sendToTrackers('setDimension', arguments); | ||
}; | ||
Analytics.prototype.setDimension = function (index, value) { | ||
this.sendToTrackers('setDimension', arguments) | ||
} | ||
|
||
/* | ||
Add a beacon to track a page in another GA account on another domain. | ||
*/ | ||
Analytics.prototype.addLinkedTrackerDomain = function(trackerId, name, domain) { | ||
this.sendToTrackers('addLinkedTrackerDomain', arguments); | ||
}; | ||
Analytics.prototype.addLinkedTrackerDomain = function (trackerId, name, domain) { | ||
this.sendToTrackers('addLinkedTrackerDomain', arguments) | ||
} | ||
|
||
GOVUK.Analytics = Analytics; | ||
GOVUK.Analytics = Analytics | ||
|
||
global.GOVUK = GOVUK; | ||
})(window); | ||
global.GOVUK = GOVUK | ||
})(window) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,41 @@ | ||
(function(global) { | ||
"use strict"; | ||
(function (global) { | ||
'use strict' | ||
|
||
var $ = global.jQuery; | ||
var GOVUK = global.GOVUK || {}; | ||
var $ = global.jQuery | ||
var GOVUK = global.GOVUK || {} | ||
|
||
GOVUK.analyticsPlugins = GOVUK.analyticsPlugins || {}; | ||
GOVUK.analyticsPlugins = GOVUK.analyticsPlugins || {} | ||
GOVUK.analyticsPlugins.downloadLinkTracker = function (options) { | ||
var options = options || {}, | ||
downloadLinkSelector = options.selector; | ||
options = options || {} | ||
var downloadLinkSelector = options.selector | ||
|
||
if (downloadLinkSelector) { | ||
$('body').on('click', downloadLinkSelector, trackDownload); | ||
$('body').on('click', downloadLinkSelector, trackDownload) | ||
} | ||
|
||
function trackDownload(evt) { | ||
var $link = getLinkFromEvent(evt), | ||
href = $link.attr('href'), | ||
evtOptions = {transport: 'beacon'}, | ||
linkText = $.trim($link.text()); | ||
function trackDownload (evt) { | ||
var $link = getLinkFromEvent(evt) | ||
var href = $link.attr('href') | ||
var evtOptions = {transport: 'beacon'} | ||
var linkText = $.trim($link.text()) | ||
|
||
if (linkText) { | ||
evtOptions.label = linkText; | ||
evtOptions.label = linkText | ||
} | ||
|
||
GOVUK.analytics.trackEvent('Download Link Clicked', href, evtOptions); | ||
GOVUK.analytics.trackEvent('Download Link Clicked', href, evtOptions) | ||
} | ||
|
||
function getLinkFromEvent(evt) { | ||
var $target = $(evt.target); | ||
function getLinkFromEvent (evt) { | ||
var $target = $(evt.target) | ||
|
||
if (!$target.is('a')) { | ||
$target = $target.parents('a'); | ||
$target = $target.parents('a') | ||
} | ||
|
||
return $target; | ||
return $target | ||
} | ||
} | ||
|
||
global.GOVUK = GOVUK; | ||
})(window); | ||
global.GOVUK = GOVUK | ||
})(window) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,51 @@ | ||
// Extension to track errors using google analytics as a data store. | ||
(function(global) { | ||
"use strict"; | ||
(function (global) { | ||
'use strict' | ||
|
||
var GOVUK = global.GOVUK || {}; | ||
var GOVUK = global.GOVUK || {} | ||
|
||
GOVUK.analyticsPlugins = GOVUK.analyticsPlugins || {}; | ||
GOVUK.analyticsPlugins = GOVUK.analyticsPlugins || {} | ||
|
||
GOVUK.analyticsPlugins.error = function (options) { | ||
var options = options || {}, | ||
filenameMustMatch = options.filenameMustMatch; | ||
options = options || {} | ||
var filenameMustMatch = options.filenameMustMatch | ||
|
||
var trackJavaScriptError = function (e) { | ||
var errorFilename = e.filename, | ||
errorSource = errorFilename + ': ' + e.lineno; | ||
var errorFilename = e.filename | ||
var errorSource = errorFilename + ': ' + e.lineno | ||
|
||
if (shouldTrackThisError(errorFilename)) { | ||
GOVUK.analytics.trackEvent('JavaScript Error', e.message, { | ||
label: errorSource, | ||
value: 1, | ||
nonInteraction: true | ||
}); | ||
}) | ||
} | ||
}; | ||
} | ||
|
||
function shouldTrackThisError(errorFilename) { | ||
function shouldTrackThisError (errorFilename) { | ||
// Errors in page should always be tracked | ||
// If there's no filename filter, everything is tracked | ||
if (!errorFilename || !filenameMustMatch) { | ||
return true; | ||
return true | ||
} | ||
|
||
// If there's a filter and the error matches it, track it | ||
if (filenameMustMatch.test(errorFilename)) { | ||
return true; | ||
return true | ||
} | ||
|
||
return false; | ||
return false | ||
} | ||
|
||
if (global.addEventListener) { | ||
global.addEventListener('error', trackJavaScriptError, false); | ||
global.addEventListener('error', trackJavaScriptError, false) | ||
} else if (global.attachEvent) { | ||
global.attachEvent('onerror', trackJavaScriptError); | ||
global.attachEvent('onerror', trackJavaScriptError) | ||
} else { | ||
global.onerror = trackJavaScriptError; | ||
global.onerror = trackJavaScriptError | ||
} | ||
} | ||
|
||
global.GOVUK = GOVUK; | ||
})(window); | ||
global.GOVUK = GOVUK | ||
})(window) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,43 @@ | ||
(function(global) { | ||
"use strict"; | ||
(function (global) { | ||
'use strict' | ||
|
||
var $ = global.jQuery; | ||
var GOVUK = global.GOVUK || {}; | ||
var $ = global.jQuery | ||
var GOVUK = global.GOVUK || {} | ||
|
||
GOVUK.analyticsPlugins = GOVUK.analyticsPlugins || {}; | ||
GOVUK.analyticsPlugins = GOVUK.analyticsPlugins || {} | ||
GOVUK.analyticsPlugins.externalLinkTracker = function () { | ||
var currentHost = GOVUK.analyticsPlugins.externalLinkTracker.getHostname() | ||
var externalLinkSelector = 'a[href^="http"]:not(a[href*="' + currentHost + '"])' | ||
|
||
var currentHost = GOVUK.analyticsPlugins.externalLinkTracker.getHostname(), | ||
externalLinkSelector = 'a[href^="http"]:not(a[href*="' + currentHost + '"])'; | ||
$('body').on('click', externalLinkSelector, trackClickEvent) | ||
|
||
$('body').on('click', externalLinkSelector, trackClickEvent); | ||
|
||
function trackClickEvent(evt) { | ||
var $link = getLinkFromEvent(evt), | ||
options = {transport: 'beacon'}, | ||
href = $link.attr('href'), | ||
linkText = $.trim($link.text()); | ||
function trackClickEvent (evt) { | ||
var $link = getLinkFromEvent(evt) | ||
var options = {transport: 'beacon'} | ||
var href = $link.attr('href') | ||
var linkText = $.trim($link.text()) | ||
|
||
if (linkText) { | ||
options.label = linkText; | ||
options.label = linkText | ||
} | ||
|
||
GOVUK.analytics.trackEvent('External Link Clicked', href, options); | ||
GOVUK.analytics.trackEvent('External Link Clicked', href, options) | ||
} | ||
|
||
function getLinkFromEvent(evt) { | ||
var $target = $(evt.target); | ||
function getLinkFromEvent (evt) { | ||
var $target = $(evt.target) | ||
|
||
if (!$target.is('a')) { | ||
$target = $target.parents('a'); | ||
$target = $target.parents('a') | ||
} | ||
|
||
return $target; | ||
return $target | ||
} | ||
} | ||
|
||
GOVUK.analyticsPlugins.externalLinkTracker.getHostname = function() { | ||
return global.location.hostname; | ||
GOVUK.analyticsPlugins.externalLinkTracker.getHostname = function () { | ||
return global.location.hostname | ||
} | ||
|
||
global.GOVUK = GOVUK; | ||
})(window); | ||
global.GOVUK = GOVUK | ||
})(window) |
Oops, something went wrong.