govuk_tech_docs 3.4.0 → 3.4.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -1
  3. data/lib/assets/stylesheets/_govuk_tech_docs.scss +13 -0
  4. data/lib/govuk_tech_docs/version.rb +1 -1
  5. data/lib/source/favicon.ico +0 -0
  6. data/lib/source/layouts/_header.erb +13 -15
  7. data/node_modules/govuk-frontend/govuk/all-ie8.scss +8 -0
  8. data/node_modules/govuk-frontend/govuk/all.js +4918 -3796
  9. data/node_modules/govuk-frontend/govuk/common/closest-attribute-value.js +54 -49
  10. data/node_modules/govuk-frontend/govuk/common/govuk-frontend-version.js +17 -0
  11. data/node_modules/govuk-frontend/govuk/common/index.js +172 -152
  12. data/node_modules/govuk-frontend/govuk/common/normalise-dataset.js +334 -321
  13. data/node_modules/govuk-frontend/govuk/common.js +171 -151
  14. data/node_modules/govuk-frontend/govuk/components/_all.scss +3 -2
  15. data/node_modules/govuk-frontend/govuk/components/accordion/_index.scss +26 -7
  16. data/node_modules/govuk-frontend/govuk/components/accordion/accordion.js +2203 -1650
  17. data/node_modules/govuk-frontend/govuk/components/back-link/_index.scss +24 -16
  18. data/node_modules/govuk-frontend/govuk/components/breadcrumbs/_index.scss +34 -11
  19. data/node_modules/govuk-frontend/govuk/components/button/_index.scss +49 -9
  20. data/node_modules/govuk-frontend/govuk/components/button/button.js +961 -916
  21. data/node_modules/govuk-frontend/govuk/components/character-count/character-count.js +2142 -2038
  22. data/node_modules/govuk-frontend/govuk/components/checkboxes/_index.scss +6 -6
  23. data/node_modules/govuk-frontend/govuk/components/checkboxes/checkboxes.js +1204 -1145
  24. data/node_modules/govuk-frontend/govuk/components/details/details.js +826 -799
  25. data/node_modules/govuk-frontend/govuk/components/error-summary/error-summary.js +1097 -1044
  26. data/node_modules/govuk-frontend/govuk/components/exit-this-page/_exit-this-page.scss +2 -0
  27. data/node_modules/govuk-frontend/govuk/components/exit-this-page/_index.scss +97 -0
  28. data/node_modules/govuk-frontend/govuk/components/exit-this-page/exit-this-page.js +2120 -0
  29. data/node_modules/govuk-frontend/govuk/components/file-upload/_index.scss +6 -1
  30. data/node_modules/govuk-frontend/govuk/components/footer/_index.scss +0 -7
  31. data/node_modules/govuk-frontend/govuk/components/header/_index.scss +6 -0
  32. data/node_modules/govuk-frontend/govuk/components/header/header.js +683 -1003
  33. data/node_modules/govuk-frontend/govuk/components/input/_index.scss +15 -3
  34. data/node_modules/govuk-frontend/govuk/components/notification-banner/notification-banner.js +786 -751
  35. data/node_modules/govuk-frontend/govuk/components/radios/_index.scss +5 -5
  36. data/node_modules/govuk-frontend/govuk/components/radios/radios.js +1151 -1105
  37. data/node_modules/govuk-frontend/govuk/components/select/_index.scss +7 -1
  38. data/node_modules/govuk-frontend/govuk/components/skip-link/skip-link.js +1045 -1014
  39. data/node_modules/govuk-frontend/govuk/components/summary-list/_index.scss +107 -0
  40. data/node_modules/govuk-frontend/govuk/components/tabs/tabs.js +1514 -1268
  41. data/node_modules/govuk-frontend/govuk/components/tag/_index.scss +18 -18
  42. data/node_modules/govuk-frontend/govuk/components/textarea/_index.scss +8 -1
  43. data/node_modules/govuk-frontend/govuk/core/_all.scss +1 -0
  44. data/node_modules/govuk-frontend/govuk/core/_govuk-frontend-version.scss +5 -0
  45. data/node_modules/govuk-frontend/govuk/helpers/_colour.scss +5 -2
  46. data/node_modules/govuk-frontend/govuk/helpers/_focused.scss +1 -1
  47. data/node_modules/govuk-frontend/govuk/helpers/_font-faces.scss +1 -1
  48. data/node_modules/govuk-frontend/govuk/helpers/_visually-hidden.scss +12 -0
  49. data/node_modules/govuk-frontend/govuk/i18n.js +371 -364
  50. data/node_modules/govuk-frontend/govuk/objects/_template.scss +20 -0
  51. data/node_modules/govuk-frontend/govuk/objects/_width-container.scss +1 -1
  52. data/node_modules/govuk-frontend/govuk/settings/_colours-organisations.scss +4 -0
  53. data/node_modules/govuk-frontend/govuk/settings/_ie8.scss +16 -0
  54. data/node_modules/govuk-frontend/govuk/settings/_links.scss +5 -1
  55. data/node_modules/govuk-frontend/govuk/settings/_measurements.scss +5 -5
  56. data/node_modules/govuk-frontend/govuk/tools/_ie8.scss +38 -2
  57. data/node_modules/govuk-frontend/govuk/vendor/polyfills/DOMTokenList.js +243 -241
  58. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Date/now.js +14 -12
  59. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Document.js +18 -16
  60. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element/prototype/classList.js +553 -545
  61. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element/prototype/closest.js +40 -36
  62. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element/prototype/dataset.js +257 -250
  63. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element/prototype/matches.js +22 -20
  64. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element/prototype/nextElementSibling.js +204 -197
  65. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element/prototype/previousElementSibling.js +204 -197
  66. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element.js +109 -105
  67. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Event.js +407 -399
  68. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Function/prototype/bind.js +242 -238
  69. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Object/defineProperty.js +73 -71
  70. data/node_modules/govuk-frontend/govuk/vendor/polyfills/String/prototype/trim.js +15 -13
  71. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Window.js +18 -16
  72. data/node_modules/govuk-frontend/govuk-prototype-kit/init.js +1 -0
  73. data/package-lock.json +7 -7
  74. data/package.json +1 -1
  75. metadata +8 -3
@@ -4,1111 +4,791 @@
4
4
  (global.GOVUKFrontend = global.GOVUKFrontend || {}, global.GOVUKFrontend.Header = factory());
5
5
  }(this, (function () { 'use strict';
6
6
 
7
- (function(undefined) {
7
+ // @ts-nocheck
8
+ (function (undefined) {
8
9
 
9
- // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Window/detect.js
10
- var detect = ('Window' in this);
10
+ // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Window/detect.js
11
+ var detect = ('Window' in this);
11
12
 
12
- if (detect) return
13
+ if (detect) return
13
14
 
14
- // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Window&flags=always
15
- if ((typeof WorkerGlobalScope === "undefined") && (typeof importScripts !== "function")) {
16
- (function (global) {
17
- if (global.constructor) {
18
- global.Window = global.constructor;
19
- } else {
20
- (global.Window = global.constructor = new Function('return function Window() {}')()).prototype = this;
21
- }
22
- }(this));
23
- }
15
+ // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Window&flags=always
16
+ if ((typeof WorkerGlobalScope === "undefined") && (typeof importScripts !== "function")) {
17
+ (function (global) {
18
+ if (global.constructor) {
19
+ global.Window = global.constructor;
20
+ } else {
21
+ (global.Window = global.constructor = new Function('return function Window() {}')()).prototype = this;
22
+ }
23
+ }(this));
24
+ }
24
25
 
25
- })
26
- .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
26
+ })
27
+ .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
27
28
 
28
- (function(undefined) {
29
+ // @ts-nocheck
30
+ (function (undefined) {
29
31
 
30
- // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Document/detect.js
31
- var detect = ("Document" in this);
32
+ // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Document/detect.js
33
+ var detect = ("Document" in this);
32
34
 
33
- if (detect) return
35
+ if (detect) return
34
36
 
35
- // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Document&flags=always
36
- if ((typeof WorkerGlobalScope === "undefined") && (typeof importScripts !== "function")) {
37
+ // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Document&flags=always
38
+ if ((typeof WorkerGlobalScope === "undefined") && (typeof importScripts !== "function")) {
37
39
 
38
- if (this.HTMLDocument) { // IE8
40
+ if (this.HTMLDocument) { // IE8
39
41
 
40
- // HTMLDocument is an extension of Document. If the browser has HTMLDocument but not Document, the former will suffice as an alias for the latter.
41
- this.Document = this.HTMLDocument;
42
+ // HTMLDocument is an extension of Document. If the browser has HTMLDocument but not Document, the former will suffice as an alias for the latter.
43
+ this.Document = this.HTMLDocument;
42
44
 
43
- } else {
45
+ } else {
44
46
 
45
- // Create an empty function to act as the missing constructor for the document object, attach the document object as its prototype. The function needs to be anonymous else it is hoisted and causes the feature detect to prematurely pass, preventing the assignments below being made.
46
- this.Document = this.HTMLDocument = document.constructor = (new Function('return function Document() {}')());
47
- this.Document.prototype = document;
47
+ // Create an empty function to act as the missing constructor for the document object, attach the document object as its prototype. The function needs to be anonymous else it is hoisted and causes the feature detect to prematurely pass, preventing the assignments below being made.
48
+ this.Document = this.HTMLDocument = document.constructor = (new Function('return function Document() {}')());
49
+ this.Document.prototype = document;
50
+ }
48
51
  }
49
- }
50
-
51
-
52
- })
53
- .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
54
52
 
55
- (function(undefined) {
56
53
 
57
- // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Element/detect.js
58
- var detect = ('Element' in this && 'HTMLElement' in this);
54
+ })
55
+ .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
59
56
 
60
- if (detect) return
57
+ // @ts-nocheck
61
58
 
62
- // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Element&flags=always
63
- (function () {
59
+ (function(undefined) {
64
60
 
65
- // IE8
66
- if (window.Element && !window.HTMLElement) {
67
- window.HTMLElement = window.Element;
68
- return;
69
- }
61
+ // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Element/detect.js
62
+ var detect = ('Element' in this && 'HTMLElement' in this);
70
63
 
71
- // create Element constructor
72
- window.Element = window.HTMLElement = new Function('return function Element() {}')();
64
+ if (detect) return
73
65
 
74
- // generate sandboxed iframe
75
- var vbody = document.appendChild(document.createElement('body'));
76
- var frame = vbody.appendChild(document.createElement('iframe'));
66
+ // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Element&flags=always
67
+ (function () {
77
68
 
78
- // use sandboxed iframe to replicate Element functionality
79
- var frameDocument = frame.contentWindow.document;
80
- var prototype = Element.prototype = frameDocument.appendChild(frameDocument.createElement('*'));
81
- var cache = {};
69
+ // IE8
70
+ if (window.Element && !window.HTMLElement) {
71
+ window.HTMLElement = window.Element;
72
+ return;
73
+ }
82
74
 
83
- // polyfill Element.prototype on an element
84
- var shiv = function (element, deep) {
85
- var
86
- childNodes = element.childNodes || [],
87
- index = -1,
88
- key, value, childNode;
75
+ // create Element constructor
76
+ window.Element = window.HTMLElement = new Function('return function Element() {}')();
89
77
 
90
- if (element.nodeType === 1 && element.constructor !== Element) {
91
- element.constructor = Element;
78
+ // generate sandboxed iframe
79
+ var vbody = document.appendChild(document.createElement('body'));
80
+ var frame = vbody.appendChild(document.createElement('iframe'));
92
81
 
93
- for (key in cache) {
94
- value = cache[key];
95
- element[key] = value;
96
- }
97
- }
82
+ // use sandboxed iframe to replicate Element functionality
83
+ var frameDocument = frame.contentWindow.document;
84
+ var prototype = Element.prototype = frameDocument.appendChild(frameDocument.createElement('*'));
85
+ var cache = {};
98
86
 
99
- while (childNode = deep && childNodes[++index]) {
100
- shiv(childNode, deep);
101
- }
87
+ // polyfill Element.prototype on an element
88
+ var shiv = function (element, deep) {
89
+ var
90
+ childNodes = element.childNodes || [],
91
+ index = -1,
92
+ key, value, childNode;
102
93
 
103
- return element;
104
- };
94
+ if (element.nodeType === 1 && element.constructor !== Element) {
95
+ element.constructor = Element;
105
96
 
106
- var elements = document.getElementsByTagName('*');
107
- var nativeCreateElement = document.createElement;
108
- var interval;
109
- var loopLimit = 100;
110
-
111
- prototype.attachEvent('onpropertychange', function (event) {
112
- var
113
- propertyName = event.propertyName,
114
- nonValue = !cache.hasOwnProperty(propertyName),
115
- newValue = prototype[propertyName],
116
- oldValue = cache[propertyName],
117
- index = -1,
118
- element;
119
-
120
- while (element = elements[++index]) {
121
- if (element.nodeType === 1) {
122
- if (nonValue || element[propertyName] === oldValue) {
123
- element[propertyName] = newValue;
97
+ for (key in cache) {
98
+ value = cache[key];
99
+ element[key] = value;
124
100
  }
125
101
  }
126
- }
127
102
 
128
- cache[propertyName] = newValue;
129
- });
130
-
131
- prototype.constructor = Element;
103
+ while (childNode = deep && childNodes[++index]) {
104
+ shiv(childNode, deep);
105
+ }
132
106
 
133
- if (!prototype.hasAttribute) {
134
- // <Element>.hasAttribute
135
- prototype.hasAttribute = function hasAttribute(name) {
136
- return this.getAttribute(name) !== null;
107
+ return element;
137
108
  };
138
- }
139
-
140
- // Apply Element prototype to the pre-existing DOM as soon as the body element appears.
141
- function bodyCheck() {
142
- if (!(loopLimit--)) clearTimeout(interval);
143
- if (document.body && !document.body.prototype && /(complete|interactive)/.test(document.readyState)) {
144
- shiv(document, true);
145
- if (interval && document.body.prototype) clearTimeout(interval);
146
- return (!!document.body.prototype);
147
- }
148
- return false;
149
- }
150
- if (!bodyCheck()) {
151
- document.onreadystatechange = bodyCheck;
152
- interval = setInterval(bodyCheck, 25);
153
- }
154
109
 
155
- // Apply to any new elements created after load
156
- document.createElement = function createElement(nodeName) {
157
- var element = nativeCreateElement(String(nodeName).toLowerCase());
158
- return shiv(element);
159
- };
110
+ var elements = document.getElementsByTagName('*');
111
+ var nativeCreateElement = document.createElement;
112
+ var interval;
113
+ var loopLimit = 100;
160
114
 
161
- // remove sandboxed iframe
162
- document.removeChild(vbody);
163
- }());
164
-
165
- })
166
- .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
167
-
168
- (function(undefined) {
169
-
170
- // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Object/defineProperty/detect.js
171
- var detect = (
172
- // In IE8, defineProperty could only act on DOM elements, so full support
173
- // for the feature requires the ability to set a property on an arbitrary object
174
- 'defineProperty' in Object && (function() {
175
- try {
176
- var a = {};
177
- Object.defineProperty(a, 'test', {value:42});
178
- return true;
179
- } catch(e) {
180
- return false
181
- }
182
- }())
183
- );
184
-
185
- if (detect) return
186
-
187
- // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Object.defineProperty&flags=always
188
- (function (nativeDefineProperty) {
115
+ prototype.attachEvent('onpropertychange', function (event) {
116
+ var
117
+ propertyName = event.propertyName,
118
+ nonValue = !cache.hasOwnProperty(propertyName),
119
+ newValue = prototype[propertyName],
120
+ oldValue = cache[propertyName],
121
+ index = -1,
122
+ element;
123
+
124
+ while (element = elements[++index]) {
125
+ if (element.nodeType === 1) {
126
+ if (nonValue || element[propertyName] === oldValue) {
127
+ element[propertyName] = newValue;
128
+ }
129
+ }
130
+ }
189
131
 
190
- var supportsAccessors = Object.prototype.hasOwnProperty('__defineGetter__');
191
- var ERR_ACCESSORS_NOT_SUPPORTED = 'Getters & setters cannot be defined on this javascript engine';
192
- var ERR_VALUE_ACCESSORS = 'A property cannot both have accessors and be writable or have a value';
132
+ cache[propertyName] = newValue;
133
+ });
193
134
 
194
- Object.defineProperty = function defineProperty(object, property, descriptor) {
135
+ prototype.constructor = Element;
195
136
 
196
- // Where native support exists, assume it
197
- if (nativeDefineProperty && (object === window || object === document || object === Element.prototype || object instanceof Element)) {
198
- return nativeDefineProperty(object, property, descriptor);
137
+ if (!prototype.hasAttribute) {
138
+ // <Element>.hasAttribute
139
+ prototype.hasAttribute = function hasAttribute(name) {
140
+ return this.getAttribute(name) !== null;
141
+ };
199
142
  }
200
143
 
201
- if (object === null || !(object instanceof Object || typeof object === 'object')) {
202
- throw new TypeError('Object.defineProperty called on non-object');
144
+ // Apply Element prototype to the pre-existing DOM as soon as the body element appears.
145
+ function bodyCheck() {
146
+ if (!(loopLimit--)) clearTimeout(interval);
147
+ if (document.body && !document.body.prototype && /(complete|interactive)/.test(document.readyState)) {
148
+ shiv(document, true);
149
+ if (interval && document.body.prototype) clearTimeout(interval);
150
+ return (!!document.body.prototype);
151
+ }
152
+ return false;
203
153
  }
204
-
205
- if (!(descriptor instanceof Object)) {
206
- throw new TypeError('Property description must be an object');
154
+ if (!bodyCheck()) {
155
+ document.onreadystatechange = bodyCheck;
156
+ interval = setInterval(bodyCheck, 25);
207
157
  }
208
158
 
209
- var propertyString = String(property);
210
- var hasValueOrWritable = 'value' in descriptor || 'writable' in descriptor;
211
- var getterType = 'get' in descriptor && typeof descriptor.get;
212
- var setterType = 'set' in descriptor && typeof descriptor.set;
159
+ // Apply to any new elements created after load
160
+ document.createElement = function createElement(nodeName) {
161
+ var element = nativeCreateElement(String(nodeName).toLowerCase());
162
+ return shiv(element);
163
+ };
213
164
 
214
- // handle descriptor.get
215
- if (getterType) {
216
- if (getterType !== 'function') {
217
- throw new TypeError('Getter must be a function');
165
+ // remove sandboxed iframe
166
+ document.removeChild(vbody);
167
+ }());
168
+
169
+ })
170
+ .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
171
+
172
+ // @ts-nocheck
173
+ (function (undefined) {
174
+
175
+ // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Object/defineProperty/detect.js
176
+ var detect = (
177
+ // In IE8, defineProperty could only act on DOM elements, so full support
178
+ // for the feature requires the ability to set a property on an arbitrary object
179
+ 'defineProperty' in Object && (function() {
180
+ try {
181
+ var a = {};
182
+ Object.defineProperty(a, 'test', {value:42});
183
+ return true;
184
+ } catch(e) {
185
+ return false
186
+ }
187
+ }())
188
+ );
189
+
190
+ if (detect) return
191
+
192
+ // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Object.defineProperty&flags=always
193
+ (function (nativeDefineProperty) {
194
+
195
+ var supportsAccessors = Object.prototype.hasOwnProperty('__defineGetter__');
196
+ var ERR_ACCESSORS_NOT_SUPPORTED = 'Getters & setters cannot be defined on this javascript engine';
197
+ var ERR_VALUE_ACCESSORS = 'A property cannot both have accessors and be writable or have a value';
198
+
199
+ Object.defineProperty = function defineProperty(object, property, descriptor) {
200
+
201
+ // Where native support exists, assume it
202
+ if (nativeDefineProperty && (object === window || object === document || object === Element.prototype || object instanceof Element)) {
203
+ return nativeDefineProperty(object, property, descriptor);
218
204
  }
219
- if (!supportsAccessors) {
220
- throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
221
- }
222
- if (hasValueOrWritable) {
223
- throw new TypeError(ERR_VALUE_ACCESSORS);
205
+
206
+ if (object === null || !(object instanceof Object || typeof object === 'object')) {
207
+ throw new TypeError('Object.defineProperty called on non-object');
224
208
  }
225
- Object.__defineGetter__.call(object, propertyString, descriptor.get);
226
- } else {
227
- object[propertyString] = descriptor.value;
228
- }
229
209
 
230
- // handle descriptor.set
231
- if (setterType) {
232
- if (setterType !== 'function') {
233
- throw new TypeError('Setter must be a function');
210
+ if (!(descriptor instanceof Object)) {
211
+ throw new TypeError('Property description must be an object');
234
212
  }
235
- if (!supportsAccessors) {
236
- throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
213
+
214
+ var propertyString = String(property);
215
+ var hasValueOrWritable = 'value' in descriptor || 'writable' in descriptor;
216
+ var getterType = 'get' in descriptor && typeof descriptor.get;
217
+ var setterType = 'set' in descriptor && typeof descriptor.set;
218
+
219
+ // handle descriptor.get
220
+ if (getterType) {
221
+ if (getterType !== 'function') {
222
+ throw new TypeError('Getter must be a function');
223
+ }
224
+ if (!supportsAccessors) {
225
+ throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
226
+ }
227
+ if (hasValueOrWritable) {
228
+ throw new TypeError(ERR_VALUE_ACCESSORS);
229
+ }
230
+ Object.__defineGetter__.call(object, propertyString, descriptor.get);
231
+ } else {
232
+ object[propertyString] = descriptor.value;
237
233
  }
238
- if (hasValueOrWritable) {
239
- throw new TypeError(ERR_VALUE_ACCESSORS);
234
+
235
+ // handle descriptor.set
236
+ if (setterType) {
237
+ if (setterType !== 'function') {
238
+ throw new TypeError('Setter must be a function');
239
+ }
240
+ if (!supportsAccessors) {
241
+ throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
242
+ }
243
+ if (hasValueOrWritable) {
244
+ throw new TypeError(ERR_VALUE_ACCESSORS);
245
+ }
246
+ Object.__defineSetter__.call(object, propertyString, descriptor.set);
240
247
  }
241
- Object.__defineSetter__.call(object, propertyString, descriptor.set);
242
- }
243
248
 
244
- // OK to define value unconditionally - if a getter has been specified as well, an error would be thrown above
245
- if ('value' in descriptor) {
246
- object[propertyString] = descriptor.value;
247
- }
249
+ // OK to define value unconditionally - if a getter has been specified as well, an error would be thrown above
250
+ if ('value' in descriptor) {
251
+ object[propertyString] = descriptor.value;
252
+ }
248
253
 
249
- return object;
250
- };
251
- }(Object.defineProperty));
252
- })
253
- .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
254
-
255
- (function(undefined) {
256
-
257
- // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Event/detect.js
258
- var detect = (
259
- (function(global) {
260
-
261
- if (!('Event' in global)) return false;
262
- if (typeof global.Event === 'function') return true;
263
-
264
- try {
265
-
266
- // In IE 9-11, the Event object exists but cannot be instantiated
267
- new Event('click');
268
- return true;
269
- } catch(e) {
270
- return false;
271
- }
272
- }(this))
273
- );
274
-
275
- if (detect) return
276
-
277
- // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Event&flags=always
278
- (function () {
279
- var unlistenableWindowEvents = {
280
- click: 1,
281
- dblclick: 1,
282
- keyup: 1,
283
- keypress: 1,
284
- keydown: 1,
285
- mousedown: 1,
286
- mouseup: 1,
287
- mousemove: 1,
288
- mouseover: 1,
289
- mouseenter: 1,
290
- mouseleave: 1,
291
- mouseout: 1,
292
- storage: 1,
293
- storagecommit: 1,
294
- textinput: 1
295
- };
254
+ return object;
255
+ };
256
+ }(Object.defineProperty));
257
+ })
258
+ .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
259
+
260
+ // @ts-nocheck
261
+
262
+ (function(undefined) {
263
+
264
+ // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Event/detect.js
265
+ var detect = (
266
+ (function(global) {
267
+
268
+ if (!('Event' in global)) return false;
269
+ if (typeof global.Event === 'function') return true;
270
+
271
+ try {
272
+
273
+ // In IE 9-11, the Event object exists but cannot be instantiated
274
+ new Event('click');
275
+ return true;
276
+ } catch(e) {
277
+ return false;
278
+ }
279
+ }(this))
280
+ );
281
+
282
+ if (detect) return
283
+
284
+ // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Event&flags=always
285
+ (function () {
286
+ var unlistenableWindowEvents = {
287
+ click: 1,
288
+ dblclick: 1,
289
+ keyup: 1,
290
+ keypress: 1,
291
+ keydown: 1,
292
+ mousedown: 1,
293
+ mouseup: 1,
294
+ mousemove: 1,
295
+ mouseover: 1,
296
+ mouseenter: 1,
297
+ mouseleave: 1,
298
+ mouseout: 1,
299
+ storage: 1,
300
+ storagecommit: 1,
301
+ textinput: 1
302
+ };
296
303
 
297
- // This polyfill depends on availability of `document` so will not run in a worker
298
- // However, we asssume there are no browsers with worker support that lack proper
299
- // support for `Event` within the worker
300
- if (typeof document === 'undefined' || typeof window === 'undefined') return;
304
+ // This polyfill depends on availability of `document` so will not run in a worker
305
+ // However, we asssume there are no browsers with worker support that lack proper
306
+ // support for `Event` within the worker
307
+ if (typeof document === 'undefined' || typeof window === 'undefined') return;
301
308
 
302
- function indexOf(array, element) {
303
- var
304
- index = -1,
305
- length = array.length;
309
+ function indexOf(array, element) {
310
+ var
311
+ index = -1,
312
+ length = array.length;
306
313
 
307
- while (++index < length) {
308
- if (index in array && array[index] === element) {
309
- return index;
314
+ while (++index < length) {
315
+ if (index in array && array[index] === element) {
316
+ return index;
317
+ }
310
318
  }
319
+
320
+ return -1;
311
321
  }
312
322
 
313
- return -1;
314
- }
323
+ var existingProto = (window.Event && window.Event.prototype) || null;
324
+ window.Event = Window.prototype.Event = function Event(type, eventInitDict) {
325
+ if (!type) {
326
+ throw new Error('Not enough arguments');
327
+ }
315
328
 
316
- var existingProto = (window.Event && window.Event.prototype) || null;
317
- window.Event = Window.prototype.Event = function Event(type, eventInitDict) {
318
- if (!type) {
319
- throw new Error('Not enough arguments');
320
- }
329
+ var event;
330
+ // Shortcut if browser supports createEvent
331
+ if ('createEvent' in document) {
332
+ event = document.createEvent('Event');
333
+ var bubbles = eventInitDict && eventInitDict.bubbles !== undefined ? eventInitDict.bubbles : false;
334
+ var cancelable = eventInitDict && eventInitDict.cancelable !== undefined ? eventInitDict.cancelable : false;
335
+
336
+ event.initEvent(type, bubbles, cancelable);
321
337
 
322
- var event;
323
- // Shortcut if browser supports createEvent
324
- if ('createEvent' in document) {
325
- event = document.createEvent('Event');
326
- var bubbles = eventInitDict && eventInitDict.bubbles !== undefined ? eventInitDict.bubbles : false;
327
- var cancelable = eventInitDict && eventInitDict.cancelable !== undefined ? eventInitDict.cancelable : false;
338
+ return event;
339
+ }
340
+
341
+ event = document.createEventObject();
328
342
 
329
- event.initEvent(type, bubbles, cancelable);
343
+ event.type = type;
344
+ event.bubbles = eventInitDict && eventInitDict.bubbles !== undefined ? eventInitDict.bubbles : false;
345
+ event.cancelable = eventInitDict && eventInitDict.cancelable !== undefined ? eventInitDict.cancelable : false;
330
346
 
331
347
  return event;
348
+ };
349
+ if (existingProto) {
350
+ Object.defineProperty(window.Event, 'prototype', {
351
+ configurable: false,
352
+ enumerable: false,
353
+ writable: true,
354
+ value: existingProto
355
+ });
332
356
  }
333
357
 
334
- event = document.createEventObject();
358
+ if (!('createEvent' in document)) {
359
+ window.addEventListener = Window.prototype.addEventListener = Document.prototype.addEventListener = Element.prototype.addEventListener = function addEventListener() {
360
+ var
361
+ element = this,
362
+ type = arguments[0],
363
+ listener = arguments[1];
335
364
 
336
- event.type = type;
337
- event.bubbles = eventInitDict && eventInitDict.bubbles !== undefined ? eventInitDict.bubbles : false;
338
- event.cancelable = eventInitDict && eventInitDict.cancelable !== undefined ? eventInitDict.cancelable : false;
365
+ if (element === window && type in unlistenableWindowEvents) {
366
+ throw new Error('In IE8 the event: ' + type + ' is not available on the window object. Please see https://github.com/Financial-Times/polyfill-service/issues/317 for more information.');
367
+ }
339
368
 
340
- return event;
341
- };
342
- if (existingProto) {
343
- Object.defineProperty(window.Event, 'prototype', {
344
- configurable: false,
345
- enumerable: false,
346
- writable: true,
347
- value: existingProto
348
- });
349
- }
369
+ if (!element._events) {
370
+ element._events = {};
371
+ }
350
372
 
351
- if (!('createEvent' in document)) {
352
- window.addEventListener = Window.prototype.addEventListener = Document.prototype.addEventListener = Element.prototype.addEventListener = function addEventListener() {
353
- var
354
- element = this,
355
- type = arguments[0],
356
- listener = arguments[1];
373
+ if (!element._events[type]) {
374
+ element._events[type] = function (event) {
375
+ var
376
+ list = element._events[event.type].list,
377
+ events = list.slice(),
378
+ index = -1,
379
+ length = events.length,
380
+ eventElement;
381
+
382
+ event.preventDefault = function preventDefault() {
383
+ if (event.cancelable !== false) {
384
+ event.returnValue = false;
385
+ }
386
+ };
357
387
 
358
- if (element === window && type in unlistenableWindowEvents) {
359
- throw new Error('In IE8 the event: ' + type + ' is not available on the window object. Please see https://github.com/Financial-Times/polyfill-service/issues/317 for more information.');
360
- }
388
+ event.stopPropagation = function stopPropagation() {
389
+ event.cancelBubble = true;
390
+ };
361
391
 
362
- if (!element._events) {
363
- element._events = {};
364
- }
392
+ event.stopImmediatePropagation = function stopImmediatePropagation() {
393
+ event.cancelBubble = true;
394
+ event.cancelImmediate = true;
395
+ };
396
+
397
+ event.currentTarget = element;
398
+ event.relatedTarget = event.fromElement || null;
399
+ event.target = event.target || event.srcElement || element;
400
+ event.timeStamp = new Date().getTime();
365
401
 
366
- if (!element._events[type]) {
367
- element._events[type] = function (event) {
368
- var
369
- list = element._events[event.type].list,
370
- events = list.slice(),
371
- index = -1,
372
- length = events.length,
373
- eventElement;
374
-
375
- event.preventDefault = function preventDefault() {
376
- if (event.cancelable !== false) {
377
- event.returnValue = false;
402
+ if (event.clientX) {
403
+ event.pageX = event.clientX + document.documentElement.scrollLeft;
404
+ event.pageY = event.clientY + document.documentElement.scrollTop;
378
405
  }
379
- };
380
406
 
381
- event.stopPropagation = function stopPropagation() {
382
- event.cancelBubble = true;
383
- };
407
+ while (++index < length && !event.cancelImmediate) {
408
+ if (index in events) {
409
+ eventElement = events[index];
384
410
 
385
- event.stopImmediatePropagation = function stopImmediatePropagation() {
386
- event.cancelBubble = true;
387
- event.cancelImmediate = true;
411
+ if (indexOf(list, eventElement) !== -1 && typeof eventElement === 'function') {
412
+ eventElement.call(element, event);
413
+ }
414
+ }
415
+ }
388
416
  };
389
417
 
390
- event.currentTarget = element;
391
- event.relatedTarget = event.fromElement || null;
392
- event.target = event.target || event.srcElement || element;
393
- event.timeStamp = new Date().getTime();
418
+ element._events[type].list = [];
394
419
 
395
- if (event.clientX) {
396
- event.pageX = event.clientX + document.documentElement.scrollLeft;
397
- event.pageY = event.clientY + document.documentElement.scrollTop;
420
+ if (element.attachEvent) {
421
+ element.attachEvent('on' + type, element._events[type]);
398
422
  }
423
+ }
424
+
425
+ element._events[type].list.push(listener);
426
+ };
427
+
428
+ window.removeEventListener = Window.prototype.removeEventListener = Document.prototype.removeEventListener = Element.prototype.removeEventListener = function removeEventListener() {
429
+ var
430
+ element = this,
431
+ type = arguments[0],
432
+ listener = arguments[1],
433
+ index;
434
+
435
+ if (element._events && element._events[type] && element._events[type].list) {
436
+ index = indexOf(element._events[type].list, listener);
399
437
 
400
- while (++index < length && !event.cancelImmediate) {
401
- if (index in events) {
402
- eventElement = events[index];
438
+ if (index !== -1) {
439
+ element._events[type].list.splice(index, 1);
403
440
 
404
- if (indexOf(list, eventElement) !== -1 && typeof eventElement === 'function') {
405
- eventElement.call(element, event);
441
+ if (!element._events[type].list.length) {
442
+ if (element.detachEvent) {
443
+ element.detachEvent('on' + type, element._events[type]);
406
444
  }
445
+ delete element._events[type];
407
446
  }
408
447
  }
409
- };
448
+ }
449
+ };
410
450
 
411
- element._events[type].list = [];
451
+ window.dispatchEvent = Window.prototype.dispatchEvent = Document.prototype.dispatchEvent = Element.prototype.dispatchEvent = function dispatchEvent(event) {
452
+ if (!arguments.length) {
453
+ throw new Error('Not enough arguments');
454
+ }
412
455
 
413
- if (element.attachEvent) {
414
- element.attachEvent('on' + type, element._events[type]);
456
+ if (!event || typeof event.type !== 'string') {
457
+ throw new Error('DOM Events Exception 0');
415
458
  }
416
- }
417
459
 
418
- element._events[type].list.push(listener);
419
- };
460
+ var element = this, type = event.type;
420
461
 
421
- window.removeEventListener = Window.prototype.removeEventListener = Document.prototype.removeEventListener = Element.prototype.removeEventListener = function removeEventListener() {
422
- var
423
- element = this,
424
- type = arguments[0],
425
- listener = arguments[1],
426
- index;
462
+ try {
463
+ if (!event.bubbles) {
464
+ event.cancelBubble = true;
427
465
 
428
- if (element._events && element._events[type] && element._events[type].list) {
429
- index = indexOf(element._events[type].list, listener);
466
+ var cancelBubbleEvent = function (event) {
467
+ event.cancelBubble = true;
430
468
 
431
- if (index !== -1) {
432
- element._events[type].list.splice(index, 1);
469
+ (element || window).detachEvent('on' + type, cancelBubbleEvent);
470
+ };
433
471
 
434
- if (!element._events[type].list.length) {
435
- if (element.detachEvent) {
436
- element.detachEvent('on' + type, element._events[type]);
437
- }
438
- delete element._events[type];
472
+ this.attachEvent('on' + type, cancelBubbleEvent);
439
473
  }
440
- }
441
- }
442
- };
443
474
 
444
- window.dispatchEvent = Window.prototype.dispatchEvent = Document.prototype.dispatchEvent = Element.prototype.dispatchEvent = function dispatchEvent(event) {
445
- if (!arguments.length) {
446
- throw new Error('Not enough arguments');
447
- }
448
-
449
- if (!event || typeof event.type !== 'string') {
450
- throw new Error('DOM Events Exception 0');
451
- }
452
-
453
- var element = this, type = event.type;
475
+ this.fireEvent('on' + type, event);
476
+ } catch (error) {
477
+ event.target = element;
454
478
 
455
- try {
456
- if (!event.bubbles) {
457
- event.cancelBubble = true;
479
+ do {
480
+ event.currentTarget = element;
458
481
 
459
- var cancelBubbleEvent = function (event) {
460
- event.cancelBubble = true;
482
+ if ('_events' in element && typeof element._events[type] === 'function') {
483
+ element._events[type].call(element, event);
484
+ }
461
485
 
462
- (element || window).detachEvent('on' + type, cancelBubbleEvent);
463
- };
486
+ if (typeof element['on' + type] === 'function') {
487
+ element['on' + type].call(element, event);
488
+ }
464
489
 
465
- this.attachEvent('on' + type, cancelBubbleEvent);
490
+ element = element.nodeType === 9 ? element.parentWindow : element.parentNode;
491
+ } while (element && !event.cancelBubble);
466
492
  }
467
493
 
468
- this.fireEvent('on' + type, event);
469
- } catch (error) {
470
- event.target = element;
471
-
472
- do {
473
- event.currentTarget = element;
494
+ return true;
495
+ };
474
496
 
475
- if ('_events' in element && typeof element._events[type] === 'function') {
476
- element._events[type].call(element, event);
477
- }
497
+ // Add the DOMContentLoaded Event
498
+ document.attachEvent('onreadystatechange', function() {
499
+ if (document.readyState === 'complete') {
500
+ document.dispatchEvent(new Event('DOMContentLoaded', {
501
+ bubbles: true
502
+ }));
503
+ }
504
+ });
505
+ }
506
+ }());
507
+
508
+ })
509
+ .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
510
+
511
+ // @ts-nocheck
512
+
513
+ (function(undefined) {
514
+ // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Function/prototype/bind/detect.js
515
+ var detect = 'bind' in Function.prototype;
516
+
517
+ if (detect) return
518
+
519
+ // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Function.prototype.bind&flags=always
520
+ Object.defineProperty(Function.prototype, 'bind', {
521
+ value: function bind(that) { // .length is 1
522
+ // add necessary es5-shim utilities
523
+ var $Array = Array;
524
+ var $Object = Object;
525
+ var ObjectPrototype = $Object.prototype;
526
+ var ArrayPrototype = $Array.prototype;
527
+ var Empty = function Empty() {};
528
+ var to_string = ObjectPrototype.toString;
529
+ var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';
530
+ var isCallable; /* inlined from https://npmjs.com/is-callable */ var fnToStr = Function.prototype.toString, tryFunctionObject = function tryFunctionObject(value) { try { fnToStr.call(value); return true; } catch (e) { return false; } }, fnClass = '[object Function]', genClass = '[object GeneratorFunction]'; isCallable = function isCallable(value) { if (typeof value !== 'function') { return false; } if (hasToStringTag) { return tryFunctionObject(value); } var strClass = to_string.call(value); return strClass === fnClass || strClass === genClass; };
531
+ var array_slice = ArrayPrototype.slice;
532
+ var array_concat = ArrayPrototype.concat;
533
+ var array_push = ArrayPrototype.push;
534
+ var max = Math.max;
535
+ // /add necessary es5-shim utilities
536
+
537
+ // 1. Let Target be the this value.
538
+ var target = this;
539
+ // 2. If IsCallable(Target) is false, throw a TypeError exception.
540
+ if (!isCallable(target)) {
541
+ throw new TypeError('Function.prototype.bind called on incompatible ' + target);
542
+ }
543
+ // 3. Let A be a new (possibly empty) internal list of all of the
544
+ // argument values provided after thisArg (arg1, arg2 etc), in order.
545
+ // XXX slicedArgs will stand in for "A" if used
546
+ var args = array_slice.call(arguments, 1); // for normal call
547
+ // 4. Let F be a new native ECMAScript object.
548
+ // 11. Set the [[Prototype]] internal property of F to the standard
549
+ // built-in Function prototype object as specified in 15.3.3.1.
550
+ // 12. Set the [[Call]] internal property of F as described in
551
+ // 15.3.4.5.1.
552
+ // 13. Set the [[Construct]] internal property of F as described in
553
+ // 15.3.4.5.2.
554
+ // 14. Set the [[HasInstance]] internal property of F as described in
555
+ // 15.3.4.5.3.
556
+ var bound;
557
+ var binder = function () {
558
+
559
+ if (this instanceof bound) {
560
+ // 15.3.4.5.2 [[Construct]]
561
+ // When the [[Construct]] internal method of a function object,
562
+ // F that was created using the bind function is called with a
563
+ // list of arguments ExtraArgs, the following steps are taken:
564
+ // 1. Let target be the value of F's [[TargetFunction]]
565
+ // internal property.
566
+ // 2. If target has no [[Construct]] internal method, a
567
+ // TypeError exception is thrown.
568
+ // 3. Let boundArgs be the value of F's [[BoundArgs]] internal
569
+ // property.
570
+ // 4. Let args be a new list containing the same values as the
571
+ // list boundArgs in the same order followed by the same
572
+ // values as the list ExtraArgs in the same order.
573
+ // 5. Return the result of calling the [[Construct]] internal
574
+ // method of target providing args as the arguments.
575
+
576
+ var result = target.apply(
577
+ this,
578
+ array_concat.call(args, array_slice.call(arguments))
579
+ );
580
+ if ($Object(result) === result) {
581
+ return result;
582
+ }
583
+ return this;
584
+
585
+ } else {
586
+ // 15.3.4.5.1 [[Call]]
587
+ // When the [[Call]] internal method of a function object, F,
588
+ // which was created using the bind function is called with a
589
+ // this value and a list of arguments ExtraArgs, the following
590
+ // steps are taken:
591
+ // 1. Let boundArgs be the value of F's [[BoundArgs]] internal
592
+ // property.
593
+ // 2. Let boundThis be the value of F's [[BoundThis]] internal
594
+ // property.
595
+ // 3. Let target be the value of F's [[TargetFunction]] internal
596
+ // property.
597
+ // 4. Let args be a new list containing the same values as the
598
+ // list boundArgs in the same order followed by the same
599
+ // values as the list ExtraArgs in the same order.
600
+ // 5. Return the result of calling the [[Call]] internal method
601
+ // of target providing boundThis as the this value and
602
+ // providing args as the arguments.
603
+
604
+ // equiv: target.call(this, ...boundArgs, ...args)
605
+ return target.apply(
606
+ that,
607
+ array_concat.call(args, array_slice.call(arguments))
608
+ );
609
+
610
+ }
611
+
612
+ };
613
+
614
+ // 15. If the [[Class]] internal property of Target is "Function", then
615
+ // a. Let L be the length property of Target minus the length of A.
616
+ // b. Set the length own property of F to either 0 or L, whichever is
617
+ // larger.
618
+ // 16. Else set the length own property of F to 0.
619
+
620
+ var boundLength = max(0, target.length - args.length);
621
+
622
+ // 17. Set the attributes of the length own property of F to the values
623
+ // specified in 15.3.5.1.
624
+ var boundArgs = [];
625
+ for (var i = 0; i < boundLength; i++) {
626
+ array_push.call(boundArgs, '$' + i);
627
+ }
628
+
629
+ // XXX Build a dynamic function with desired amount of arguments is the only
630
+ // way to set the length property of a function.
631
+ // In environments where Content Security Policies enabled (Chrome extensions,
632
+ // for ex.) all use of eval or Function costructor throws an exception.
633
+ // However in all of these environments Function.prototype.bind exists
634
+ // and so this code will never be executed.
635
+ bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this, arguments); }')(binder);
636
+
637
+ if (target.prototype) {
638
+ Empty.prototype = target.prototype;
639
+ bound.prototype = new Empty();
640
+ // Clean up dangling references.
641
+ Empty.prototype = null;
642
+ }
643
+
644
+ // TODO
645
+ // 18. Set the [[Extensible]] internal property of F to true.
646
+
647
+ // TODO
648
+ // 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3).
649
+ // 20. Call the [[DefineOwnProperty]] internal method of F with
650
+ // arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]:
651
+ // thrower, [[Enumerable]]: false, [[Configurable]]: false}, and
652
+ // false.
653
+ // 21. Call the [[DefineOwnProperty]] internal method of F with
654
+ // arguments "arguments", PropertyDescriptor {[[Get]]: thrower,
655
+ // [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false},
656
+ // and false.
657
+
658
+ // TODO
659
+ // NOTE Function objects created using Function.prototype.bind do not
660
+ // have a prototype property or the [[Code]], [[FormalParameters]], and
661
+ // [[Scope]] internal properties.
662
+ // XXX can't delete prototype in pure-js.
663
+
664
+ // 22. Return F.
665
+ return bound;
666
+ }
667
+ });
668
+ })
669
+ .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
670
+
671
+ /* eslint-disable es-x/no-function-prototype-bind -- Polyfill imported */
672
+
673
+ /**
674
+ * Header component
675
+ *
676
+ * @class
677
+ * @param {Element} $module - HTML element to use for header
678
+ */
679
+ function Header ($module) {
680
+ if (!($module instanceof HTMLElement)) {
681
+ return this
682
+ }
683
+
684
+ /** @deprecated Will be made private in v5.0 */
685
+ this.$module = $module;
686
+
687
+ /** @deprecated Will be made private in v5.0 */
688
+ this.$menuButton = $module.querySelector('.govuk-js-header-toggle');
689
+
690
+ /** @deprecated Will be made private in v5.0 */
691
+ this.$menu = this.$menuButton && $module.querySelector(
692
+ '#' + this.$menuButton.getAttribute('aria-controls')
693
+ );
694
+
695
+ /**
696
+ * Save the opened/closed state for the nav in memory so that we can
697
+ * accurately maintain state when the screen is changed from small to
698
+ * big and back to small
699
+ *
700
+ * @deprecated Will be made private in v5.0
701
+ */
702
+ this.menuIsOpen = false;
703
+
704
+ /**
705
+ * A global const for storing a matchMedia instance which we'll use to
706
+ * detect when a screen size change happens. We set this later during the
707
+ * init function and rely on it being null if the feature isn't available
708
+ * to initially apply hidden attributes
709
+ *
710
+ * @deprecated Will be made private in v5.0
711
+ */
712
+ this.mql = null;
713
+ }
478
714
 
479
- if (typeof element['on' + type] === 'function') {
480
- element['on' + type].call(element, event);
481
- }
715
+ /**
716
+ * Initialise component
717
+ *
718
+ * Check for the presence of the header, menu and menu button – if any are
719
+ * missing then there's nothing to do so return early.
720
+ * Feature sniff for and apply a matchMedia for desktop which will
721
+ * trigger a state sync if the browser viewport moves between states. If
722
+ * matchMedia isn't available, hide the menu button and present the "no js"
723
+ * version of the menu to the user.
724
+ */
725
+ Header.prototype.init = function () {
726
+ // Check that required elements are present
727
+ if (!this.$module || !this.$menuButton || !this.$menu) {
728
+ return
729
+ }
730
+
731
+ if ('matchMedia' in window) {
732
+ // Set the matchMedia to the govuk-frontend desktop breakpoint
733
+ this.mql = window.matchMedia('(min-width: 48.0625em)');
734
+
735
+ if ('addEventListener' in this.mql) {
736
+ this.mql.addEventListener('change', this.syncState.bind(this));
737
+ } else {
738
+ // addListener is a deprecated function, however addEventListener
739
+ // isn't supported by IE or Safari < 14. We therefore add this in as
740
+ // a fallback for those browsers
741
+ // @ts-expect-error Property 'addListener' does not exist
742
+ this.mql.addListener(this.syncState.bind(this));
743
+ }
744
+
745
+ this.syncState();
746
+ this.$menuButton.addEventListener('click', this.handleMenuButtonClick.bind(this));
747
+ } else {
748
+ this.$menuButton.setAttribute('hidden', '');
749
+ }
750
+ };
482
751
 
483
- element = element.nodeType === 9 ? element.parentWindow : element.parentNode;
484
- } while (element && !event.cancelBubble);
485
- }
752
+ /**
753
+ * Sync menu state
754
+ *
755
+ * Uses the global variable menuIsOpen to correctly set the accessible and
756
+ * visual states of the menu and the menu button.
757
+ * Additionally will force the menu to be visible and the menu button to be
758
+ * hidden if the matchMedia is triggered to desktop.
759
+ *
760
+ * @deprecated Will be made private in v5.0
761
+ */
762
+ Header.prototype.syncState = function () {
763
+ if (this.mql.matches) {
764
+ this.$menu.removeAttribute('hidden');
765
+ this.$menuButton.setAttribute('hidden', '');
766
+ } else {
767
+ this.$menuButton.removeAttribute('hidden');
768
+ this.$menuButton.setAttribute('aria-expanded', this.menuIsOpen.toString());
769
+
770
+ if (this.menuIsOpen) {
771
+ this.$menu.removeAttribute('hidden');
772
+ } else {
773
+ this.$menu.setAttribute('hidden', '');
774
+ }
775
+ }
776
+ };
486
777
 
487
- return true;
488
- };
778
+ /**
779
+ * Handle menu button click
780
+ *
781
+ * When the menu button is clicked, change the visibility of the menu and then
782
+ * sync the accessibility state and menu button state
783
+ *
784
+ * @deprecated Will be made private in v5.0
785
+ */
786
+ Header.prototype.handleMenuButtonClick = function () {
787
+ this.menuIsOpen = !this.menuIsOpen;
788
+ this.syncState();
789
+ };
489
790
 
490
- // Add the DOMContentLoaded Event
491
- document.attachEvent('onreadystatechange', function() {
492
- if (document.readyState === 'complete') {
493
- document.dispatchEvent(new Event('DOMContentLoaded', {
494
- bubbles: true
495
- }));
496
- }
497
- });
498
- }
499
- }());
500
-
501
- })
502
- .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
503
-
504
- (function(undefined) {
505
-
506
- // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-service/master/packages/polyfill-library/polyfills/DOMTokenList/detect.js
507
- var detect = (
508
- 'DOMTokenList' in this && (function (x) {
509
- return 'classList' in x ? !x.classList.toggle('x', false) && !x.className : true;
510
- })(document.createElement('x'))
511
- );
512
-
513
- if (detect) return
514
-
515
- // Polyfill from https://raw.githubusercontent.com/Financial-Times/polyfill-service/master/packages/polyfill-library/polyfills/DOMTokenList/polyfill.js
516
- (function (global) {
517
- var nativeImpl = "DOMTokenList" in global && global.DOMTokenList;
518
-
519
- if (
520
- !nativeImpl ||
521
- (
522
- !!document.createElementNS &&
523
- !!document.createElementNS('http://www.w3.org/2000/svg', 'svg') &&
524
- !(document.createElementNS("http://www.w3.org/2000/svg", "svg").classList instanceof DOMTokenList)
525
- )
526
- ) {
527
- global.DOMTokenList = (function() { // eslint-disable-line no-unused-vars
528
- var dpSupport = true;
529
- var defineGetter = function (object, name, fn, configurable) {
530
- if (Object.defineProperty)
531
- Object.defineProperty(object, name, {
532
- configurable: false === dpSupport ? true : !!configurable,
533
- get: fn
534
- });
535
-
536
- else object.__defineGetter__(name, fn);
537
- };
538
-
539
- /** Ensure the browser allows Object.defineProperty to be used on native JavaScript objects. */
540
- try {
541
- defineGetter({}, "support");
542
- }
543
- catch (e) {
544
- dpSupport = false;
545
- }
546
-
547
-
548
- var _DOMTokenList = function (el, prop) {
549
- var that = this;
550
- var tokens = [];
551
- var tokenMap = {};
552
- var length = 0;
553
- var maxLength = 0;
554
- var addIndexGetter = function (i) {
555
- defineGetter(that, i, function () {
556
- preop();
557
- return tokens[i];
558
- }, false);
559
-
560
- };
561
- var reindex = function () {
562
-
563
- /** Define getter functions for array-like access to the tokenList's contents. */
564
- if (length >= maxLength)
565
- for (; maxLength < length; ++maxLength) {
566
- addIndexGetter(maxLength);
567
- }
568
- };
569
-
570
- /** Helper function called at the start of each class method. Internal use only. */
571
- var preop = function () {
572
- var error;
573
- var i;
574
- var args = arguments;
575
- var rSpace = /\s+/;
576
-
577
- /** Validate the token/s passed to an instance method, if any. */
578
- if (args.length)
579
- for (i = 0; i < args.length; ++i)
580
- if (rSpace.test(args[i])) {
581
- error = new SyntaxError('String "' + args[i] + '" ' + "contains" + ' an invalid character');
582
- error.code = 5;
583
- error.name = "InvalidCharacterError";
584
- throw error;
585
- }
586
-
587
-
588
- /** Split the new value apart by whitespace*/
589
- if (typeof el[prop] === "object") {
590
- tokens = ("" + el[prop].baseVal).replace(/^\s+|\s+$/g, "").split(rSpace);
591
- } else {
592
- tokens = ("" + el[prop]).replace(/^\s+|\s+$/g, "").split(rSpace);
593
- }
594
-
595
- /** Avoid treating blank strings as single-item token lists */
596
- if ("" === tokens[0]) tokens = [];
597
-
598
- /** Repopulate the internal token lists */
599
- tokenMap = {};
600
- for (i = 0; i < tokens.length; ++i)
601
- tokenMap[tokens[i]] = true;
602
- length = tokens.length;
603
- reindex();
604
- };
605
-
606
- /** Populate our internal token list if the targeted attribute of the subject element isn't empty. */
607
- preop();
608
-
609
- /** Return the number of tokens in the underlying string. Read-only. */
610
- defineGetter(that, "length", function () {
611
- preop();
612
- return length;
613
- });
614
-
615
- /** Override the default toString/toLocaleString methods to return a space-delimited list of tokens when typecast. */
616
- that.toLocaleString =
617
- that.toString = function () {
618
- preop();
619
- return tokens.join(" ");
620
- };
621
-
622
- that.item = function (idx) {
623
- preop();
624
- return tokens[idx];
625
- };
626
-
627
- that.contains = function (token) {
628
- preop();
629
- return !!tokenMap[token];
630
- };
631
-
632
- that.add = function () {
633
- preop.apply(that, args = arguments);
634
-
635
- for (var args, token, i = 0, l = args.length; i < l; ++i) {
636
- token = args[i];
637
- if (!tokenMap[token]) {
638
- tokens.push(token);
639
- tokenMap[token] = true;
640
- }
641
- }
642
-
643
- /** Update the targeted attribute of the attached element if the token list's changed. */
644
- if (length !== tokens.length) {
645
- length = tokens.length >>> 0;
646
- if (typeof el[prop] === "object") {
647
- el[prop].baseVal = tokens.join(" ");
648
- } else {
649
- el[prop] = tokens.join(" ");
650
- }
651
- reindex();
652
- }
653
- };
654
-
655
- that.remove = function () {
656
- preop.apply(that, args = arguments);
657
-
658
- /** Build a hash of token names to compare against when recollecting our token list. */
659
- for (var args, ignore = {}, i = 0, t = []; i < args.length; ++i) {
660
- ignore[args[i]] = true;
661
- delete tokenMap[args[i]];
662
- }
663
-
664
- /** Run through our tokens list and reassign only those that aren't defined in the hash declared above. */
665
- for (i = 0; i < tokens.length; ++i)
666
- if (!ignore[tokens[i]]) t.push(tokens[i]);
667
-
668
- tokens = t;
669
- length = t.length >>> 0;
670
-
671
- /** Update the targeted attribute of the attached element. */
672
- if (typeof el[prop] === "object") {
673
- el[prop].baseVal = tokens.join(" ");
674
- } else {
675
- el[prop] = tokens.join(" ");
676
- }
677
- reindex();
678
- };
679
-
680
- that.toggle = function (token, force) {
681
- preop.apply(that, [token]);
682
-
683
- /** Token state's being forced. */
684
- if (undefined !== force) {
685
- if (force) {
686
- that.add(token);
687
- return true;
688
- } else {
689
- that.remove(token);
690
- return false;
691
- }
692
- }
693
-
694
- /** Token already exists in tokenList. Remove it, and return FALSE. */
695
- if (tokenMap[token]) {
696
- that.remove(token);
697
- return false;
698
- }
699
-
700
- /** Otherwise, add the token and return TRUE. */
701
- that.add(token);
702
- return true;
703
- };
704
-
705
- return that;
706
- };
707
-
708
- return _DOMTokenList;
709
- }());
710
- }
711
-
712
- // Add second argument to native DOMTokenList.toggle() if necessary
713
- (function () {
714
- var e = document.createElement('span');
715
- if (!('classList' in e)) return;
716
- e.classList.toggle('x', false);
717
- if (!e.classList.contains('x')) return;
718
- e.classList.constructor.prototype.toggle = function toggle(token /*, force*/) {
719
- var force = arguments[1];
720
- if (force === undefined) {
721
- var add = !this.contains(token);
722
- this[add ? 'add' : 'remove'](token);
723
- return add;
724
- }
725
- force = !!force;
726
- this[force ? 'add' : 'remove'](token);
727
- return force;
728
- };
729
- }());
730
-
731
- // Add multiple arguments to native DOMTokenList.add() if necessary
732
- (function () {
733
- var e = document.createElement('span');
734
- if (!('classList' in e)) return;
735
- e.classList.add('a', 'b');
736
- if (e.classList.contains('b')) return;
737
- var native = e.classList.constructor.prototype.add;
738
- e.classList.constructor.prototype.add = function () {
739
- var args = arguments;
740
- var l = arguments.length;
741
- for (var i = 0; i < l; i++) {
742
- native.call(this, args[i]);
743
- }
744
- };
745
- }());
746
-
747
- // Add multiple arguments to native DOMTokenList.remove() if necessary
748
- (function () {
749
- var e = document.createElement('span');
750
- if (!('classList' in e)) return;
751
- e.classList.add('a');
752
- e.classList.add('b');
753
- e.classList.remove('a', 'b');
754
- if (!e.classList.contains('b')) return;
755
- var native = e.classList.constructor.prototype.remove;
756
- e.classList.constructor.prototype.remove = function () {
757
- var args = arguments;
758
- var l = arguments.length;
759
- for (var i = 0; i < l; i++) {
760
- native.call(this, args[i]);
761
- }
762
- };
763
- }());
764
-
765
- }(this));
766
-
767
- }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
768
-
769
- (function(undefined) {
770
-
771
- // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-service/8717a9e04ac7aff99b4980fbedead98036b0929a/packages/polyfill-library/polyfills/Element/prototype/classList/detect.js
772
- var detect = (
773
- 'document' in this && "classList" in document.documentElement && 'Element' in this && 'classList' in Element.prototype && (function () {
774
- var e = document.createElement('span');
775
- e.classList.add('a', 'b');
776
- return e.classList.contains('b');
777
- }())
778
- );
779
-
780
- if (detect) return
781
-
782
- // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Element.prototype.classList&flags=always
783
- (function (global) {
784
- var dpSupport = true;
785
- var defineGetter = function (object, name, fn, configurable) {
786
- if (Object.defineProperty)
787
- Object.defineProperty(object, name, {
788
- configurable: false === dpSupport ? true : !!configurable,
789
- get: fn
790
- });
791
-
792
- else object.__defineGetter__(name, fn);
793
- };
794
- /** Ensure the browser allows Object.defineProperty to be used on native JavaScript objects. */
795
- try {
796
- defineGetter({}, "support");
797
- }
798
- catch (e) {
799
- dpSupport = false;
800
- }
801
- /** Polyfills a property with a DOMTokenList */
802
- var addProp = function (o, name, attr) {
803
-
804
- defineGetter(o.prototype, name, function () {
805
- var tokenList;
806
-
807
- var THIS = this,
808
-
809
- /** Prevent this from firing twice for some reason. What the hell, IE. */
810
- gibberishProperty = "__defineGetter__" + "DEFINE_PROPERTY" + name;
811
- if(THIS[gibberishProperty]) return tokenList;
812
- THIS[gibberishProperty] = true;
813
-
814
- /**
815
- * IE8 can't define properties on native JavaScript objects, so we'll use a dumb hack instead.
816
- *
817
- * What this is doing is creating a dummy element ("reflection") inside a detached phantom node ("mirror")
818
- * that serves as the target of Object.defineProperty instead. While we could simply use the subject HTML
819
- * element instead, this would conflict with element types which use indexed properties (such as forms and
820
- * select lists).
821
- */
822
- if (false === dpSupport) {
823
-
824
- var visage;
825
- var mirror = addProp.mirror || document.createElement("div");
826
- var reflections = mirror.childNodes;
827
- var l = reflections.length;
828
-
829
- for (var i = 0; i < l; ++i)
830
- if (reflections[i]._R === THIS) {
831
- visage = reflections[i];
832
- break;
833
- }
834
-
835
- /** Couldn't find an element's reflection inside the mirror. Materialise one. */
836
- visage || (visage = mirror.appendChild(document.createElement("div")));
837
-
838
- tokenList = DOMTokenList.call(visage, THIS, attr);
839
- } else tokenList = new DOMTokenList(THIS, attr);
840
-
841
- defineGetter(THIS, name, function () {
842
- return tokenList;
843
- });
844
- delete THIS[gibberishProperty];
845
-
846
- return tokenList;
847
- }, true);
848
- };
849
-
850
- addProp(global.Element, "classList", "className");
851
- addProp(global.HTMLElement, "classList", "className");
852
- addProp(global.HTMLLinkElement, "relList", "rel");
853
- addProp(global.HTMLAnchorElement, "relList", "rel");
854
- addProp(global.HTMLAreaElement, "relList", "rel");
855
- }(this));
856
-
857
- }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
858
-
859
- (function(undefined) {
860
- // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Function/prototype/bind/detect.js
861
- var detect = 'bind' in Function.prototype;
862
-
863
- if (detect) return
864
-
865
- // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Function.prototype.bind&flags=always
866
- Object.defineProperty(Function.prototype, 'bind', {
867
- value: function bind(that) { // .length is 1
868
- // add necessary es5-shim utilities
869
- var $Array = Array;
870
- var $Object = Object;
871
- var ObjectPrototype = $Object.prototype;
872
- var ArrayPrototype = $Array.prototype;
873
- var Empty = function Empty() {};
874
- var to_string = ObjectPrototype.toString;
875
- var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';
876
- var isCallable; /* inlined from https://npmjs.com/is-callable */ var fnToStr = Function.prototype.toString, tryFunctionObject = function tryFunctionObject(value) { try { fnToStr.call(value); return true; } catch (e) { return false; } }, fnClass = '[object Function]', genClass = '[object GeneratorFunction]'; isCallable = function isCallable(value) { if (typeof value !== 'function') { return false; } if (hasToStringTag) { return tryFunctionObject(value); } var strClass = to_string.call(value); return strClass === fnClass || strClass === genClass; };
877
- var array_slice = ArrayPrototype.slice;
878
- var array_concat = ArrayPrototype.concat;
879
- var array_push = ArrayPrototype.push;
880
- var max = Math.max;
881
- // /add necessary es5-shim utilities
882
-
883
- // 1. Let Target be the this value.
884
- var target = this;
885
- // 2. If IsCallable(Target) is false, throw a TypeError exception.
886
- if (!isCallable(target)) {
887
- throw new TypeError('Function.prototype.bind called on incompatible ' + target);
888
- }
889
- // 3. Let A be a new (possibly empty) internal list of all of the
890
- // argument values provided after thisArg (arg1, arg2 etc), in order.
891
- // XXX slicedArgs will stand in for "A" if used
892
- var args = array_slice.call(arguments, 1); // for normal call
893
- // 4. Let F be a new native ECMAScript object.
894
- // 11. Set the [[Prototype]] internal property of F to the standard
895
- // built-in Function prototype object as specified in 15.3.3.1.
896
- // 12. Set the [[Call]] internal property of F as described in
897
- // 15.3.4.5.1.
898
- // 13. Set the [[Construct]] internal property of F as described in
899
- // 15.3.4.5.2.
900
- // 14. Set the [[HasInstance]] internal property of F as described in
901
- // 15.3.4.5.3.
902
- var bound;
903
- var binder = function () {
904
-
905
- if (this instanceof bound) {
906
- // 15.3.4.5.2 [[Construct]]
907
- // When the [[Construct]] internal method of a function object,
908
- // F that was created using the bind function is called with a
909
- // list of arguments ExtraArgs, the following steps are taken:
910
- // 1. Let target be the value of F's [[TargetFunction]]
911
- // internal property.
912
- // 2. If target has no [[Construct]] internal method, a
913
- // TypeError exception is thrown.
914
- // 3. Let boundArgs be the value of F's [[BoundArgs]] internal
915
- // property.
916
- // 4. Let args be a new list containing the same values as the
917
- // list boundArgs in the same order followed by the same
918
- // values as the list ExtraArgs in the same order.
919
- // 5. Return the result of calling the [[Construct]] internal
920
- // method of target providing args as the arguments.
921
-
922
- var result = target.apply(
923
- this,
924
- array_concat.call(args, array_slice.call(arguments))
925
- );
926
- if ($Object(result) === result) {
927
- return result;
928
- }
929
- return this;
930
-
931
- } else {
932
- // 15.3.4.5.1 [[Call]]
933
- // When the [[Call]] internal method of a function object, F,
934
- // which was created using the bind function is called with a
935
- // this value and a list of arguments ExtraArgs, the following
936
- // steps are taken:
937
- // 1. Let boundArgs be the value of F's [[BoundArgs]] internal
938
- // property.
939
- // 2. Let boundThis be the value of F's [[BoundThis]] internal
940
- // property.
941
- // 3. Let target be the value of F's [[TargetFunction]] internal
942
- // property.
943
- // 4. Let args be a new list containing the same values as the
944
- // list boundArgs in the same order followed by the same
945
- // values as the list ExtraArgs in the same order.
946
- // 5. Return the result of calling the [[Call]] internal method
947
- // of target providing boundThis as the this value and
948
- // providing args as the arguments.
949
-
950
- // equiv: target.call(this, ...boundArgs, ...args)
951
- return target.apply(
952
- that,
953
- array_concat.call(args, array_slice.call(arguments))
954
- );
955
-
956
- }
957
-
958
- };
959
-
960
- // 15. If the [[Class]] internal property of Target is "Function", then
961
- // a. Let L be the length property of Target minus the length of A.
962
- // b. Set the length own property of F to either 0 or L, whichever is
963
- // larger.
964
- // 16. Else set the length own property of F to 0.
965
-
966
- var boundLength = max(0, target.length - args.length);
967
-
968
- // 17. Set the attributes of the length own property of F to the values
969
- // specified in 15.3.5.1.
970
- var boundArgs = [];
971
- for (var i = 0; i < boundLength; i++) {
972
- array_push.call(boundArgs, '$' + i);
973
- }
974
-
975
- // XXX Build a dynamic function with desired amount of arguments is the only
976
- // way to set the length property of a function.
977
- // In environments where Content Security Policies enabled (Chrome extensions,
978
- // for ex.) all use of eval or Function costructor throws an exception.
979
- // However in all of these environments Function.prototype.bind exists
980
- // and so this code will never be executed.
981
- bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this, arguments); }')(binder);
982
-
983
- if (target.prototype) {
984
- Empty.prototype = target.prototype;
985
- bound.prototype = new Empty();
986
- // Clean up dangling references.
987
- Empty.prototype = null;
988
- }
989
-
990
- // TODO
991
- // 18. Set the [[Extensible]] internal property of F to true.
992
-
993
- // TODO
994
- // 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3).
995
- // 20. Call the [[DefineOwnProperty]] internal method of F with
996
- // arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]:
997
- // thrower, [[Enumerable]]: false, [[Configurable]]: false}, and
998
- // false.
999
- // 21. Call the [[DefineOwnProperty]] internal method of F with
1000
- // arguments "arguments", PropertyDescriptor {[[Get]]: thrower,
1001
- // [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false},
1002
- // and false.
1003
-
1004
- // TODO
1005
- // NOTE Function objects created using Function.prototype.bind do not
1006
- // have a prototype property or the [[Code]], [[FormalParameters]], and
1007
- // [[Scope]] internal properties.
1008
- // XXX can't delete prototype in pure-js.
1009
-
1010
- // 22. Return F.
1011
- return bound;
1012
- }
1013
- });
1014
- })
1015
- .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
1016
-
1017
- /**
1018
- * Header component
1019
- *
1020
- * @class
1021
- * @param {HTMLElement} $module - HTML element to use for header
1022
- */
1023
- function Header ($module) {
1024
- this.$module = $module;
1025
- this.$menuButton = $module && $module.querySelector('.govuk-js-header-toggle');
1026
- this.$menu = this.$menuButton && $module.querySelector(
1027
- '#' + this.$menuButton.getAttribute('aria-controls')
1028
- );
1029
-
1030
- // Save the opened/closed state for the nav in memory so that we can
1031
- // accurately maintain state when the screen is changed from small to
1032
- // big and back to small
1033
- this.menuIsOpen = false;
1034
-
1035
- // A global const for storing a matchMedia instance which we'll use to
1036
- // detect when a screen size change happens. We set this later during the
1037
- // init function and rely on it being null if the feature isn't available
1038
- // to initially apply hidden attributes
1039
- this.mql = null;
1040
- }
1041
-
1042
- /**
1043
- * Initialise header
1044
- *
1045
- * Check for the presence of the header, menu and menu button – if any are
1046
- * missing then there's nothing to do so return early.
1047
- * Feature sniff for and apply a matchMedia for desktop which will
1048
- * trigger a state sync if the browser viewport moves between states. If
1049
- * matchMedia isn't available, hide the menu button and present the "no js"
1050
- * version of the menu to the user.
1051
- */
1052
- Header.prototype.init = function () {
1053
- if (!this.$module || !this.$menuButton || !this.$menu) {
1054
- return
1055
- }
1056
-
1057
- if ('matchMedia' in window) {
1058
- // Set the matchMedia to the govuk-frontend desktop breakpoint
1059
- this.mql = window.matchMedia('(min-width: 48.0625em)');
1060
-
1061
- if ('addEventListener' in this.mql) {
1062
- this.mql.addEventListener('change', this.syncState.bind(this));
1063
- } else {
1064
- // addListener is a deprecated function, however addEventListener
1065
- // isn't supported by IE or Safari. We therefore add this in as
1066
- // a fallback for those browsers
1067
- this.mql.addListener(this.syncState.bind(this));
1068
- }
1069
-
1070
- this.syncState();
1071
- this.$menuButton.addEventListener('click', this.handleMenuButtonClick.bind(this));
1072
- } else {
1073
- this.$menuButton.setAttribute('hidden', '');
1074
- }
1075
- };
1076
-
1077
- /**
1078
- * Sync menu state
1079
- *
1080
- * Uses the global variable menuIsOpen to correctly set the accessible and
1081
- * visual states of the menu and the menu button.
1082
- * Additionally will force the menu to be visible and the menu button to be
1083
- * hidden if the matchMedia is triggered to desktop.
1084
- */
1085
- Header.prototype.syncState = function () {
1086
- if (this.mql.matches) {
1087
- this.$menu.removeAttribute('hidden');
1088
- this.$menuButton.setAttribute('hidden', '');
1089
- } else {
1090
- this.$menuButton.removeAttribute('hidden');
1091
- this.$menuButton.setAttribute('aria-expanded', this.menuIsOpen);
1092
-
1093
- if (this.menuIsOpen) {
1094
- this.$menu.removeAttribute('hidden');
1095
- } else {
1096
- this.$menu.setAttribute('hidden', '');
1097
- }
1098
- }
1099
- };
1100
-
1101
- /**
1102
- * Handle menu button click
1103
- *
1104
- * When the menu button is clicked, change the visibility of the menu and then
1105
- * sync the accessibility state and menu button state
1106
- */
1107
- Header.prototype.handleMenuButtonClick = function () {
1108
- this.menuIsOpen = !this.menuIsOpen;
1109
- this.syncState();
1110
- };
1111
-
1112
- return Header;
791
+ return Header;
1113
792
 
1114
793
  })));
794
+ //# sourceMappingURL=header.js.map