govuk_frontend_toolkit 4.18.3 → 4.18.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/.gitignore +1 -0
  3. data/app/assets/CHANGELOG.md +5 -0
  4. data/app/assets/Gruntfile.js +21 -22
  5. data/app/assets/README.md +4 -0
  6. data/app/assets/VERSION.txt +1 -1
  7. data/app/assets/docs/javascript.md +29 -28
  8. data/app/assets/javascripts/govuk/analytics/analytics.js +37 -37
  9. data/app/assets/javascripts/govuk/analytics/download-link-tracker.js +21 -21
  10. data/app/assets/javascripts/govuk/analytics/error-tracking.js +19 -19
  11. data/app/assets/javascripts/govuk/analytics/external-link-tracker.js +23 -24
  12. data/app/assets/javascripts/govuk/analytics/google-analytics-universal-tracker.js +71 -70
  13. data/app/assets/javascripts/govuk/analytics/mailto-link-tracker.js +20 -21
  14. data/app/assets/javascripts/govuk/analytics/print-intent.js +19 -20
  15. data/app/assets/javascripts/govuk/modules.js +33 -32
  16. data/app/assets/javascripts/govuk/modules/auto-track-event.js +18 -18
  17. data/app/assets/javascripts/govuk/multivariate-test.js +83 -85
  18. data/app/assets/javascripts/govuk/primary-links.js +39 -38
  19. data/app/assets/javascripts/govuk/selection-buttons.js +57 -58
  20. data/app/assets/javascripts/govuk/shim-links-with-button-role.js +14 -15
  21. data/app/assets/javascripts/govuk/stick-at-top-when-scrolling.js +70 -70
  22. data/app/assets/javascripts/govuk/stop-scrolling-at-footer.js +74 -75
  23. data/app/assets/javascripts/govuk_toolkit.js +1 -1
  24. data/app/assets/javascripts/stageprompt.js +24 -25
  25. data/app/assets/javascripts/vendor/jquery/jquery.player.min.js +1 -1
  26. data/app/assets/package.json +10 -3
  27. data/app/assets/spec/manifest.js +2 -0
  28. data/app/assets/spec/support/console-runner.js +0 -1
  29. data/app/assets/spec/unit/analytics/analytics.spec.js +51 -47
  30. data/app/assets/spec/unit/analytics/download-link-tracker.spec.js +59 -51
  31. data/app/assets/spec/unit/analytics/error-tracking.spec.js +35 -30
  32. data/app/assets/spec/unit/analytics/external-link-tracker.spec.js +69 -61
  33. data/app/assets/spec/unit/analytics/google-analytics-universal-tracker.spec.js +129 -122
  34. data/app/assets/spec/unit/analytics/mailto-link-tracker.spec.js +55 -47
  35. data/app/assets/spec/unit/modules.spec.js +82 -78
  36. data/app/assets/spec/unit/modules/auto-track-event.spec.js +45 -40
  37. data/app/assets/spec/unit/multivariate-test.spec.js +150 -145
  38. data/app/assets/spec/unit/primary-links.spec.js +53 -47
  39. data/app/assets/spec/unit/selection-button.spec.js +701 -693
  40. data/app/assets/spec/unit/shim-links-with-button-role.spec.js +33 -28
  41. data/app/assets/spec/unit/show-hide-content.spec.js +5 -1
  42. data/app/assets/spec/unit/stick-at-top-when-scrolling.spec.js +104 -107
  43. metadata +2 -2
@@ -1,44 +1,43 @@
1
- (function(global) {
2
- "use strict";
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.externalLinkTracker = function () {
9
+ var currentHost = GOVUK.analyticsPlugins.externalLinkTracker.getHostname()
10
+ var externalLinkSelector = 'a[href^="http"]:not(a[href*="' + currentHost + '"])'
9
11
 
10
- var currentHost = GOVUK.analyticsPlugins.externalLinkTracker.getHostname(),
11
- externalLinkSelector = 'a[href^="http"]:not(a[href*="' + currentHost + '"])';
12
+ $('body').on('click', externalLinkSelector, trackClickEvent)
12
13
 
13
- $('body').on('click', externalLinkSelector, trackClickEvent);
14
-
15
- function trackClickEvent(evt) {
16
- var $link = getLinkFromEvent(evt),
17
- options = {transport: 'beacon'},
18
- href = $link.attr('href'),
19
- linkText = $.trim($link.text());
14
+ function trackClickEvent (evt) {
15
+ var $link = getLinkFromEvent(evt)
16
+ var options = {transport: 'beacon'}
17
+ var href = $link.attr('href')
18
+ var linkText = $.trim($link.text())
20
19
 
21
20
  if (linkText) {
22
- options.label = linkText;
21
+ options.label = linkText
23
22
  }
24
23
 
25
- GOVUK.analytics.trackEvent('External Link Clicked', href, options);
24
+ GOVUK.analytics.trackEvent('External Link Clicked', href, options)
26
25
  }
27
26
 
28
- function getLinkFromEvent(evt) {
29
- var $target = $(evt.target);
27
+ function getLinkFromEvent (evt) {
28
+ var $target = $(evt.target)
30
29
 
31
30
  if (!$target.is('a')) {
32
- $target = $target.parents('a');
31
+ $target = $target.parents('a')
33
32
  }
34
33
 
35
- return $target;
34
+ return $target
36
35
  }
37
36
  }
38
37
 
39
- GOVUK.analyticsPlugins.externalLinkTracker.getHostname = function() {
40
- return global.location.hostname;
38
+ GOVUK.analyticsPlugins.externalLinkTracker.getHostname = function () {
39
+ return global.location.hostname
41
40
  }
42
41
 
43
- global.GOVUK = GOVUK;
44
- })(window);
42
+ global.GOVUK = GOVUK
43
+ })(window)
@@ -1,107 +1,108 @@
1
- (function(global) {
2
- "use strict";
1
+ ;(function (global) {
2
+ 'use strict'
3
3
 
4
- var GOVUK = global.GOVUK || {};
4
+ var GOVUK = global.GOVUK || {}
5
5
 
6
- var GoogleAnalyticsUniversalTracker = function(trackingId, fieldsObject) {
7
-
8
- function configureProfile() {
6
+ var GoogleAnalyticsUniversalTracker = function (trackingId, fieldsObject) {
7
+ function configureProfile () {
9
8
  // https://developers.google.com/analytics/devguides/collection/analyticsjs/command-queue-reference#create
10
- sendToGa('create', trackingId, fieldsObject);
9
+ sendToGa('create', trackingId, fieldsObject)
11
10
  }
12
11
 
13
- function anonymizeIp() {
12
+ function anonymizeIp () {
14
13
  // https://developers.google.com/analytics/devguides/collection/analyticsjs/advanced#anonymizeip
15
- sendToGa('set', 'anonymizeIp', true);
14
+ sendToGa('set', 'anonymizeIp', true)
16
15
  }
17
16
 
18
17
  // Support legacy cookieDomain param
19
18
  if (typeof fieldsObject === 'string') {
20
- fieldsObject = { cookieDomain: fieldsObject };
19
+ fieldsObject = { cookieDomain: fieldsObject }
21
20
  }
22
21
 
23
- configureProfile();
24
- anonymizeIp();
25
- };
22
+ configureProfile()
23
+ anonymizeIp()
24
+ }
26
25
 
27
- GoogleAnalyticsUniversalTracker.load = function() {
28
- (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
29
- (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
30
- m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
31
- })(global,document,'script','https://www.google-analytics.com/analytics.js','ga');
32
- };
26
+ GoogleAnalyticsUniversalTracker.load = function () {
27
+ /* eslint-disable */
28
+ (function (i, s, o, g, r, a, m) { i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
29
+ (i[r].q = i[r].q || []).push(arguments) }, i[r].l = 1 * new Date(); a = s.createElement(o),
30
+ m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
31
+ })(global, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga')
32
+ /* eslint-enable */
33
+ }
33
34
 
34
35
  // https://developers.google.com/analytics/devguides/collection/analyticsjs/pages
35
- GoogleAnalyticsUniversalTracker.prototype.trackPageview = function(path, title, options) {
36
- var options = options || {};
36
+ GoogleAnalyticsUniversalTracker.prototype.trackPageview = function (path, title, options) {
37
+ options = options || {}
37
38
 
38
- if (typeof path === "string") {
39
+ if (typeof path === 'string') {
39
40
  var pageviewObject = {
40
- page: path
41
- };
41
+ page: path
42
+ }
42
43
 
43
- if (typeof title === "string") {
44
- pageviewObject.title = title;
44
+ if (typeof title === 'string') {
45
+ pageviewObject.title = title
45
46
  }
46
47
 
47
48
  // Set the transport method for the pageview
48
49
  // Typically used for enabling `navigator.sendBeacon` when the page might be unloading
49
50
  // https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#transport
50
51
  if (options.transport) {
51
- pageviewObject.transport = options.transport;
52
+ pageviewObject.transport = options.transport
52
53
  }
53
54
 
54
- sendToGa('send', 'pageview', pageviewObject);
55
+ sendToGa('send', 'pageview', pageviewObject)
55
56
  } else {
56
- sendToGa('send', 'pageview');
57
+ sendToGa('send', 'pageview')
57
58
  }
58
- };
59
+ }
59
60
 
60
61
  // https://developers.google.com/analytics/devguides/collection/analyticsjs/events
61
- GoogleAnalyticsUniversalTracker.prototype.trackEvent = function(category, action, options) {
62
- var value,
63
- options = options || {},
64
- evt = {
65
- hitType: 'event',
66
- eventCategory: category,
67
- eventAction: action
68
- };
62
+ GoogleAnalyticsUniversalTracker.prototype.trackEvent = function (category, action, options) {
63
+ options = options || {}
64
+ var value
65
+ var evt = {
66
+ hitType: 'event',
67
+ eventCategory: category,
68
+ eventAction: action
69
+ }
69
70
 
70
71
  // Label is optional
71
- if (typeof options.label === "string") {
72
- evt.eventLabel = options.label;
72
+ if (typeof options.label === 'string') {
73
+ evt.eventLabel = options.label
73
74
  }
74
75
 
75
76
  // Page is optional
76
- if (typeof options.page === "string") {
77
- evt.page = options.page;
77
+ if (typeof options.page === 'string') {
78
+ evt.page = options.page
78
79
  }
79
80
 
80
81
  // Value is optional, but when used must be an
81
82
  // integer, otherwise the event will be invalid
82
83
  // and not logged
83
84
  if (options.value || options.value === 0) {
84
- value = parseInt(options.value, 10);
85
- if (typeof value === "number" && !isNaN(value)) {
86
- evt.eventValue = value;
85
+ value = parseInt(options.value, 10)
86
+ if (typeof value === 'number' && !isNaN(value)) {
87
+ evt.eventValue = value
87
88
  }
88
89
  }
89
90
 
90
91
  // Prevents an event from affecting bounce rate
91
92
  // https://developers.google.com/analytics/devguides/collection/analyticsjs/events#implementation
92
93
  if (options.nonInteraction) {
93
- evt.nonInteraction = 1;
94
+ evt.nonInteraction = 1
94
95
  }
95
96
 
96
97
  // Set the transport method for the event
97
98
  // Typically used for enabling `navigator.sendBeacon` when the page might be unloading
98
99
  // https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#transport
99
100
  if (options.transport) {
100
- evt.transport = options.transport;
101
+ evt.transport = options.transport
101
102
  }
102
103
 
103
- sendToGa('send', evt);
104
- };
104
+ sendToGa('send', evt)
105
+ }
105
106
 
106
107
  /*
107
108
  https://developers.google.com/analytics/devguides/collection/analyticsjs/social-interactions
@@ -110,14 +111,14 @@
110
111
  target – Specifies the target of a social interaction.
111
112
  This value is typically a URL but can be any text.
112
113
  */
113
- GoogleAnalyticsUniversalTracker.prototype.trackSocial = function(network, action, target) {
114
+ GoogleAnalyticsUniversalTracker.prototype.trackSocial = function (network, action, target) {
114
115
  sendToGa('send', {
115
116
  'hitType': 'social',
116
117
  'socialNetwork': network,
117
118
  'socialAction': action,
118
119
  'socialTarget': target
119
- });
120
- };
120
+ })
121
+ }
121
122
 
122
123
  /*
123
124
  https://developers.google.com/analytics/devguides/collection/analyticsjs/cross-domain
@@ -125,35 +126,35 @@
125
126
  name - name for the tracker
126
127
  domain - the domain to track
127
128
  */
128
- GoogleAnalyticsUniversalTracker.prototype.addLinkedTrackerDomain = function(trackerId, name, domain) {
129
+ GoogleAnalyticsUniversalTracker.prototype.addLinkedTrackerDomain = function (trackerId, name, domain) {
129
130
  sendToGa('create',
130
131
  trackerId,
131
132
  'auto',
132
- {'name': name});
133
+ {'name': name})
133
134
  // Load the plugin.
134
- sendToGa('require', 'linker');
135
- sendToGa(name + '.require', 'linker');
135
+ sendToGa('require', 'linker')
136
+ sendToGa(name + '.require', 'linker')
136
137
 
137
138
  // Define which domains to autoLink.
138
- sendToGa('linker:autoLink', [domain]);
139
- sendToGa(name + '.linker:autoLink', [domain]);
139
+ sendToGa('linker:autoLink', [domain])
140
+ sendToGa(name + '.linker:autoLink', [domain])
140
141
 
141
- sendToGa(name + '.set', 'anonymizeIp', true);
142
- sendToGa(name + '.send', 'pageview');
143
- };
142
+ sendToGa(name + '.set', 'anonymizeIp', true)
143
+ sendToGa(name + '.send', 'pageview')
144
+ }
144
145
 
145
146
  // https://developers.google.com/analytics/devguides/collection/analyticsjs/custom-dims-mets
146
- GoogleAnalyticsUniversalTracker.prototype.setDimension = function(index, value) {
147
- sendToGa('set', 'dimension' + index, String(value));
148
- };
147
+ GoogleAnalyticsUniversalTracker.prototype.setDimension = function (index, value) {
148
+ sendToGa('set', 'dimension' + index, String(value))
149
+ }
149
150
 
150
- function sendToGa() {
151
- if (typeof global.ga === "function") {
152
- ga.apply(global, arguments);
151
+ function sendToGa () {
152
+ if (typeof global.ga === 'function') {
153
+ global.ga.apply(global, arguments)
153
154
  }
154
155
  }
155
156
 
156
- GOVUK.GoogleAnalyticsUniversalTracker = GoogleAnalyticsUniversalTracker;
157
+ GOVUK.GoogleAnalyticsUniversalTracker = GoogleAnalyticsUniversalTracker
157
158
 
158
- global.GOVUK = GOVUK;
159
- })(window);
159
+ global.GOVUK = GOVUK
160
+ })(window)
@@ -1,39 +1,38 @@
1
- (function(global) {
2
- "use strict";
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.mailtoLinkTracker = function () {
9
+ var mailtoLinkSelector = 'a[href^="mailto:"]'
9
10
 
10
- var mailtoLinkSelector = 'a[href^="mailto:"]';
11
+ $('body').on('click', mailtoLinkSelector, trackClickEvent)
11
12
 
12
- $('body').on('click', mailtoLinkSelector, trackClickEvent);
13
-
14
- function trackClickEvent(evt) {
15
- var $link = getLinkFromEvent(evt),
16
- options = {transport: 'beacon'},
17
- href = $link.attr('href'),
18
- linkText = $.trim($link.text());
13
+ function trackClickEvent (evt) {
14
+ var $link = getLinkFromEvent(evt)
15
+ var options = { transport: 'beacon' }
16
+ var href = $link.attr('href')
17
+ var linkText = $.trim($link.text())
19
18
 
20
19
  if (linkText) {
21
- options.label = linkText;
20
+ options.label = linkText
22
21
  }
23
22
 
24
- GOVUK.analytics.trackEvent('Mailto Link Clicked', href, options);
23
+ GOVUK.analytics.trackEvent('Mailto Link Clicked', href, options)
25
24
  }
26
25
 
27
- function getLinkFromEvent(evt) {
28
- var $target = $(evt.target);
26
+ function getLinkFromEvent (evt) {
27
+ var $target = $(evt.target)
29
28
 
30
29
  if (!$target.is('a')) {
31
- $target = $target.parents('a');
30
+ $target = $target.parents('a')
32
31
  }
33
32
 
34
- return $target;
33
+ return $target
35
34
  }
36
35
  }
37
36
 
38
- global.GOVUK = GOVUK;
39
- })(window);
37
+ global.GOVUK = GOVUK
38
+ })(window)
@@ -1,40 +1,39 @@
1
1
  // Extension to monitor attempts to print pages.
2
- (function (global) {
3
- "use strict";
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.printIntent = function () {
10
- var printAttempt = (function () {
11
- GOVUK.analytics.trackEvent('Print Intent', document.location.pathname);
12
- GOVUK.analytics.trackPageview('/print' + document.location.pathname);
13
- });
10
+ var printAttempt = function () {
11
+ GOVUK.analytics.trackEvent('Print Intent', document.location.pathname)
12
+ GOVUK.analytics.trackPageview('/print' + document.location.pathname)
13
+ }
14
14
 
15
15
  // Most browsers
16
16
  if (global.matchMedia) {
17
- var mediaQueryList = global.matchMedia('print'),
18
- mqlListenerCount = 0;
17
+ var mediaQueryList = global.matchMedia('print')
18
+ var mqlListenerCount = 0
19
19
  mediaQueryList.addListener(function (mql) {
20
20
  if (!mql.matches && mqlListenerCount === 0) {
21
- printAttempt();
22
- mqlListenerCount++;
21
+ printAttempt()
22
+ mqlListenerCount++
23
23
  // If we try and print again within 3 seconds, don't log it
24
24
  setTimeout(function () {
25
- mqlListenerCount = 0;
25
+ mqlListenerCount = 0
26
26
  // printing will be tracked again now
27
- }, 3000);
27
+ }, 3000)
28
28
  }
29
- });
29
+ })
30
30
  }
31
31
 
32
32
  // IE < 10
33
33
  if (global.onafterprint) {
34
- global.onafterprint = printAttempt;
34
+ global.onafterprint = printAttempt
35
35
  }
36
+ }
36
37
 
37
- };
38
-
39
- global.GOVUK = GOVUK;
40
- })(window);
38
+ global.GOVUK = GOVUK
39
+ })(window)
@@ -1,60 +1,61 @@
1
- (function(global) {
2
- "use strict";
1
+ ;(function (global) {
2
+ 'use strict'
3
3
 
4
- var $ = global.jQuery;
5
- var GOVUK = global.GOVUK || {};
6
- GOVUK.Modules = GOVUK.Modules || {};
4
+ var $ = global.jQuery
5
+ var GOVUK = global.GOVUK || {}
6
+ GOVUK.Modules = GOVUK.Modules || {}
7
7
 
8
8
  GOVUK.modules = {
9
- find: function(container) {
10
- var modules,
11
- moduleSelector = '[data-module]',
12
- container = container || $('body');
9
+ find: function (container) {
10
+ container = container || $('body')
13
11
 
14
- modules = container.find(moduleSelector);
12
+ var modules
13
+ var moduleSelector = '[data-module]'
14
+
15
+ modules = container.find(moduleSelector)
15
16
 
16
17
  // Container could be a module too
17
18
  if (container.is(moduleSelector)) {
18
- modules = modules.add(container);
19
+ modules = modules.add(container)
19
20
  }
20
21
 
21
- return modules;
22
+ return modules
22
23
  },
23
24
 
24
- start: function(container) {
25
- var modules = this.find(container);
25
+ start: function (container) {
26
+ var modules = this.find(container)
26
27
 
27
28
  for (var i = 0, l = modules.length; i < l; i++) {
28
- var module,
29
- element = $(modules[i]),
30
- type = camelCaseAndCapitalise(element.data('module')),
31
- started = element.data('module-started');
32
-
33
- if (typeof GOVUK.Modules[type] === "function" && !started) {
34
- module = new GOVUK.Modules[type]();
35
- module.start(element);
36
- element.data('module-started', true);
29
+ var module
30
+ var element = $(modules[i])
31
+ var type = camelCaseAndCapitalise(element.data('module'))
32
+ var started = element.data('module-started')
33
+
34
+ if (typeof GOVUK.Modules[type] === 'function' && !started) {
35
+ module = new GOVUK.Modules[type]()
36
+ module.start(element)
37
+ element.data('module-started', true)
37
38
  }
38
39
  }
39
40
 
40
41
  // eg selectable-table to SelectableTable
41
- function camelCaseAndCapitalise(string) {
42
- return capitaliseFirstLetter(camelCase(string));
42
+ function camelCaseAndCapitalise (string) {
43
+ return capitaliseFirstLetter(camelCase(string))
43
44
  }
44
45
 
45
46
  // http://stackoverflow.com/questions/6660977/convert-hyphens-to-camel-case-camelcase
46
- function camelCase(string) {
47
+ function camelCase (string) {
47
48
  return string.replace(/-([a-z])/g, function (g) {
48
- return g[1].toUpperCase();
49
- });
49
+ return g[1].toUpperCase()
50
+ })
50
51
  }
51
52
 
52
53
  // http://stackoverflow.com/questions/1026069/capitalize-the-first-letter-of-string-in-javascript
53
- function capitaliseFirstLetter(string) {
54
- return string.charAt(0).toUpperCase() + string.slice(1);
54
+ function capitaliseFirstLetter (string) {
55
+ return string.charAt(0).toUpperCase() + string.slice(1)
55
56
  }
56
57
  }
57
58
  }
58
59
 
59
- global.GOVUK = GOVUK;
60
- })(window);
60
+ global.GOVUK = GOVUK
61
+ })(window)