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
@@ -8,11 +8,11 @@
8
8
  // object with your own selector for the target elements and addional keyup
9
9
  // codes if there becomes a need to do so. For example:
10
10
  // GOVUK.shimLinksWithButtonRole.init({ selector: '[role="button"]' });
11
- (function(global) {
12
- "use strict";
11
+ ;(function (global) {
12
+ 'use strict'
13
13
 
14
- var $ = global.jQuery;
15
- var GOVUK = global.GOVUK || {};
14
+ var $ = global.jQuery
15
+ var GOVUK = global.GOVUK || {}
16
16
 
17
17
  GOVUK.shimLinksWithButtonRole = {
18
18
 
@@ -27,12 +27,12 @@
27
27
  },
28
28
 
29
29
  // event behaviour (not a typical anonymous function for resuse if needed)
30
- triggerClickOnTarget: function triggerClickOnTarget(event) {
30
+ triggerClickOnTarget: function triggerClickOnTarget (event) {
31
31
  // if the code from this event is in the keycodes array then
32
32
  if ($.inArray(event.which, this.config.keycodes) !== -1) {
33
- event.preventDefault();
33
+ event.preventDefault()
34
34
  // trigger the target's click event
35
- event.target.click();
35
+ event.target.click()
36
36
  }
37
37
  },
38
38
 
@@ -42,19 +42,18 @@
42
42
  // @param {Object} customConfig object to override default configuration
43
43
  // {String} customConfig.selector a selector for the elements to be 'clicked'
44
44
  // {Array} customConfig.keycodes an array of javascript keycode values to match against that when pressed will trigger the click
45
- init: function init(customConfig) {
45
+ init: function init (customConfig) {
46
46
  // extend the default config with any custom attributes passed in
47
- this.config = $.extend(this.config, customConfig);
47
+ this.config = $.extend(this.config, customConfig)
48
48
  // if we have found elements then:
49
- if($(this.config.selector).length > 0) {
49
+ if ($(this.config.selector).length > 0) {
50
50
  // listen to 'document' for keyup event on the elements and fire the triggerClickOnTarget
51
- $(document).on('keyup', this.config.selector, this.triggerClickOnTarget.bind(this));
51
+ $(document).on('keyup', this.config.selector, this.triggerClickOnTarget.bind(this))
52
52
  }
53
53
  }
54
54
 
55
- };
55
+ }
56
56
 
57
57
  // hand back to global
58
- global.GOVUK = GOVUK;
59
-
60
- })(window);
58
+ global.GOVUK = GOVUK
59
+ })(window)
@@ -1,8 +1,8 @@
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
7
  // Stick elements to top of screen when you scroll past, documentation is in the README.md
8
8
  var sticky = {
@@ -11,108 +11,108 @@
11
11
  _hasResized: false,
12
12
  _resizeTimeout: false,
13
13
 
14
- getWindowDimensions: function() {
14
+ getWindowDimensions: function () {
15
15
  return {
16
16
  height: $(global).height(),
17
17
  width: $(global).width()
18
- };
18
+ }
19
19
  },
20
- getWindowPositions: function() {
20
+ getWindowPositions: function () {
21
21
  return {
22
22
  scrollTop: $(global).scrollTop()
23
- };
23
+ }
24
24
  },
25
- getElementOffset: function($el) {
25
+ getElementOffset: function ($el) {
26
26
  return $el.offset()
27
27
  },
28
- init: function(){
29
- var $els = $('.js-stick-at-top-when-scrolling');
28
+ init: function () {
29
+ var $els = $('.js-stick-at-top-when-scrolling')
30
30
 
31
- if($els.length > 0){
32
- sticky.$els = $els;
31
+ if ($els.length > 0) {
32
+ sticky.$els = $els
33
33
 
34
- if(sticky._scrollTimeout === false) {
35
- $(global).scroll(sticky.onScroll);
36
- sticky._scrollTimeout = global.setInterval(sticky.checkScroll, 50);
34
+ if (sticky._scrollTimeout === false) {
35
+ $(global).scroll(sticky.onScroll)
36
+ sticky._scrollTimeout = global.setInterval(sticky.checkScroll, 50)
37
37
  }
38
38
 
39
- if(sticky._resizeTimeout === false) {
40
- $(global).resize(sticky.onResize);
41
- sticky._resizeTimeout = global.setInterval(sticky.checkResize, 50);
39
+ if (sticky._resizeTimeout === false) {
40
+ $(global).resize(sticky.onResize)
41
+ sticky._resizeTimeout = global.setInterval(sticky.checkResize, 50)
42
42
  }
43
43
  }
44
- if(GOVUK.stopScrollingAtFooter){
45
- $els.each(function(i,el){
46
- var $img = $(el).find('img');
47
- if($img.length > 0){
48
- var image = new Image();
49
- image.onload = function(){
50
- GOVUK.stopScrollingAtFooter.addEl($(el), $(el).outerHeight());
51
- };
52
- image.src = $img.attr('src');
44
+ if (GOVUK.stopScrollingAtFooter) {
45
+ $els.each(function (i, el) {
46
+ var $img = $(el).find('img')
47
+ if ($img.length > 0) {
48
+ var image = new global.Image()
49
+ image.onload = function () {
50
+ GOVUK.stopScrollingAtFooter.addEl($(el), $(el).outerHeight())
51
+ }
52
+ image.src = $img.attr('src')
53
53
  } else {
54
- GOVUK.stopScrollingAtFooter.addEl($(el), $(el).outerHeight());
54
+ GOVUK.stopScrollingAtFooter.addEl($(el), $(el).outerHeight())
55
55
  }
56
- });
56
+ })
57
57
  }
58
58
  },
59
- onScroll: function(){
60
- sticky._hasScrolled = true;
59
+ onScroll: function () {
60
+ sticky._hasScrolled = true
61
61
  },
62
- onResize: function(){
63
- sticky._hasResized = true;
62
+ onResize: function () {
63
+ sticky._hasResized = true
64
64
  },
65
- checkScroll: function(){
66
- if(sticky._hasScrolled === true){
67
- sticky._hasScrolled = false;
65
+ checkScroll: function () {
66
+ if (sticky._hasScrolled === true) {
67
+ sticky._hasScrolled = false
68
68
 
69
- var windowVerticalPosition = sticky.getWindowPositions().scrollTop;
69
+ var windowVerticalPosition = sticky.getWindowPositions().scrollTop
70
70
 
71
- var windowDimensions = sticky.getWindowDimensions();
71
+ var windowDimensions = sticky.getWindowDimensions()
72
72
 
73
- sticky.$els.each(function(i, el){
74
- var $el = $(el),
75
- scrolledFrom = $el.data('scrolled-from');
73
+ sticky.$els.each(function (i, el) {
74
+ var $el = $(el)
75
+ var scrolledFrom = $el.data('scrolled-from')
76
76
 
77
- if (scrolledFrom && windowVerticalPosition < scrolledFrom){
78
- sticky.release($el);
79
- } else if(windowDimensions.width > 768 && windowVerticalPosition >= sticky.getElementOffset($el).top) {
80
- sticky.stick($el);
77
+ if (scrolledFrom && windowVerticalPosition < scrolledFrom) {
78
+ sticky.release($el)
79
+ } else if (windowDimensions.width > 768 && windowVerticalPosition >= sticky.getElementOffset($el).top) {
80
+ sticky.stick($el)
81
81
  }
82
- });
82
+ })
83
83
  }
84
84
  },
85
- checkResize: function() {
86
- if(sticky._hasResized === true){
87
- sticky._hasResized = false;
85
+ checkResize: function () {
86
+ if (sticky._hasResized === true) {
87
+ sticky._hasResized = false
88
88
 
89
- var windowDimensions = sticky.getWindowDimensions();
89
+ var windowDimensions = sticky.getWindowDimensions()
90
90
 
91
- sticky.$els.each(function(i, el){
92
- var $el = $(el);
91
+ sticky.$els.each(function (i, el) {
92
+ var $el = $(el)
93
93
 
94
- if(windowDimensions.width <= 768) {
95
- sticky.release($el);
94
+ if (windowDimensions.width <= 768) {
95
+ sticky.release($el)
96
96
  }
97
- });
97
+ })
98
98
  }
99
99
  },
100
- stick: function($el){
100
+ stick: function ($el) {
101
101
  if (!$el.hasClass('content-fixed')) {
102
- $el.data('scrolled-from', sticky.getElementOffset($el).top);
103
- var height = Math.max($el.height(), 1);
104
- $el.before('<div class="shim" style="width: '+ $el.width() + 'px; height: ' + height + 'px">&nbsp;</div>');
105
- $el.css('width', $el.width() + "px").addClass('content-fixed');
102
+ $el.data('scrolled-from', sticky.getElementOffset($el).top)
103
+ var height = Math.max($el.height(), 1)
104
+ $el.before('<div class="shim" style="width: ' + $el.width() + 'px; height: ' + height + 'px">&nbsp;</div>')
105
+ $el.css('width', $el.width() + 'px').addClass('content-fixed')
106
106
  }
107
107
  },
108
- release: function($el){
109
- if($el.hasClass('content-fixed')){
110
- $el.data('scrolled-from', false);
111
- $el.removeClass('content-fixed').css('width', '');
112
- $el.siblings('.shim').remove();
108
+ release: function ($el) {
109
+ if ($el.hasClass('content-fixed')) {
110
+ $el.data('scrolled-from', false)
111
+ $el.removeClass('content-fixed').css('width', '')
112
+ $el.siblings('.shim').remove()
113
113
  }
114
114
  }
115
- };
116
- GOVUK.stickAtTopWhenScrolling = sticky;
117
- global.GOVUK = GOVUK;
118
- })(window);
115
+ }
116
+ GOVUK.stickAtTopWhenScrolling = sticky
117
+ global.GOVUK = GOVUK
118
+ })(window)
@@ -10,12 +10,11 @@
10
10
  // Height is passed in separatly incase the scrolling element has no height
11
11
  // itself.
12
12
 
13
+ ;(function (global) {
14
+ 'use strict'
13
15
 
14
- (function (global) {
15
- "use strict";
16
-
17
- var $ = global.jQuery;
18
- var GOVUK = global.GOVUK || {};
16
+ var $ = global.jQuery
17
+ var GOVUK = global.GOVUK || {}
19
18
 
20
19
  var stopScrollingAtFooter = {
21
20
  _pollingId: null,
@@ -23,118 +22,118 @@
23
22
  _hasScrollEvt: false,
24
23
  _els: [],
25
24
 
26
- addEl: function($fixedEl, height){
27
- var fixedOffset;
25
+ addEl: function ($fixedEl, height) {
26
+ var fixedOffset
28
27
 
29
- if(!$fixedEl.length) { return; }
28
+ if (!$fixedEl.length) { return }
30
29
 
31
- fixedOffset = parseInt($fixedEl.css('top'), 10);
32
- fixedOffset = isNaN(fixedOffset) ? 0 : fixedOffset;
30
+ fixedOffset = parseInt($fixedEl.css('top'), 10)
31
+ fixedOffset = isNaN(fixedOffset) ? 0 : fixedOffset
33
32
 
34
- stopScrollingAtFooter.updateFooterTop();
35
- $(global).on('govuk.pageSizeChanged', stopScrollingAtFooter.updateFooterTop);
33
+ stopScrollingAtFooter.updateFooterTop()
34
+ $(global).on('govuk.pageSizeChanged', stopScrollingAtFooter.updateFooterTop)
36
35
 
37
- var $siblingEl = $('<div></div>');
38
- $siblingEl.insertBefore($fixedEl);
39
- var fixedTop = $siblingEl.offset().top - $siblingEl.position().top;
40
- $siblingEl.remove();
36
+ var $siblingEl = $('<div></div>')
37
+ $siblingEl.insertBefore($fixedEl)
38
+ var fixedTop = $siblingEl.offset().top - $siblingEl.position().top
39
+ $siblingEl.remove()
41
40
 
42
41
  var el = {
43
42
  $fixedEl: $fixedEl,
44
43
  height: height + fixedOffset,
45
44
  fixedTop: height + fixedTop,
46
45
  state: 'fixed'
47
- };
48
- stopScrollingAtFooter._els.push(el);
46
+ }
47
+ stopScrollingAtFooter._els.push(el)
49
48
 
50
- stopScrollingAtFooter.initTimeout();
49
+ stopScrollingAtFooter.initTimeout()
51
50
  },
52
- updateFooterTop: function(){
53
- var footer = $('.js-footer:eq(0)');
51
+ updateFooterTop: function () {
52
+ var footer = $('.js-footer:eq(0)')
54
53
  if (footer.length === 0) {
55
- return 0;
54
+ return 0
56
55
  }
57
- stopScrollingAtFooter.footerTop = footer.offset().top - 10;
56
+ stopScrollingAtFooter.footerTop = footer.offset().top - 10
58
57
  },
59
- initTimeout: function(){
60
- if(stopScrollingAtFooter._hasScrollEvt === false) {
61
- $(window).scroll(stopScrollingAtFooter.onScroll);
62
- stopScrollingAtFooter._hasScrollEvt = true;
58
+ initTimeout: function () {
59
+ if (stopScrollingAtFooter._hasScrollEvt === false) {
60
+ $(window).scroll(stopScrollingAtFooter.onScroll)
61
+ stopScrollingAtFooter._hasScrollEvt = true
63
62
  }
64
63
  },
65
- onScroll: function(){
64
+ onScroll: function () {
66
65
  if (stopScrollingAtFooter._isPolling === false) {
67
- stopScrollingAtFooter.startPolling();
66
+ stopScrollingAtFooter.startPolling()
68
67
  }
69
68
  },
70
- startPolling: (function(){
69
+ startPolling: (function () {
71
70
  if (window.requestAnimationFrame) {
72
- return (function(){
73
- var callback = function(){
74
- stopScrollingAtFooter.checkScroll();
71
+ return function () {
72
+ var callback = function () {
73
+ stopScrollingAtFooter.checkScroll()
75
74
  if (stopScrollingAtFooter._isPolling === true) {
76
- stopScrollingAtFooter.startPolling();
75
+ stopScrollingAtFooter.startPolling()
77
76
  }
78
- };
79
- stopScrollingAtFooter._pollingId = window.requestAnimationFrame(callback);
80
- stopScrollingAtFooter._isPolling = true;
81
- });
77
+ }
78
+ stopScrollingAtFooter._pollingId = window.requestAnimationFrame(callback)
79
+ stopScrollingAtFooter._isPolling = true
80
+ }
82
81
  } else {
83
- return (function(){
84
- stopScrollingAtFooter._pollingId = window.setInterval(stopScrollingAtFooter.checkScroll, 16);
85
- stopScrollingAtFooter._isPolling = true;
86
- });
82
+ return function () {
83
+ stopScrollingAtFooter._pollingId = window.setInterval(stopScrollingAtFooter.checkScroll, 16)
84
+ stopScrollingAtFooter._isPolling = true
85
+ }
87
86
  }
88
87
  }()),
89
- stopPolling: (function(){
88
+ stopPolling: (function () {
90
89
  if (window.requestAnimationFrame) {
91
- return (function(){
92
- window.cancelAnimationFrame(stopScrollingAtFooter._pollingId);
93
- stopScrollingAtFooter._isPolling = false;
94
- });
90
+ return function () {
91
+ window.cancelAnimationFrame(stopScrollingAtFooter._pollingId)
92
+ stopScrollingAtFooter._isPolling = false
93
+ }
95
94
  } else {
96
- return (function(){
97
- window.clearInterval(stopScrollingAtFooter._pollingId);
98
- stopScrollingAtFooter._isPolling = false;
99
- });
95
+ return function () {
96
+ window.clearInterval(stopScrollingAtFooter._pollingId)
97
+ stopScrollingAtFooter._isPolling = false
98
+ }
100
99
  }
101
100
  }()),
102
- checkScroll: function(){
103
- var cachedScrollTop = $(window).scrollTop();
101
+ checkScroll: function () {
102
+ var cachedScrollTop = $(window).scrollTop()
104
103
  if ((cachedScrollTop < (stopScrollingAtFooter.cachedScrollTop + 2)) && (cachedScrollTop > (stopScrollingAtFooter.cachedScrollTop - 2))) {
105
- stopScrollingAtFooter.stopPolling();
106
- return;
104
+ stopScrollingAtFooter.stopPolling()
105
+ return
107
106
  } else {
108
- stopScrollingAtFooter.cachedScrollTop = cachedScrollTop;
107
+ stopScrollingAtFooter.cachedScrollTop = cachedScrollTop
109
108
  }
110
109
 
111
- $.each(stopScrollingAtFooter._els, function(i, el){
112
- var bottomOfEl = cachedScrollTop + el.height;
110
+ $.each(stopScrollingAtFooter._els, function (i, el) {
111
+ var bottomOfEl = cachedScrollTop + el.height
113
112
 
114
- if (bottomOfEl > stopScrollingAtFooter.footerTop){
115
- stopScrollingAtFooter.stick(el);
113
+ if (bottomOfEl > stopScrollingAtFooter.footerTop) {
114
+ stopScrollingAtFooter.stick(el)
116
115
  } else {
117
- stopScrollingAtFooter.unstick(el);
116
+ stopScrollingAtFooter.unstick(el)
118
117
  }
119
- });
118
+ })
120
119
  },
121
- stick: function(el){
122
- if(el.state === 'fixed' && el.$fixedEl.css('position') === 'fixed'){
123
- el.$fixedEl.css({ 'position': 'absolute', 'top': stopScrollingAtFooter.footerTop - el.fixedTop });
124
- el.state = 'absolute';
120
+ stick: function (el) {
121
+ if (el.state === 'fixed' && el.$fixedEl.css('position') === 'fixed') {
122
+ el.$fixedEl.css({ 'position': 'absolute', 'top': stopScrollingAtFooter.footerTop - el.fixedTop })
123
+ el.state = 'absolute'
125
124
  }
126
125
  },
127
- unstick: function(el){
128
- if(el.state === 'absolute'){
129
- el.$fixedEl.css({ 'position': '', 'top': '' });
130
- el.state = 'fixed';
126
+ unstick: function (el) {
127
+ if (el.state === 'absolute') {
128
+ el.$fixedEl.css({ 'position': '', 'top': '' })
129
+ el.state = 'fixed'
131
130
  }
132
131
  }
133
- };
132
+ }
134
133
 
135
- GOVUK.stopScrollingAtFooter = stopScrollingAtFooter;
134
+ GOVUK.stopScrollingAtFooter = stopScrollingAtFooter
136
135
 
137
- $(global).load(function(){ $(global).trigger('govuk.pageSizeChanged'); });
136
+ $(global).load(function () { $(global).trigger('govuk.pageSizeChanged') })
138
137
 
139
- global.GOVUK = GOVUK;
140
- })(window);
138
+ global.GOVUK = GOVUK
139
+ })(window)