govuk_frontend_toolkit 4.18.3 → 4.18.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/assets/.gitignore +1 -0
- data/app/assets/CHANGELOG.md +5 -0
- data/app/assets/Gruntfile.js +21 -22
- data/app/assets/README.md +4 -0
- data/app/assets/VERSION.txt +1 -1
- data/app/assets/docs/javascript.md +29 -28
- data/app/assets/javascripts/govuk/analytics/analytics.js +37 -37
- data/app/assets/javascripts/govuk/analytics/download-link-tracker.js +21 -21
- data/app/assets/javascripts/govuk/analytics/error-tracking.js +19 -19
- data/app/assets/javascripts/govuk/analytics/external-link-tracker.js +23 -24
- data/app/assets/javascripts/govuk/analytics/google-analytics-universal-tracker.js +71 -70
- data/app/assets/javascripts/govuk/analytics/mailto-link-tracker.js +20 -21
- data/app/assets/javascripts/govuk/analytics/print-intent.js +19 -20
- data/app/assets/javascripts/govuk/modules.js +33 -32
- data/app/assets/javascripts/govuk/modules/auto-track-event.js +18 -18
- data/app/assets/javascripts/govuk/multivariate-test.js +83 -85
- data/app/assets/javascripts/govuk/primary-links.js +39 -38
- data/app/assets/javascripts/govuk/selection-buttons.js +57 -58
- data/app/assets/javascripts/govuk/shim-links-with-button-role.js +14 -15
- data/app/assets/javascripts/govuk/stick-at-top-when-scrolling.js +70 -70
- data/app/assets/javascripts/govuk/stop-scrolling-at-footer.js +74 -75
- data/app/assets/javascripts/govuk_toolkit.js +1 -1
- data/app/assets/javascripts/stageprompt.js +24 -25
- data/app/assets/javascripts/vendor/jquery/jquery.player.min.js +1 -1
- data/app/assets/package.json +10 -3
- data/app/assets/spec/manifest.js +2 -0
- data/app/assets/spec/support/console-runner.js +0 -1
- data/app/assets/spec/unit/analytics/analytics.spec.js +51 -47
- data/app/assets/spec/unit/analytics/download-link-tracker.spec.js +59 -51
- data/app/assets/spec/unit/analytics/error-tracking.spec.js +35 -30
- data/app/assets/spec/unit/analytics/external-link-tracker.spec.js +69 -61
- data/app/assets/spec/unit/analytics/google-analytics-universal-tracker.spec.js +129 -122
- data/app/assets/spec/unit/analytics/mailto-link-tracker.spec.js +55 -47
- data/app/assets/spec/unit/modules.spec.js +82 -78
- data/app/assets/spec/unit/modules/auto-track-event.spec.js +45 -40
- data/app/assets/spec/unit/multivariate-test.spec.js +150 -145
- data/app/assets/spec/unit/primary-links.spec.js +53 -47
- data/app/assets/spec/unit/selection-button.spec.js +701 -693
- data/app/assets/spec/unit/shim-links-with-button-role.spec.js +33 -28
- data/app/assets/spec/unit/show-hide-content.spec.js +5 -1
- data/app/assets/spec/unit/stick-at-top-when-scrolling.spec.js +104 -107
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed31373cbe3fd29495e7825368045f0961c44b00
|
4
|
+
data.tar.gz: 5e1914525810948b8ea7ebeb6a863500c3b8dc7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6de494a693da9ee1f4650cec2e256de23b91b46627f035e7d688e4ab4625e9dfce928809b6f1ae921e32879bf8de4a32f5492111fe37f88e1742047510128e5c
|
7
|
+
data.tar.gz: 1581b99971f60eebab602605fe1bc1de2e32b69ccec3b4d00653759b9e8f000e76c63d5c3543f08829958e2bebf9bb045f51bf6410a8b19e7b669b4c260f5f34
|
data/app/assets/.gitignore
CHANGED
data/app/assets/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
# 4.18.4
|
2
|
+
|
3
|
+
- Lint codebase using standard ([PR #334](https://github.com/alphagov/govuk_frontend_toolkit/pull/334))
|
4
|
+
- Add semicolons at the start of IIFE's ([PR #339](https://github.com/alphagov/govuk_frontend_toolkit/pull/339))
|
5
|
+
|
1
6
|
# 4.18.3
|
2
7
|
|
3
8
|
- For smaller screens (<768px) ensure that the GOVUK.StickAtTopWhenScrolling JS "unsticks" the element which was previously "stuck" (by removing both the class which sets fixed positioning and the shim). ([PR #329](https://github.com/alphagov/govuk_frontend_toolkit/pull/329))
|
data/app/assets/Gruntfile.js
CHANGED
@@ -1,30 +1,29 @@
|
|
1
|
-
module.exports = function(grunt) {
|
2
|
-
var allSassFiles = []
|
3
|
-
|
4
|
-
var path = require('path');
|
1
|
+
module.exports = function (grunt) {
|
2
|
+
var allSassFiles = []
|
5
3
|
|
6
4
|
grunt.file.recurse(
|
7
|
-
|
8
|
-
function(abspath, rootdir, subdir, filename) {
|
9
|
-
|
10
|
-
|
5
|
+
'./stylesheets/',
|
6
|
+
function (abspath, rootdir, subdir, filename) {
|
7
|
+
var relpath
|
8
|
+
if (typeof subdir !== 'undefined') {
|
9
|
+
relpath = subdir + '/' + filename
|
11
10
|
} else {
|
12
|
-
|
11
|
+
relpath = filename
|
13
12
|
}
|
14
13
|
if (filename.match(/\.scss/)) {
|
15
|
-
allSassFiles.push("@import '" + relpath + "';")
|
14
|
+
allSassFiles.push("@import '" + relpath + "';")
|
16
15
|
}
|
17
16
|
}
|
18
|
-
)
|
17
|
+
)
|
19
18
|
|
20
19
|
grunt.file.write(
|
21
|
-
|
22
|
-
allSassFiles.join(
|
23
|
-
)
|
20
|
+
'./spec/stylesheets/test.scss',
|
21
|
+
allSassFiles.join('\n')
|
22
|
+
)
|
24
23
|
|
25
24
|
grunt.initConfig({
|
26
25
|
clean: {
|
27
|
-
sass: [
|
26
|
+
sass: ['spec/stylesheets/test*css']
|
28
27
|
},
|
29
28
|
jasmine: {
|
30
29
|
javascripts: {
|
@@ -53,12 +52,12 @@ module.exports = function(grunt) {
|
|
53
52
|
}
|
54
53
|
}
|
55
54
|
}
|
56
|
-
})
|
55
|
+
})
|
57
56
|
|
58
|
-
grunt.loadNpmTasks('grunt-contrib-clean')
|
59
|
-
grunt.loadNpmTasks('grunt-contrib-jasmine')
|
60
|
-
grunt.loadNpmTasks('grunt-contrib-sass')
|
57
|
+
grunt.loadNpmTasks('grunt-contrib-clean')
|
58
|
+
grunt.loadNpmTasks('grunt-contrib-jasmine')
|
59
|
+
grunt.loadNpmTasks('grunt-contrib-sass')
|
61
60
|
|
62
|
-
grunt.registerTask('test', ['sass', 'clean', 'jasmine'])
|
63
|
-
grunt.registerTask('default', ['test'])
|
64
|
-
}
|
61
|
+
grunt.registerTask('test', ['sass', 'clean', 'jasmine'])
|
62
|
+
grunt.registerTask('default', ['test'])
|
63
|
+
}
|
data/app/assets/README.md
CHANGED
@@ -94,6 +94,10 @@ npm install
|
|
94
94
|
npm test
|
95
95
|
```
|
96
96
|
|
97
|
+
### Standard JavaScript
|
98
|
+
`govuk_frontend_toolkit` uses [standardjs](http://standardjs.com/), an opinionated JavaScript linter.
|
99
|
+
All JavaScript files follow its conventions. [Read more](https://github.com/alphagov/govuk_prototype_kit/blob/master/docs/linting.md)
|
100
|
+
|
97
101
|
### Using the local test runner
|
98
102
|
|
99
103
|
The test suite can be run by opening the `./spec/support/LocalTestRunner.html` file in a browser for a more detailed trace of errors.
|
data/app/assets/VERSION.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
4.18.
|
1
|
+
4.18.4
|
@@ -23,7 +23,7 @@ Modules can be found and started by including `govuk/modules.js` and running:
|
|
23
23
|
|
24
24
|
```javascript
|
25
25
|
$(document).ready(function(){
|
26
|
-
GOVUK.modules.start()
|
26
|
+
GOVUK.modules.start()
|
27
27
|
});
|
28
28
|
```
|
29
29
|
|
@@ -32,15 +32,15 @@ This will attempt to find and start all modules in the page. For the example abo
|
|
32
32
|
The module will be instantiated and then its `start` method called. The HTML element with the `data-module` attribute is passed as the first argument to the module. This limits modules to acting only within their containing elements.
|
33
33
|
|
34
34
|
```javascript
|
35
|
-
module = new GOVUK.Modules[type]()
|
36
|
-
module.start(element)
|
35
|
+
module = new GOVUK.Modules[type]()
|
36
|
+
module.start(element)
|
37
37
|
```
|
38
38
|
|
39
39
|
Running `GOVUK.modules.start()` multiple times will have no additional affect. When a module is started a flag is set on the element using the data attribute `module-started`. `data-module-started` is a reserved attribute. It can however be called with an element as the first argument, to allow modules to be started in dynamically loaded content:
|
40
40
|
|
41
41
|
```javascript
|
42
|
-
var $container = $('.dynamic-content')
|
43
|
-
GOVUK.modules.start($container)
|
42
|
+
var $container = $('.dynamic-content')
|
43
|
+
GOVUK.modules.start($container)
|
44
44
|
```
|
45
45
|
|
46
46
|
### Module structure
|
@@ -49,14 +49,15 @@ A module must add its constructor to `GOVUK.Modules` and it must have a `start`
|
|
49
49
|
The simplest module looks like:
|
50
50
|
|
51
51
|
```javascript
|
52
|
-
(function(Modules) {
|
53
|
-
|
52
|
+
;(function(Modules) {
|
53
|
+
'use strict'
|
54
|
+
|
54
55
|
Modules.SomeModule = function() {
|
55
56
|
this.start = function($element) {
|
56
57
|
// module code
|
57
58
|
}
|
58
|
-
}
|
59
|
-
})(window.GOVUK.Modules)
|
59
|
+
}
|
60
|
+
})(window.GOVUK.Modules)
|
60
61
|
```
|
61
62
|
|
62
63
|
### Writing modules
|
@@ -80,8 +81,8 @@ Beginning with a set of event listeners clearly indicates the module’s intenti
|
|
80
81
|
|
81
82
|
```js
|
82
83
|
this.start = function($element) {
|
83
|
-
$element.on('click', '.js-toggle', toggle)
|
84
|
-
$element.on('click', '.js-cancel', cancel)
|
84
|
+
$element.on('click', '.js-toggle', toggle)
|
85
|
+
$element.on('click', '.js-cancel', cancel)
|
85
86
|
}
|
86
87
|
```
|
87
88
|
|
@@ -302,13 +303,13 @@ To add it to all lists which have items with the class `primary-item` use
|
|
302
303
|
something like:
|
303
304
|
|
304
305
|
```javascript
|
305
|
-
GOVUK.primaryLinks.init('.primary-item')
|
306
|
+
GOVUK.primaryLinks.init('.primary-item')
|
306
307
|
```
|
307
308
|
|
308
309
|
Or to add it just to that list you could use:
|
309
310
|
|
310
311
|
```javascript
|
311
|
-
new GOVUK.PrimaryList($('#primary-list'), '.primary-item')
|
312
|
+
new GOVUK.PrimaryList($('#primary-list'), '.primary-item')
|
312
313
|
```
|
313
314
|
|
314
315
|
## Stick at top when scrolling
|
@@ -333,7 +334,7 @@ The following would cause the element to stay when you scroll:
|
|
333
334
|
```
|
334
335
|
|
335
336
|
```javascript
|
336
|
-
GOVUK.stickAtTopWhenScrolling.init()
|
337
|
+
GOVUK.stickAtTopWhenScrolling.init()
|
337
338
|
```
|
338
339
|
|
339
340
|
If you also include the `stopScrollingAtFooter` JavaScript this will also try
|
@@ -356,14 +357,14 @@ When the input is focused or its `checked` attribute is set, classes are added t
|
|
356
357
|
To apply this behaviour to elements with the above HTML pattern, call the `GOVUK.SelectionButtons` constructor with their inputs:
|
357
358
|
|
358
359
|
```
|
359
|
-
var $buttons = $("label input[type='radio'], label input[type='checkbox']")
|
360
|
-
var selectionButtons = new GOVUK.SelectionButtons($buttons)
|
360
|
+
var $buttons = $("label input[type='radio'], label input[type='checkbox']")
|
361
|
+
var selectionButtons = new GOVUK.SelectionButtons($buttons)
|
361
362
|
```
|
362
363
|
|
363
364
|
You can also call `GOVUK.SelectionButtons` with a selector:
|
364
365
|
|
365
366
|
```
|
366
|
-
var selectionButtons = new GOVUK.SelectionButtons("label input[type='radio'], label input[type='checkbox']")
|
367
|
+
var selectionButtons = new GOVUK.SelectionButtons("label input[type='radio'], label input[type='checkbox']")
|
367
368
|
```
|
368
369
|
|
369
370
|
This will bind all events to the document, meaning any changes to content (for example, by AJAX) will not effect the button's behaviour.
|
@@ -371,10 +372,10 @@ This will bind all events to the document, meaning any changes to content (for e
|
|
371
372
|
The classes that get added to the `<label>` tags can be passed in as options:
|
372
373
|
|
373
374
|
```
|
374
|
-
var $buttons = $("label input[type='radio'], label input[type='checkbox']")
|
375
|
-
var selectionButtons = new GOVUK.SelectionButtons($buttons, { focusedClass : 'selectable-focused', selectedClass : 'selectable-selected' })
|
375
|
+
var $buttons = $("label input[type='radio'], label input[type='checkbox']")
|
376
|
+
var selectionButtons = new GOVUK.SelectionButtons($buttons, { focusedClass : 'selectable-focused', selectedClass : 'selectable-selected' })
|
376
377
|
|
377
|
-
var selectionButtons = new GOVUK.SelectionButtons("label input[type='radio'], label input[type='checkbox']", { focusedClass : 'selectable-focused', selectedClass : 'selectable-selected' })
|
378
|
+
var selectionButtons = new GOVUK.SelectionButtons("label input[type='radio'], label input[type='checkbox']", { focusedClass : 'selectable-focused', selectedClass : 'selectable-selected' })
|
378
379
|
```
|
379
380
|
|
380
381
|
#### destroy method
|
@@ -393,8 +394,8 @@ The previous method of calling selection buttons is now deprecated. If you need
|
|
393
394
|
|
394
395
|
```
|
395
396
|
GOVUK.selectionButtons = function (elms, opts) {
|
396
|
-
new GOVUK.SelectionButtons(elms, opts)
|
397
|
-
}
|
397
|
+
new GOVUK.SelectionButtons(elms, opts)
|
398
|
+
}
|
398
399
|
```
|
399
400
|
|
400
401
|
This method will mean the `destroy` method is not available to call.
|
@@ -412,7 +413,7 @@ By default, this behaviour will only be applied to links with a role of button.
|
|
412
413
|
```
|
413
414
|
|
414
415
|
```javascript
|
415
|
-
GOVUK.shimLinksWithButtonRole.init()
|
416
|
+
GOVUK.shimLinksWithButtonRole.init()
|
416
417
|
```
|
417
418
|
|
418
419
|
If you need to override the elements this is applied to then you can do that by passing in a custom selector to the initialiser:
|
@@ -420,7 +421,7 @@ If you need to override the elements this is applied to then you can do that by
|
|
420
421
|
```javascript
|
421
422
|
GOVUK.shimLinksWithButtonRole.init({
|
422
423
|
selector: '.my-class'
|
423
|
-
})
|
424
|
+
})
|
424
425
|
```
|
425
426
|
|
426
427
|
It’s also possible to define more or different keycodes to activate against:
|
@@ -457,8 +458,8 @@ When the input's `checked` attribute is set, the show/hide content's `.js-hidden
|
|
457
458
|
To apply this behaviour to elements with the above HTML pattern, call the `GOVUK.ShowHideContent` constructor:
|
458
459
|
|
459
460
|
```
|
460
|
-
var showHideContent = new GOVUK.ShowHideContent()
|
461
|
-
showHideContent.init()
|
461
|
+
var showHideContent = new GOVUK.ShowHideContent()
|
462
|
+
showHideContent.init()
|
462
463
|
```
|
463
464
|
|
464
465
|
This will bind two event handlers to $(document.body), one for radio inputs and one for checkboxes. By listening for events bubbling up to the `body` tag, additional show/hide content added to the page will still be picked up after `.init()` is called.
|
@@ -466,6 +467,6 @@ This will bind two event handlers to $(document.body), one for radio inputs and
|
|
466
467
|
Alternatively, pass in your own selector. In the example below, event handlers are bound to the form instead.
|
467
468
|
|
468
469
|
```
|
469
|
-
var showHideContent = new GOVUK.ShowHideContent()
|
470
|
-
showHideContent.init($('form.example'))
|
470
|
+
var showHideContent = new GOVUK.ShowHideContent()
|
471
|
+
showHideContent.init($('form.example'))
|
471
472
|
```
|
@@ -1,38 +1,38 @@
|
|
1
|
-
(function(global) {
|
2
|
-
|
1
|
+
;(function (global) {
|
2
|
+
'use strict'
|
3
3
|
|
4
|
-
var GOVUK = global.GOVUK || {}
|
4
|
+
var GOVUK = global.GOVUK || {}
|
5
5
|
|
6
6
|
// For usage and initialisation see:
|
7
7
|
// https://github.com/alphagov/govuk_frontend_toolkit/blob/master/docs/analytics.md#create-an-analytics-tracker
|
8
8
|
|
9
|
-
var Analytics = function(config) {
|
10
|
-
this.trackers = []
|
11
|
-
if (typeof config.universalId
|
12
|
-
var universalId = config.universalId
|
13
|
-
delete config.universalId
|
14
|
-
this.trackers.push(new GOVUK.GoogleAnalyticsUniversalTracker(universalId, config))
|
9
|
+
var Analytics = function (config) {
|
10
|
+
this.trackers = []
|
11
|
+
if (typeof config.universalId !== 'undefined') {
|
12
|
+
var universalId = config.universalId
|
13
|
+
delete config.universalId
|
14
|
+
this.trackers.push(new GOVUK.GoogleAnalyticsUniversalTracker(universalId, config))
|
15
15
|
}
|
16
|
-
}
|
16
|
+
}
|
17
17
|
|
18
|
-
Analytics.prototype.sendToTrackers = function(method, args) {
|
18
|
+
Analytics.prototype.sendToTrackers = function (method, args) {
|
19
19
|
for (var i = 0, l = this.trackers.length; i < l; i++) {
|
20
|
-
var tracker = this.trackers[i]
|
21
|
-
|
20
|
+
var tracker = this.trackers[i]
|
21
|
+
var fn = tracker[method]
|
22
22
|
|
23
|
-
if (typeof fn ===
|
24
|
-
fn.apply(tracker, args)
|
23
|
+
if (typeof fn === 'function') {
|
24
|
+
fn.apply(tracker, args)
|
25
25
|
}
|
26
26
|
}
|
27
|
-
}
|
27
|
+
}
|
28
28
|
|
29
|
-
Analytics.load = function() {
|
30
|
-
GOVUK.GoogleAnalyticsUniversalTracker.load()
|
31
|
-
}
|
29
|
+
Analytics.load = function () {
|
30
|
+
GOVUK.GoogleAnalyticsUniversalTracker.load()
|
31
|
+
}
|
32
32
|
|
33
|
-
Analytics.prototype.trackPageview = function(path, title, options) {
|
34
|
-
this.sendToTrackers('trackPageview', arguments)
|
35
|
-
}
|
33
|
+
Analytics.prototype.trackPageview = function (path, title, options) {
|
34
|
+
this.sendToTrackers('trackPageview', arguments)
|
35
|
+
}
|
36
36
|
|
37
37
|
/*
|
38
38
|
https://developers.google.com/analytics/devguides/collection/analyticsjs/events
|
@@ -40,30 +40,30 @@
|
|
40
40
|
options.value – Values must be non-negative. Useful to pass counts
|
41
41
|
options.nonInteraction – Prevent event from impacting bounce rate
|
42
42
|
*/
|
43
|
-
Analytics.prototype.trackEvent = function(category, action, options) {
|
44
|
-
this.sendToTrackers('trackEvent', arguments)
|
45
|
-
}
|
43
|
+
Analytics.prototype.trackEvent = function (category, action, options) {
|
44
|
+
this.sendToTrackers('trackEvent', arguments)
|
45
|
+
}
|
46
46
|
|
47
|
-
Analytics.prototype.trackShare = function(network) {
|
48
|
-
this.sendToTrackers('trackSocial', [network, 'share', location.pathname])
|
49
|
-
}
|
47
|
+
Analytics.prototype.trackShare = function (network) {
|
48
|
+
this.sendToTrackers('trackSocial', [network, 'share', global.location.pathname])
|
49
|
+
}
|
50
50
|
|
51
51
|
/*
|
52
52
|
The custom dimension index must be configured within the
|
53
53
|
Universal Analytics profile
|
54
54
|
*/
|
55
|
-
Analytics.prototype.setDimension = function(index, value) {
|
56
|
-
this.sendToTrackers('setDimension', arguments)
|
57
|
-
}
|
55
|
+
Analytics.prototype.setDimension = function (index, value) {
|
56
|
+
this.sendToTrackers('setDimension', arguments)
|
57
|
+
}
|
58
58
|
|
59
59
|
/*
|
60
60
|
Add a beacon to track a page in another GA account on another domain.
|
61
61
|
*/
|
62
|
-
Analytics.prototype.addLinkedTrackerDomain = function(trackerId, name, domain) {
|
63
|
-
this.sendToTrackers('addLinkedTrackerDomain', arguments)
|
64
|
-
}
|
62
|
+
Analytics.prototype.addLinkedTrackerDomain = function (trackerId, name, domain) {
|
63
|
+
this.sendToTrackers('addLinkedTrackerDomain', arguments)
|
64
|
+
}
|
65
65
|
|
66
|
-
GOVUK.Analytics = Analytics
|
66
|
+
GOVUK.Analytics = Analytics
|
67
67
|
|
68
|
-
global.GOVUK = GOVUK
|
69
|
-
})(window)
|
68
|
+
global.GOVUK = GOVUK
|
69
|
+
})(window)
|
@@ -1,41 +1,41 @@
|
|
1
|
-
(function(global) {
|
2
|
-
|
1
|
+
;(function (global) {
|
2
|
+
'use strict'
|
3
3
|
|
4
|
-
var $ = global.jQuery
|
5
|
-
var GOVUK = global.GOVUK || {}
|
4
|
+
var $ = global.jQuery
|
5
|
+
var GOVUK = global.GOVUK || {}
|
6
6
|
|
7
|
-
GOVUK.analyticsPlugins = GOVUK.analyticsPlugins || {}
|
7
|
+
GOVUK.analyticsPlugins = GOVUK.analyticsPlugins || {}
|
8
8
|
GOVUK.analyticsPlugins.downloadLinkTracker = function (options) {
|
9
|
-
|
10
|
-
|
9
|
+
options = options || {}
|
10
|
+
var downloadLinkSelector = options.selector
|
11
11
|
|
12
12
|
if (downloadLinkSelector) {
|
13
|
-
$('body').on('click', downloadLinkSelector, trackDownload)
|
13
|
+
$('body').on('click', downloadLinkSelector, trackDownload)
|
14
14
|
}
|
15
15
|
|
16
|
-
function trackDownload(evt) {
|
17
|
-
var $link = getLinkFromEvent(evt)
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
function trackDownload (evt) {
|
17
|
+
var $link = getLinkFromEvent(evt)
|
18
|
+
var href = $link.attr('href')
|
19
|
+
var evtOptions = {transport: 'beacon'}
|
20
|
+
var linkText = $.trim($link.text())
|
21
21
|
|
22
22
|
if (linkText) {
|
23
|
-
evtOptions.label = linkText
|
23
|
+
evtOptions.label = linkText
|
24
24
|
}
|
25
25
|
|
26
|
-
GOVUK.analytics.trackEvent('Download Link Clicked', href, evtOptions)
|
26
|
+
GOVUK.analytics.trackEvent('Download Link Clicked', href, evtOptions)
|
27
27
|
}
|
28
28
|
|
29
|
-
function getLinkFromEvent(evt) {
|
30
|
-
var $target = $(evt.target)
|
29
|
+
function getLinkFromEvent (evt) {
|
30
|
+
var $target = $(evt.target)
|
31
31
|
|
32
32
|
if (!$target.is('a')) {
|
33
|
-
$target = $target.parents('a')
|
33
|
+
$target = $target.parents('a')
|
34
34
|
}
|
35
35
|
|
36
|
-
return $target
|
36
|
+
return $target
|
37
37
|
}
|
38
38
|
}
|
39
39
|
|
40
|
-
global.GOVUK = GOVUK
|
41
|
-
})(window)
|
40
|
+
global.GOVUK = GOVUK
|
41
|
+
})(window)
|
@@ -1,51 +1,51 @@
|
|
1
1
|
// Extension to track errors using google analytics as a data store.
|
2
|
-
(function(global) {
|
3
|
-
|
2
|
+
;(function (global) {
|
3
|
+
'use strict'
|
4
4
|
|
5
|
-
var GOVUK = global.GOVUK || {}
|
5
|
+
var GOVUK = global.GOVUK || {}
|
6
6
|
|
7
|
-
GOVUK.analyticsPlugins = GOVUK.analyticsPlugins || {}
|
7
|
+
GOVUK.analyticsPlugins = GOVUK.analyticsPlugins || {}
|
8
8
|
|
9
9
|
GOVUK.analyticsPlugins.error = function (options) {
|
10
|
-
|
11
|
-
|
10
|
+
options = options || {}
|
11
|
+
var filenameMustMatch = options.filenameMustMatch
|
12
12
|
|
13
13
|
var trackJavaScriptError = function (e) {
|
14
|
-
var errorFilename = e.filename
|
15
|
-
|
14
|
+
var errorFilename = e.filename
|
15
|
+
var errorSource = errorFilename + ': ' + e.lineno
|
16
16
|
|
17
17
|
if (shouldTrackThisError(errorFilename)) {
|
18
18
|
GOVUK.analytics.trackEvent('JavaScript Error', e.message, {
|
19
19
|
label: errorSource,
|
20
20
|
value: 1,
|
21
21
|
nonInteraction: true
|
22
|
-
})
|
22
|
+
})
|
23
23
|
}
|
24
|
-
}
|
24
|
+
}
|
25
25
|
|
26
|
-
function shouldTrackThisError(errorFilename) {
|
26
|
+
function shouldTrackThisError (errorFilename) {
|
27
27
|
// Errors in page should always be tracked
|
28
28
|
// If there's no filename filter, everything is tracked
|
29
29
|
if (!errorFilename || !filenameMustMatch) {
|
30
|
-
return true
|
30
|
+
return true
|
31
31
|
}
|
32
32
|
|
33
33
|
// If there's a filter and the error matches it, track it
|
34
34
|
if (filenameMustMatch.test(errorFilename)) {
|
35
|
-
return true
|
35
|
+
return true
|
36
36
|
}
|
37
37
|
|
38
|
-
return false
|
38
|
+
return false
|
39
39
|
}
|
40
40
|
|
41
41
|
if (global.addEventListener) {
|
42
|
-
global.addEventListener('error', trackJavaScriptError, false)
|
42
|
+
global.addEventListener('error', trackJavaScriptError, false)
|
43
43
|
} else if (global.attachEvent) {
|
44
|
-
global.attachEvent('onerror', trackJavaScriptError)
|
44
|
+
global.attachEvent('onerror', trackJavaScriptError)
|
45
45
|
} else {
|
46
|
-
global.onerror = trackJavaScriptError
|
46
|
+
global.onerror = trackJavaScriptError
|
47
47
|
}
|
48
48
|
}
|
49
49
|
|
50
|
-
global.GOVUK = GOVUK
|
51
|
-
})(window)
|
50
|
+
global.GOVUK = GOVUK
|
51
|
+
})(window)
|