govuk_tech_docs 3.4.0 → 3.5.0

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 +10 -0
  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
@@ -1,1375 +1,1621 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3
- typeof define === 'function' && define.amd ? define('GOVUKFrontend.Tabs', factory) :
4
- (global.GOVUKFrontend = global.GOVUKFrontend || {}, global.GOVUKFrontend.Tabs = factory());
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3
+ typeof define === 'function' && define.amd ? define('GOVUKFrontend.Tabs', factory) :
4
+ (global.GOVUKFrontend = global.GOVUKFrontend || {}, global.GOVUKFrontend.Tabs = factory());
5
5
  }(this, (function () { 'use strict';
6
6
 
7
- (function(undefined) {
8
-
9
- // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Object/defineProperty/detect.js
10
- var detect = (
11
- // In IE8, defineProperty could only act on DOM elements, so full support
12
- // for the feature requires the ability to set a property on an arbitrary object
13
- 'defineProperty' in Object && (function() {
14
- try {
15
- var a = {};
16
- Object.defineProperty(a, 'test', {value:42});
17
- return true;
18
- } catch(e) {
19
- return false
20
- }
21
- }())
22
- );
23
-
24
- if (detect) return
25
-
26
- // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Object.defineProperty&flags=always
27
- (function (nativeDefineProperty) {
28
-
29
- var supportsAccessors = Object.prototype.hasOwnProperty('__defineGetter__');
30
- var ERR_ACCESSORS_NOT_SUPPORTED = 'Getters & setters cannot be defined on this javascript engine';
31
- var ERR_VALUE_ACCESSORS = 'A property cannot both have accessors and be writable or have a value';
32
-
33
- Object.defineProperty = function defineProperty(object, property, descriptor) {
34
-
35
- // Where native support exists, assume it
36
- if (nativeDefineProperty && (object === window || object === document || object === Element.prototype || object instanceof Element)) {
37
- return nativeDefineProperty(object, property, descriptor);
38
- }
39
-
40
- if (object === null || !(object instanceof Object || typeof object === 'object')) {
41
- throw new TypeError('Object.defineProperty called on non-object');
42
- }
43
-
44
- if (!(descriptor instanceof Object)) {
45
- throw new TypeError('Property description must be an object');
46
- }
47
-
48
- var propertyString = String(property);
49
- var hasValueOrWritable = 'value' in descriptor || 'writable' in descriptor;
50
- var getterType = 'get' in descriptor && typeof descriptor.get;
51
- var setterType = 'set' in descriptor && typeof descriptor.set;
52
-
53
- // handle descriptor.get
54
- if (getterType) {
55
- if (getterType !== 'function') {
56
- throw new TypeError('Getter must be a function');
57
- }
58
- if (!supportsAccessors) {
59
- throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
60
- }
61
- if (hasValueOrWritable) {
62
- throw new TypeError(ERR_VALUE_ACCESSORS);
63
- }
64
- Object.__defineGetter__.call(object, propertyString, descriptor.get);
65
- } else {
66
- object[propertyString] = descriptor.value;
67
- }
68
-
69
- // handle descriptor.set
70
- if (setterType) {
71
- if (setterType !== 'function') {
72
- throw new TypeError('Setter must be a function');
73
- }
74
- if (!supportsAccessors) {
75
- throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
76
- }
77
- if (hasValueOrWritable) {
78
- throw new TypeError(ERR_VALUE_ACCESSORS);
79
- }
80
- Object.__defineSetter__.call(object, propertyString, descriptor.set);
81
- }
82
-
83
- // OK to define value unconditionally - if a getter has been specified as well, an error would be thrown above
84
- if ('value' in descriptor) {
85
- object[propertyString] = descriptor.value;
86
- }
87
-
88
- return object;
89
- };
90
- }(Object.defineProperty));
91
- })
92
- .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
93
-
94
- (function(undefined) {
95
- // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Function/prototype/bind/detect.js
96
- var detect = 'bind' in Function.prototype;
97
-
98
- if (detect) return
99
-
100
- // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Function.prototype.bind&flags=always
101
- Object.defineProperty(Function.prototype, 'bind', {
102
- value: function bind(that) { // .length is 1
103
- // add necessary es5-shim utilities
104
- var $Array = Array;
105
- var $Object = Object;
106
- var ObjectPrototype = $Object.prototype;
107
- var ArrayPrototype = $Array.prototype;
108
- var Empty = function Empty() {};
109
- var to_string = ObjectPrototype.toString;
110
- var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';
111
- 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; };
112
- var array_slice = ArrayPrototype.slice;
113
- var array_concat = ArrayPrototype.concat;
114
- var array_push = ArrayPrototype.push;
115
- var max = Math.max;
116
- // /add necessary es5-shim utilities
117
-
118
- // 1. Let Target be the this value.
119
- var target = this;
120
- // 2. If IsCallable(Target) is false, throw a TypeError exception.
121
- if (!isCallable(target)) {
122
- throw new TypeError('Function.prototype.bind called on incompatible ' + target);
123
- }
124
- // 3. Let A be a new (possibly empty) internal list of all of the
125
- // argument values provided after thisArg (arg1, arg2 etc), in order.
126
- // XXX slicedArgs will stand in for "A" if used
127
- var args = array_slice.call(arguments, 1); // for normal call
128
- // 4. Let F be a new native ECMAScript object.
129
- // 11. Set the [[Prototype]] internal property of F to the standard
130
- // built-in Function prototype object as specified in 15.3.3.1.
131
- // 12. Set the [[Call]] internal property of F as described in
132
- // 15.3.4.5.1.
133
- // 13. Set the [[Construct]] internal property of F as described in
134
- // 15.3.4.5.2.
135
- // 14. Set the [[HasInstance]] internal property of F as described in
136
- // 15.3.4.5.3.
137
- var bound;
138
- var binder = function () {
139
-
140
- if (this instanceof bound) {
141
- // 15.3.4.5.2 [[Construct]]
142
- // When the [[Construct]] internal method of a function object,
143
- // F that was created using the bind function is called with a
144
- // list of arguments ExtraArgs, the following steps are taken:
145
- // 1. Let target be the value of F's [[TargetFunction]]
146
- // internal property.
147
- // 2. If target has no [[Construct]] internal method, a
148
- // TypeError exception is thrown.
149
- // 3. Let boundArgs be the value of F's [[BoundArgs]] internal
150
- // property.
151
- // 4. Let args be a new list containing the same values as the
152
- // list boundArgs in the same order followed by the same
153
- // values as the list ExtraArgs in the same order.
154
- // 5. Return the result of calling the [[Construct]] internal
155
- // method of target providing args as the arguments.
156
-
157
- var result = target.apply(
158
- this,
159
- array_concat.call(args, array_slice.call(arguments))
160
- );
161
- if ($Object(result) === result) {
162
- return result;
163
- }
164
- return this;
165
-
166
- } else {
167
- // 15.3.4.5.1 [[Call]]
168
- // When the [[Call]] internal method of a function object, F,
169
- // which was created using the bind function is called with a
170
- // this value and a list of arguments ExtraArgs, the following
171
- // steps are taken:
172
- // 1. Let boundArgs be the value of F's [[BoundArgs]] internal
173
- // property.
174
- // 2. Let boundThis be the value of F's [[BoundThis]] internal
175
- // property.
176
- // 3. Let target be the value of F's [[TargetFunction]] internal
177
- // property.
178
- // 4. Let args be a new list containing the same values as the
179
- // list boundArgs in the same order followed by the same
180
- // values as the list ExtraArgs in the same order.
181
- // 5. Return the result of calling the [[Call]] internal method
182
- // of target providing boundThis as the this value and
183
- // providing args as the arguments.
184
-
185
- // equiv: target.call(this, ...boundArgs, ...args)
186
- return target.apply(
187
- that,
188
- array_concat.call(args, array_slice.call(arguments))
189
- );
190
-
191
- }
192
-
193
- };
7
+ /**
8
+ * Common helpers which do not require polyfill.
9
+ *
10
+ * IMPORTANT: If a helper require a polyfill, please isolate it in its own module
11
+ * so that the polyfill can be properly tree-shaken and does not burden
12
+ * the components that do not need that helper
13
+ *
14
+ * @module common/index
15
+ */
16
+
17
+ /**
18
+ * TODO: Ideally this would be a NodeList.prototype.forEach polyfill
19
+ * This seems to fail in IE8, requires more investigation.
20
+ * See: https://github.com/imagitama/nodelist-foreach-polyfill
21
+ *
22
+ * @deprecated Will be made private in v5.0
23
+ * @template {Node} ElementType
24
+ * @param {NodeListOf<ElementType>} nodes - NodeList from querySelectorAll()
25
+ * @param {nodeListIterator<ElementType>} callback - Callback function to run for each node
26
+ * @returns {void}
27
+ */
28
+ function nodeListForEach (nodes, callback) {
29
+ if (window.NodeList.prototype.forEach) {
30
+ return nodes.forEach(callback)
31
+ }
32
+ for (var i = 0; i < nodes.length; i++) {
33
+ callback.call(window, nodes[i], i, nodes);
34
+ }
35
+ }
194
36
 
195
- // 15. If the [[Class]] internal property of Target is "Function", then
196
- // a. Let L be the length property of Target minus the length of A.
197
- // b. Set the length own property of F to either 0 or L, whichever is
198
- // larger.
199
- // 16. Else set the length own property of F to 0.
200
-
201
- var boundLength = max(0, target.length - args.length);
202
-
203
- // 17. Set the attributes of the length own property of F to the values
204
- // specified in 15.3.5.1.
205
- var boundArgs = [];
206
- for (var i = 0; i < boundLength; i++) {
207
- array_push.call(boundArgs, '$' + i);
208
- }
209
-
210
- // XXX Build a dynamic function with desired amount of arguments is the only
211
- // way to set the length property of a function.
212
- // In environments where Content Security Policies enabled (Chrome extensions,
213
- // for ex.) all use of eval or Function costructor throws an exception.
214
- // However in all of these environments Function.prototype.bind exists
215
- // and so this code will never be executed.
216
- bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this, arguments); }')(binder);
217
-
218
- if (target.prototype) {
219
- Empty.prototype = target.prototype;
220
- bound.prototype = new Empty();
221
- // Clean up dangling references.
222
- Empty.prototype = null;
223
- }
224
-
225
- // TODO
226
- // 18. Set the [[Extensible]] internal property of F to true.
227
-
228
- // TODO
229
- // 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3).
230
- // 20. Call the [[DefineOwnProperty]] internal method of F with
231
- // arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]:
232
- // thrower, [[Enumerable]]: false, [[Configurable]]: false}, and
233
- // false.
234
- // 21. Call the [[DefineOwnProperty]] internal method of F with
235
- // arguments "arguments", PropertyDescriptor {[[Get]]: thrower,
236
- // [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false},
237
- // and false.
238
-
239
- // TODO
240
- // NOTE Function objects created using Function.prototype.bind do not
241
- // have a prototype property or the [[Code]], [[FormalParameters]], and
242
- // [[Scope]] internal properties.
243
- // XXX can't delete prototype in pure-js.
244
-
245
- // 22. Return F.
246
- return bound;
247
- }
248
- });
249
- })
250
- .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
251
-
252
- (function(undefined) {
253
-
254
- // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-service/master/packages/polyfill-library/polyfills/DOMTokenList/detect.js
255
- var detect = (
256
- 'DOMTokenList' in this && (function (x) {
257
- return 'classList' in x ? !x.classList.toggle('x', false) && !x.className : true;
258
- })(document.createElement('x'))
259
- );
37
+ /**
38
+ * @template {Node} ElementType
39
+ * @callback nodeListIterator
40
+ * @param {ElementType} value - The current node being iterated on
41
+ * @param {number} index - The current index in the iteration
42
+ * @param {NodeListOf<ElementType>} nodes - NodeList from querySelectorAll()
43
+ * @returns {void}
44
+ */
45
+
46
+ // @ts-nocheck
47
+ (function (undefined) {
48
+
49
+ // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Object/defineProperty/detect.js
50
+ var detect = (
51
+ // In IE8, defineProperty could only act on DOM elements, so full support
52
+ // for the feature requires the ability to set a property on an arbitrary object
53
+ 'defineProperty' in Object && (function() {
54
+ try {
55
+ var a = {};
56
+ Object.defineProperty(a, 'test', {value:42});
57
+ return true;
58
+ } catch(e) {
59
+ return false
60
+ }
61
+ }())
62
+ );
260
63
 
261
- if (detect) return
64
+ if (detect) return
262
65
 
263
- // Polyfill from https://raw.githubusercontent.com/Financial-Times/polyfill-service/master/packages/polyfill-library/polyfills/DOMTokenList/polyfill.js
264
- (function (global) {
265
- var nativeImpl = "DOMTokenList" in global && global.DOMTokenList;
266
-
267
- if (
268
- !nativeImpl ||
269
- (
270
- !!document.createElementNS &&
271
- !!document.createElementNS('http://www.w3.org/2000/svg', 'svg') &&
272
- !(document.createElementNS("http://www.w3.org/2000/svg", "svg").classList instanceof DOMTokenList)
273
- )
274
- ) {
275
- global.DOMTokenList = (function() { // eslint-disable-line no-unused-vars
276
- var dpSupport = true;
277
- var defineGetter = function (object, name, fn, configurable) {
278
- if (Object.defineProperty)
279
- Object.defineProperty(object, name, {
280
- configurable: false === dpSupport ? true : !!configurable,
281
- get: fn
282
- });
66
+ // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Object.defineProperty&flags=always
67
+ (function (nativeDefineProperty) {
68
+
69
+ var supportsAccessors = Object.prototype.hasOwnProperty('__defineGetter__');
70
+ var ERR_ACCESSORS_NOT_SUPPORTED = 'Getters & setters cannot be defined on this javascript engine';
71
+ var ERR_VALUE_ACCESSORS = 'A property cannot both have accessors and be writable or have a value';
72
+
73
+ Object.defineProperty = function defineProperty(object, property, descriptor) {
74
+
75
+ // Where native support exists, assume it
76
+ if (nativeDefineProperty && (object === window || object === document || object === Element.prototype || object instanceof Element)) {
77
+ return nativeDefineProperty(object, property, descriptor);
78
+ }
79
+
80
+ if (object === null || !(object instanceof Object || typeof object === 'object')) {
81
+ throw new TypeError('Object.defineProperty called on non-object');
82
+ }
83
+
84
+ if (!(descriptor instanceof Object)) {
85
+ throw new TypeError('Property description must be an object');
86
+ }
87
+
88
+ var propertyString = String(property);
89
+ var hasValueOrWritable = 'value' in descriptor || 'writable' in descriptor;
90
+ var getterType = 'get' in descriptor && typeof descriptor.get;
91
+ var setterType = 'set' in descriptor && typeof descriptor.set;
92
+
93
+ // handle descriptor.get
94
+ if (getterType) {
95
+ if (getterType !== 'function') {
96
+ throw new TypeError('Getter must be a function');
97
+ }
98
+ if (!supportsAccessors) {
99
+ throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
100
+ }
101
+ if (hasValueOrWritable) {
102
+ throw new TypeError(ERR_VALUE_ACCESSORS);
103
+ }
104
+ Object.__defineGetter__.call(object, propertyString, descriptor.get);
105
+ } else {
106
+ object[propertyString] = descriptor.value;
107
+ }
108
+
109
+ // handle descriptor.set
110
+ if (setterType) {
111
+ if (setterType !== 'function') {
112
+ throw new TypeError('Setter must be a function');
113
+ }
114
+ if (!supportsAccessors) {
115
+ throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
116
+ }
117
+ if (hasValueOrWritable) {
118
+ throw new TypeError(ERR_VALUE_ACCESSORS);
119
+ }
120
+ Object.__defineSetter__.call(object, propertyString, descriptor.set);
121
+ }
122
+
123
+ // OK to define value unconditionally - if a getter has been specified as well, an error would be thrown above
124
+ if ('value' in descriptor) {
125
+ object[propertyString] = descriptor.value;
126
+ }
127
+
128
+ return object;
129
+ };
130
+ }(Object.defineProperty));
131
+ })
132
+ .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
133
+
134
+ // @ts-nocheck
135
+ (function (undefined) {
136
+
137
+ // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-service/master/packages/polyfill-library/polyfills/DOMTokenList/detect.js
138
+ var detect = (
139
+ 'DOMTokenList' in this && (function (x) {
140
+ return 'classList' in x ? !x.classList.toggle('x', false) && !x.className : true;
141
+ })(document.createElement('x'))
142
+ );
143
+
144
+ if (detect) return
145
+
146
+ // Polyfill from https://raw.githubusercontent.com/Financial-Times/polyfill-service/master/packages/polyfill-library/polyfills/DOMTokenList/polyfill.js
147
+ (function (global) {
148
+ var nativeImpl = "DOMTokenList" in global && global.DOMTokenList;
149
+
150
+ if (
151
+ !nativeImpl ||
152
+ (
153
+ !!document.createElementNS &&
154
+ !!document.createElementNS('http://www.w3.org/2000/svg', 'svg') &&
155
+ !(document.createElementNS("http://www.w3.org/2000/svg", "svg").classList instanceof DOMTokenList)
156
+ )
157
+ ) {
158
+ global.DOMTokenList = (function() { // eslint-disable-line no-unused-vars
159
+ var dpSupport = true;
160
+ var defineGetter = function (object, name, fn, configurable) {
161
+ if (Object.defineProperty)
162
+ Object.defineProperty(object, name, {
163
+ configurable: false === dpSupport ? true : !!configurable,
164
+ get: fn
165
+ });
166
+
167
+ else object.__defineGetter__(name, fn);
168
+ };
283
169
 
284
- else object.__defineGetter__(name, fn);
285
- };
170
+ /** Ensure the browser allows Object.defineProperty to be used on native JavaScript objects. */
171
+ try {
172
+ defineGetter({}, "support");
173
+ }
174
+ catch (e) {
175
+ dpSupport = false;
176
+ }
177
+
178
+
179
+ var _DOMTokenList = function (el, prop) {
180
+ var that = this;
181
+ var tokens = [];
182
+ var tokenMap = {};
183
+ var length = 0;
184
+ var maxLength = 0;
185
+ var addIndexGetter = function (i) {
186
+ defineGetter(that, i, function () {
187
+ preop();
188
+ return tokens[i];
189
+ }, false);
286
190
 
287
- /** Ensure the browser allows Object.defineProperty to be used on native JavaScript objects. */
288
- try {
289
- defineGetter({}, "support");
290
- }
291
- catch (e) {
292
- dpSupport = false;
293
- }
294
-
295
-
296
- var _DOMTokenList = function (el, prop) {
297
- var that = this;
298
- var tokens = [];
299
- var tokenMap = {};
300
- var length = 0;
301
- var maxLength = 0;
302
- var addIndexGetter = function (i) {
303
- defineGetter(that, i, function () {
304
- preop();
305
- return tokens[i];
306
- }, false);
191
+ };
192
+ var reindex = function () {
307
193
 
308
- };
309
- var reindex = function () {
194
+ /** Define getter functions for array-like access to the tokenList's contents. */
195
+ if (length >= maxLength)
196
+ for (; maxLength < length; ++maxLength) {
197
+ addIndexGetter(maxLength);
198
+ }
199
+ };
310
200
 
311
- /** Define getter functions for array-like access to the tokenList's contents. */
312
- if (length >= maxLength)
313
- for (; maxLength < length; ++maxLength) {
314
- addIndexGetter(maxLength);
201
+ /** Helper function called at the start of each class method. Internal use only. */
202
+ var preop = function () {
203
+ var error;
204
+ var i;
205
+ var args = arguments;
206
+ var rSpace = /\s+/;
207
+
208
+ /** Validate the token/s passed to an instance method, if any. */
209
+ if (args.length)
210
+ for (i = 0; i < args.length; ++i)
211
+ if (rSpace.test(args[i])) {
212
+ error = new SyntaxError('String "' + args[i] + '" ' + "contains" + ' an invalid character');
213
+ error.code = 5;
214
+ error.name = "InvalidCharacterError";
215
+ throw error;
216
+ }
217
+
218
+
219
+ /** Split the new value apart by whitespace*/
220
+ if (typeof el[prop] === "object") {
221
+ tokens = ("" + el[prop].baseVal).replace(/^\s+|\s+$/g, "").split(rSpace);
222
+ } else {
223
+ tokens = ("" + el[prop]).replace(/^\s+|\s+$/g, "").split(rSpace);
315
224
  }
316
- };
317
-
318
- /** Helper function called at the start of each class method. Internal use only. */
319
- var preop = function () {
320
- var error;
321
- var i;
322
- var args = arguments;
323
- var rSpace = /\s+/;
324
-
325
- /** Validate the token/s passed to an instance method, if any. */
326
- if (args.length)
327
- for (i = 0; i < args.length; ++i)
328
- if (rSpace.test(args[i])) {
329
- error = new SyntaxError('String "' + args[i] + '" ' + "contains" + ' an invalid character');
330
- error.code = 5;
331
- error.name = "InvalidCharacterError";
332
- throw error;
333
- }
334
225
 
226
+ /** Avoid treating blank strings as single-item token lists */
227
+ if ("" === tokens[0]) tokens = [];
335
228
 
336
- /** Split the new value apart by whitespace*/
337
- if (typeof el[prop] === "object") {
338
- tokens = ("" + el[prop].baseVal).replace(/^\s+|\s+$/g, "").split(rSpace);
339
- } else {
340
- tokens = ("" + el[prop]).replace(/^\s+|\s+$/g, "").split(rSpace);
341
- }
229
+ /** Repopulate the internal token lists */
230
+ tokenMap = {};
231
+ for (i = 0; i < tokens.length; ++i)
232
+ tokenMap[tokens[i]] = true;
233
+ length = tokens.length;
234
+ reindex();
235
+ };
342
236
 
343
- /** Avoid treating blank strings as single-item token lists */
344
- if ("" === tokens[0]) tokens = [];
237
+ /** Populate our internal token list if the targeted attribute of the subject element isn't empty. */
238
+ preop();
345
239
 
346
- /** Repopulate the internal token lists */
347
- tokenMap = {};
348
- for (i = 0; i < tokens.length; ++i)
349
- tokenMap[tokens[i]] = true;
350
- length = tokens.length;
351
- reindex();
352
- };
240
+ /** Return the number of tokens in the underlying string. Read-only. */
241
+ defineGetter(that, "length", function () {
242
+ preop();
243
+ return length;
244
+ });
353
245
 
354
- /** Populate our internal token list if the targeted attribute of the subject element isn't empty. */
355
- preop();
246
+ /** Override the default toString/toLocaleString methods to return a space-delimited list of tokens when typecast. */
247
+ that.toLocaleString =
248
+ that.toString = function () {
249
+ preop();
250
+ return tokens.join(" ");
251
+ };
356
252
 
357
- /** Return the number of tokens in the underlying string. Read-only. */
358
- defineGetter(that, "length", function () {
359
- preop();
360
- return length;
361
- });
253
+ that.item = function (idx) {
254
+ preop();
255
+ return tokens[idx];
256
+ };
362
257
 
363
- /** Override the default toString/toLocaleString methods to return a space-delimited list of tokens when typecast. */
364
- that.toLocaleString =
365
- that.toString = function () {
258
+ that.contains = function (token) {
366
259
  preop();
367
- return tokens.join(" ");
260
+ return !!tokenMap[token];
368
261
  };
369
262
 
370
- that.item = function (idx) {
371
- preop();
372
- return tokens[idx];
373
- };
263
+ that.add = function () {
264
+ preop.apply(that, args = arguments);
374
265
 
375
- that.contains = function (token) {
376
- preop();
377
- return !!tokenMap[token];
378
- };
266
+ for (var args, token, i = 0, l = args.length; i < l; ++i) {
267
+ token = args[i];
268
+ if (!tokenMap[token]) {
269
+ tokens.push(token);
270
+ tokenMap[token] = true;
271
+ }
272
+ }
379
273
 
380
- that.add = function () {
381
- preop.apply(that, args = arguments);
274
+ /** Update the targeted attribute of the attached element if the token list's changed. */
275
+ if (length !== tokens.length) {
276
+ length = tokens.length >>> 0;
277
+ if (typeof el[prop] === "object") {
278
+ el[prop].baseVal = tokens.join(" ");
279
+ } else {
280
+ el[prop] = tokens.join(" ");
281
+ }
282
+ reindex();
283
+ }
284
+ };
382
285
 
383
- for (var args, token, i = 0, l = args.length; i < l; ++i) {
384
- token = args[i];
385
- if (!tokenMap[token]) {
386
- tokens.push(token);
387
- tokenMap[token] = true;
286
+ that.remove = function () {
287
+ preop.apply(that, args = arguments);
288
+
289
+ /** Build a hash of token names to compare against when recollecting our token list. */
290
+ for (var args, ignore = {}, i = 0, t = []; i < args.length; ++i) {
291
+ ignore[args[i]] = true;
292
+ delete tokenMap[args[i]];
388
293
  }
389
- }
390
294
 
391
- /** Update the targeted attribute of the attached element if the token list's changed. */
392
- if (length !== tokens.length) {
393
- length = tokens.length >>> 0;
295
+ /** Run through our tokens list and reassign only those that aren't defined in the hash declared above. */
296
+ for (i = 0; i < tokens.length; ++i)
297
+ if (!ignore[tokens[i]]) t.push(tokens[i]);
298
+
299
+ tokens = t;
300
+ length = t.length >>> 0;
301
+
302
+ /** Update the targeted attribute of the attached element. */
394
303
  if (typeof el[prop] === "object") {
395
304
  el[prop].baseVal = tokens.join(" ");
396
305
  } else {
397
306
  el[prop] = tokens.join(" ");
398
307
  }
399
308
  reindex();
400
- }
401
- };
402
-
403
- that.remove = function () {
404
- preop.apply(that, args = arguments);
405
-
406
- /** Build a hash of token names to compare against when recollecting our token list. */
407
- for (var args, ignore = {}, i = 0, t = []; i < args.length; ++i) {
408
- ignore[args[i]] = true;
409
- delete tokenMap[args[i]];
410
- }
411
-
412
- /** Run through our tokens list and reassign only those that aren't defined in the hash declared above. */
413
- for (i = 0; i < tokens.length; ++i)
414
- if (!ignore[tokens[i]]) t.push(tokens[i]);
415
-
416
- tokens = t;
417
- length = t.length >>> 0;
418
-
419
- /** Update the targeted attribute of the attached element. */
420
- if (typeof el[prop] === "object") {
421
- el[prop].baseVal = tokens.join(" ");
422
- } else {
423
- el[prop] = tokens.join(" ");
424
- }
425
- reindex();
426
- };
309
+ };
427
310
 
428
- that.toggle = function (token, force) {
429
- preop.apply(that, [token]);
311
+ that.toggle = function (token, force) {
312
+ preop.apply(that, [token]);
313
+
314
+ /** Token state's being forced. */
315
+ if (undefined !== force) {
316
+ if (force) {
317
+ that.add(token);
318
+ return true;
319
+ } else {
320
+ that.remove(token);
321
+ return false;
322
+ }
323
+ }
430
324
 
431
- /** Token state's being forced. */
432
- if (undefined !== force) {
433
- if (force) {
434
- that.add(token);
435
- return true;
436
- } else {
325
+ /** Token already exists in tokenList. Remove it, and return FALSE. */
326
+ if (tokenMap[token]) {
437
327
  that.remove(token);
438
328
  return false;
439
329
  }
440
- }
441
330
 
442
- /** Token already exists in tokenList. Remove it, and return FALSE. */
443
- if (tokenMap[token]) {
444
- that.remove(token);
445
- return false;
446
- }
331
+ /** Otherwise, add the token and return TRUE. */
332
+ that.add(token);
333
+ return true;
334
+ };
447
335
 
448
- /** Otherwise, add the token and return TRUE. */
449
- that.add(token);
450
- return true;
336
+ return that;
451
337
  };
452
338
 
453
- return that;
339
+ return _DOMTokenList;
340
+ }());
341
+ }
342
+
343
+ // Add second argument to native DOMTokenList.toggle() if necessary
344
+ (function () {
345
+ var e = document.createElement('span');
346
+ if (!('classList' in e)) return;
347
+ e.classList.toggle('x', false);
348
+ if (!e.classList.contains('x')) return;
349
+ e.classList.constructor.prototype.toggle = function toggle(token /*, force*/) {
350
+ var force = arguments[1];
351
+ if (force === undefined) {
352
+ var add = !this.contains(token);
353
+ this[add ? 'add' : 'remove'](token);
354
+ return add;
355
+ }
356
+ force = !!force;
357
+ this[force ? 'add' : 'remove'](token);
358
+ return force;
454
359
  };
360
+ }());
455
361
 
456
- return _DOMTokenList;
362
+ // Add multiple arguments to native DOMTokenList.add() if necessary
363
+ (function () {
364
+ var e = document.createElement('span');
365
+ if (!('classList' in e)) return;
366
+ e.classList.add('a', 'b');
367
+ if (e.classList.contains('b')) return;
368
+ var native = e.classList.constructor.prototype.add;
369
+ e.classList.constructor.prototype.add = function () {
370
+ var args = arguments;
371
+ var l = arguments.length;
372
+ for (var i = 0; i < l; i++) {
373
+ native.call(this, args[i]);
374
+ }
375
+ };
457
376
  }());
458
- }
459
-
460
- // Add second argument to native DOMTokenList.toggle() if necessary
461
- (function () {
462
- var e = document.createElement('span');
463
- if (!('classList' in e)) return;
464
- e.classList.toggle('x', false);
465
- if (!e.classList.contains('x')) return;
466
- e.classList.constructor.prototype.toggle = function toggle(token /*, force*/) {
467
- var force = arguments[1];
468
- if (force === undefined) {
469
- var add = !this.contains(token);
470
- this[add ? 'add' : 'remove'](token);
471
- return add;
472
- }
473
- force = !!force;
474
- this[force ? 'add' : 'remove'](token);
475
- return force;
476
- };
477
- }());
478
-
479
- // Add multiple arguments to native DOMTokenList.add() if necessary
480
- (function () {
481
- var e = document.createElement('span');
482
- if (!('classList' in e)) return;
483
- e.classList.add('a', 'b');
484
- if (e.classList.contains('b')) return;
485
- var native = e.classList.constructor.prototype.add;
486
- e.classList.constructor.prototype.add = function () {
487
- var args = arguments;
488
- var l = arguments.length;
489
- for (var i = 0; i < l; i++) {
490
- native.call(this, args[i]);
491
- }
492
- };
493
- }());
494
-
495
- // Add multiple arguments to native DOMTokenList.remove() if necessary
496
- (function () {
497
- var e = document.createElement('span');
498
- if (!('classList' in e)) return;
499
- e.classList.add('a');
500
- e.classList.add('b');
501
- e.classList.remove('a', 'b');
502
- if (!e.classList.contains('b')) return;
503
- var native = e.classList.constructor.prototype.remove;
504
- e.classList.constructor.prototype.remove = function () {
505
- var args = arguments;
506
- var l = arguments.length;
507
- for (var i = 0; i < l; i++) {
508
- native.call(this, args[i]);
509
- }
510
- };
511
- }());
512
377
 
513
- }(this));
378
+ // Add multiple arguments to native DOMTokenList.remove() if necessary
379
+ (function () {
380
+ var e = document.createElement('span');
381
+ if (!('classList' in e)) return;
382
+ e.classList.add('a');
383
+ e.classList.add('b');
384
+ e.classList.remove('a', 'b');
385
+ if (!e.classList.contains('b')) return;
386
+ var native = e.classList.constructor.prototype.remove;
387
+ e.classList.constructor.prototype.remove = function () {
388
+ var args = arguments;
389
+ var l = arguments.length;
390
+ for (var i = 0; i < l; i++) {
391
+ native.call(this, args[i]);
392
+ }
393
+ };
394
+ }());
514
395
 
515
- }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
396
+ }(this));
516
397
 
517
- (function(undefined) {
398
+ }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
518
399
 
519
- // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Document/detect.js
520
- var detect = ("Document" in this);
400
+ // @ts-nocheck
401
+ (function (undefined) {
521
402
 
522
- if (detect) return
403
+ // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Document/detect.js
404
+ var detect = ("Document" in this);
523
405
 
524
- // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Document&flags=always
525
- if ((typeof WorkerGlobalScope === "undefined") && (typeof importScripts !== "function")) {
406
+ if (detect) return
526
407
 
527
- if (this.HTMLDocument) { // IE8
408
+ // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Document&flags=always
409
+ if ((typeof WorkerGlobalScope === "undefined") && (typeof importScripts !== "function")) {
528
410
 
529
- // HTMLDocument is an extension of Document. If the browser has HTMLDocument but not Document, the former will suffice as an alias for the latter.
530
- this.Document = this.HTMLDocument;
411
+ if (this.HTMLDocument) { // IE8
531
412
 
532
- } else {
413
+ // HTMLDocument is an extension of Document. If the browser has HTMLDocument but not Document, the former will suffice as an alias for the latter.
414
+ this.Document = this.HTMLDocument;
533
415
 
534
- // 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.
535
- this.Document = this.HTMLDocument = document.constructor = (new Function('return function Document() {}')());
536
- this.Document.prototype = document;
537
- }
538
- }
416
+ } else {
539
417
 
418
+ // 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.
419
+ this.Document = this.HTMLDocument = document.constructor = (new Function('return function Document() {}')());
420
+ this.Document.prototype = document;
421
+ }
422
+ }
540
423
 
541
- })
542
- .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
543
424
 
544
- (function(undefined) {
425
+ })
426
+ .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
545
427
 
546
- // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Element/detect.js
547
- var detect = ('Element' in this && 'HTMLElement' in this);
548
-
549
- if (detect) return
550
-
551
- // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Element&flags=always
552
- (function () {
428
+ // @ts-nocheck
553
429
 
554
- // IE8
555
- if (window.Element && !window.HTMLElement) {
556
- window.HTMLElement = window.Element;
557
- return;
558
- }
430
+ (function(undefined) {
559
431
 
560
- // create Element constructor
561
- window.Element = window.HTMLElement = new Function('return function Element() {}')();
562
-
563
- // generate sandboxed iframe
564
- var vbody = document.appendChild(document.createElement('body'));
565
- var frame = vbody.appendChild(document.createElement('iframe'));
566
-
567
- // use sandboxed iframe to replicate Element functionality
568
- var frameDocument = frame.contentWindow.document;
569
- var prototype = Element.prototype = frameDocument.appendChild(frameDocument.createElement('*'));
570
- var cache = {};
571
-
572
- // polyfill Element.prototype on an element
573
- var shiv = function (element, deep) {
574
- var
575
- childNodes = element.childNodes || [],
576
- index = -1,
577
- key, value, childNode;
578
-
579
- if (element.nodeType === 1 && element.constructor !== Element) {
580
- element.constructor = Element;
581
-
582
- for (key in cache) {
583
- value = cache[key];
584
- element[key] = value;
585
- }
586
- }
587
-
588
- while (childNode = deep && childNodes[++index]) {
589
- shiv(childNode, deep);
590
- }
591
-
592
- return element;
593
- };
594
-
595
- var elements = document.getElementsByTagName('*');
596
- var nativeCreateElement = document.createElement;
597
- var interval;
598
- var loopLimit = 100;
599
-
600
- prototype.attachEvent('onpropertychange', function (event) {
601
- var
602
- propertyName = event.propertyName,
603
- nonValue = !cache.hasOwnProperty(propertyName),
604
- newValue = prototype[propertyName],
605
- oldValue = cache[propertyName],
606
- index = -1,
607
- element;
608
-
609
- while (element = elements[++index]) {
610
- if (element.nodeType === 1) {
611
- if (nonValue || element[propertyName] === oldValue) {
612
- element[propertyName] = newValue;
613
- }
614
- }
615
- }
616
-
617
- cache[propertyName] = newValue;
618
- });
619
-
620
- prototype.constructor = Element;
621
-
622
- if (!prototype.hasAttribute) {
623
- // <Element>.hasAttribute
624
- prototype.hasAttribute = function hasAttribute(name) {
625
- return this.getAttribute(name) !== null;
626
- };
627
- }
628
-
629
- // Apply Element prototype to the pre-existing DOM as soon as the body element appears.
630
- function bodyCheck() {
631
- if (!(loopLimit--)) clearTimeout(interval);
632
- if (document.body && !document.body.prototype && /(complete|interactive)/.test(document.readyState)) {
633
- shiv(document, true);
634
- if (interval && document.body.prototype) clearTimeout(interval);
635
- return (!!document.body.prototype);
636
- }
637
- return false;
638
- }
639
- if (!bodyCheck()) {
640
- document.onreadystatechange = bodyCheck;
641
- interval = setInterval(bodyCheck, 25);
642
- }
643
-
644
- // Apply to any new elements created after load
645
- document.createElement = function createElement(nodeName) {
646
- var element = nativeCreateElement(String(nodeName).toLowerCase());
647
- return shiv(element);
648
- };
649
-
650
- // remove sandboxed iframe
651
- document.removeChild(vbody);
652
- }());
653
-
654
- })
655
- .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
656
-
657
- (function(undefined) {
658
-
659
- // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-service/8717a9e04ac7aff99b4980fbedead98036b0929a/packages/polyfill-library/polyfills/Element/prototype/classList/detect.js
660
- var detect = (
661
- 'document' in this && "classList" in document.documentElement && 'Element' in this && 'classList' in Element.prototype && (function () {
662
- var e = document.createElement('span');
663
- e.classList.add('a', 'b');
664
- return e.classList.contains('b');
665
- }())
666
- );
432
+ // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Element/detect.js
433
+ var detect = ('Element' in this && 'HTMLElement' in this);
667
434
 
668
- if (detect) return
435
+ if (detect) return
436
+
437
+ // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Element&flags=always
438
+ (function () {
439
+
440
+ // IE8
441
+ if (window.Element && !window.HTMLElement) {
442
+ window.HTMLElement = window.Element;
443
+ return;
444
+ }
445
+
446
+ // create Element constructor
447
+ window.Element = window.HTMLElement = new Function('return function Element() {}')();
448
+
449
+ // generate sandboxed iframe
450
+ var vbody = document.appendChild(document.createElement('body'));
451
+ var frame = vbody.appendChild(document.createElement('iframe'));
452
+
453
+ // use sandboxed iframe to replicate Element functionality
454
+ var frameDocument = frame.contentWindow.document;
455
+ var prototype = Element.prototype = frameDocument.appendChild(frameDocument.createElement('*'));
456
+ var cache = {};
457
+
458
+ // polyfill Element.prototype on an element
459
+ var shiv = function (element, deep) {
460
+ var
461
+ childNodes = element.childNodes || [],
462
+ index = -1,
463
+ key, value, childNode;
464
+
465
+ if (element.nodeType === 1 && element.constructor !== Element) {
466
+ element.constructor = Element;
467
+
468
+ for (key in cache) {
469
+ value = cache[key];
470
+ element[key] = value;
471
+ }
472
+ }
473
+
474
+ while (childNode = deep && childNodes[++index]) {
475
+ shiv(childNode, deep);
476
+ }
477
+
478
+ return element;
479
+ };
480
+
481
+ var elements = document.getElementsByTagName('*');
482
+ var nativeCreateElement = document.createElement;
483
+ var interval;
484
+ var loopLimit = 100;
485
+
486
+ prototype.attachEvent('onpropertychange', function (event) {
487
+ var
488
+ propertyName = event.propertyName,
489
+ nonValue = !cache.hasOwnProperty(propertyName),
490
+ newValue = prototype[propertyName],
491
+ oldValue = cache[propertyName],
492
+ index = -1,
493
+ element;
494
+
495
+ while (element = elements[++index]) {
496
+ if (element.nodeType === 1) {
497
+ if (nonValue || element[propertyName] === oldValue) {
498
+ element[propertyName] = newValue;
499
+ }
500
+ }
501
+ }
502
+
503
+ cache[propertyName] = newValue;
504
+ });
505
+
506
+ prototype.constructor = Element;
507
+
508
+ if (!prototype.hasAttribute) {
509
+ // <Element>.hasAttribute
510
+ prototype.hasAttribute = function hasAttribute(name) {
511
+ return this.getAttribute(name) !== null;
512
+ };
513
+ }
514
+
515
+ // Apply Element prototype to the pre-existing DOM as soon as the body element appears.
516
+ function bodyCheck() {
517
+ if (!(loopLimit--)) clearTimeout(interval);
518
+ if (document.body && !document.body.prototype && /(complete|interactive)/.test(document.readyState)) {
519
+ shiv(document, true);
520
+ if (interval && document.body.prototype) clearTimeout(interval);
521
+ return (!!document.body.prototype);
522
+ }
523
+ return false;
524
+ }
525
+ if (!bodyCheck()) {
526
+ document.onreadystatechange = bodyCheck;
527
+ interval = setInterval(bodyCheck, 25);
528
+ }
529
+
530
+ // Apply to any new elements created after load
531
+ document.createElement = function createElement(nodeName) {
532
+ var element = nativeCreateElement(String(nodeName).toLowerCase());
533
+ return shiv(element);
534
+ };
535
+
536
+ // remove sandboxed iframe
537
+ document.removeChild(vbody);
538
+ }());
539
+
540
+ })
541
+ .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
542
+
543
+ // @ts-nocheck
544
+
545
+ (function(undefined) {
546
+
547
+ // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-service/8717a9e04ac7aff99b4980fbedead98036b0929a/packages/polyfill-library/polyfills/Element/prototype/classList/detect.js
548
+ var detect = (
549
+ 'document' in this && "classList" in document.documentElement && 'Element' in this && 'classList' in Element.prototype && (function () {
550
+ var e = document.createElement('span');
551
+ e.classList.add('a', 'b');
552
+ return e.classList.contains('b');
553
+ }())
554
+ );
555
+
556
+ if (detect) return
557
+
558
+ // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Element.prototype.classList&flags=always
559
+ (function (global) {
560
+ var dpSupport = true;
561
+ var defineGetter = function (object, name, fn, configurable) {
562
+ if (Object.defineProperty)
563
+ Object.defineProperty(object, name, {
564
+ configurable: false === dpSupport ? true : !!configurable,
565
+ get: fn
566
+ });
567
+
568
+ else object.__defineGetter__(name, fn);
569
+ };
570
+ /** Ensure the browser allows Object.defineProperty to be used on native JavaScript objects. */
571
+ try {
572
+ defineGetter({}, "support");
573
+ }
574
+ catch (e) {
575
+ dpSupport = false;
576
+ }
577
+ /** Polyfills a property with a DOMTokenList */
578
+ var addProp = function (o, name, attr) {
579
+
580
+ defineGetter(o.prototype, name, function () {
581
+ var tokenList;
582
+
583
+ var THIS = this,
584
+
585
+ /** Prevent this from firing twice for some reason. What the hell, IE. */
586
+ gibberishProperty = "__defineGetter__" + "DEFINE_PROPERTY" + name;
587
+ if(THIS[gibberishProperty]) return tokenList;
588
+ THIS[gibberishProperty] = true;
589
+
590
+ /**
591
+ * IE8 can't define properties on native JavaScript objects, so we'll use a dumb hack instead.
592
+ *
593
+ * What this is doing is creating a dummy element ("reflection") inside a detached phantom node ("mirror")
594
+ * that serves as the target of Object.defineProperty instead. While we could simply use the subject HTML
595
+ * element instead, this would conflict with element types which use indexed properties (such as forms and
596
+ * select lists).
597
+ */
598
+ if (false === dpSupport) {
599
+
600
+ var visage;
601
+ var mirror = addProp.mirror || document.createElement("div");
602
+ var reflections = mirror.childNodes;
603
+ var l = reflections.length;
604
+
605
+ for (var i = 0; i < l; ++i)
606
+ if (reflections[i]._R === THIS) {
607
+ visage = reflections[i];
608
+ break;
609
+ }
610
+
611
+ /** Couldn't find an element's reflection inside the mirror. Materialise one. */
612
+ visage || (visage = mirror.appendChild(document.createElement("div")));
613
+
614
+ tokenList = DOMTokenList.call(visage, THIS, attr);
615
+ } else tokenList = new DOMTokenList(THIS, attr);
616
+
617
+ defineGetter(THIS, name, function () {
618
+ return tokenList;
619
+ });
620
+ delete THIS[gibberishProperty];
669
621
 
670
- // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Element.prototype.classList&flags=always
671
- (function (global) {
672
- var dpSupport = true;
673
- var defineGetter = function (object, name, fn, configurable) {
674
- if (Object.defineProperty)
675
- Object.defineProperty(object, name, {
676
- configurable: false === dpSupport ? true : !!configurable,
677
- get: fn
678
- });
679
-
680
- else object.__defineGetter__(name, fn);
681
- };
682
- /** Ensure the browser allows Object.defineProperty to be used on native JavaScript objects. */
683
- try {
684
- defineGetter({}, "support");
685
- }
686
- catch (e) {
687
- dpSupport = false;
688
- }
689
- /** Polyfills a property with a DOMTokenList */
690
- var addProp = function (o, name, attr) {
691
-
692
- defineGetter(o.prototype, name, function () {
693
- var tokenList;
694
-
695
- var THIS = this,
696
-
697
- /** Prevent this from firing twice for some reason. What the hell, IE. */
698
- gibberishProperty = "__defineGetter__" + "DEFINE_PROPERTY" + name;
699
- if(THIS[gibberishProperty]) return tokenList;
700
- THIS[gibberishProperty] = true;
701
-
702
- /**
703
- * IE8 can't define properties on native JavaScript objects, so we'll use a dumb hack instead.
704
- *
705
- * What this is doing is creating a dummy element ("reflection") inside a detached phantom node ("mirror")
706
- * that serves as the target of Object.defineProperty instead. While we could simply use the subject HTML
707
- * element instead, this would conflict with element types which use indexed properties (such as forms and
708
- * select lists).
709
- */
710
- if (false === dpSupport) {
711
-
712
- var visage;
713
- var mirror = addProp.mirror || document.createElement("div");
714
- var reflections = mirror.childNodes;
715
- var l = reflections.length;
716
-
717
- for (var i = 0; i < l; ++i)
718
- if (reflections[i]._R === THIS) {
719
- visage = reflections[i];
720
- break;
721
- }
722
-
723
- /** Couldn't find an element's reflection inside the mirror. Materialise one. */
724
- visage || (visage = mirror.appendChild(document.createElement("div")));
725
-
726
- tokenList = DOMTokenList.call(visage, THIS, attr);
727
- } else tokenList = new DOMTokenList(THIS, attr);
728
-
729
- defineGetter(THIS, name, function () {
730
622
  return tokenList;
731
- });
732
- delete THIS[gibberishProperty];
623
+ }, true);
624
+ };
733
625
 
734
- return tokenList;
735
- }, true);
736
- };
626
+ addProp(global.Element, "classList", "className");
627
+ addProp(global.HTMLElement, "classList", "className");
628
+ addProp(global.HTMLLinkElement, "relList", "rel");
629
+ addProp(global.HTMLAnchorElement, "relList", "rel");
630
+ addProp(global.HTMLAreaElement, "relList", "rel");
631
+ }(this));
737
632
 
738
- addProp(global.Element, "classList", "className");
739
- addProp(global.HTMLElement, "classList", "className");
740
- addProp(global.HTMLLinkElement, "relList", "rel");
741
- addProp(global.HTMLAnchorElement, "relList", "rel");
742
- addProp(global.HTMLAreaElement, "relList", "rel");
743
- }(this));
633
+ }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
744
634
 
745
- }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
635
+ // @ts-nocheck
746
636
 
747
- (function(undefined) {
637
+ (function(undefined) {
748
638
 
749
- // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-library/master/polyfills/Element/prototype/nextElementSibling/detect.js
750
- var detect = (
751
- 'document' in this && "nextElementSibling" in document.documentElement
752
- );
639
+ // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-library/master/polyfills/Element/prototype/nextElementSibling/detect.js
640
+ var detect = (
641
+ 'document' in this && "nextElementSibling" in document.documentElement
642
+ );
753
643
 
754
- if (detect) return
644
+ if (detect) return
755
645
 
756
- // Polyfill from https://raw.githubusercontent.com/Financial-Times/polyfill-library/master/polyfills/Element/prototype/nextElementSibling/polyfill.js
757
- Object.defineProperty(Element.prototype, "nextElementSibling", {
758
- get: function(){
759
- var el = this.nextSibling;
760
- while (el && el.nodeType !== 1) { el = el.nextSibling; }
761
- return el;
762
- }
763
- });
646
+ // Polyfill from https://raw.githubusercontent.com/Financial-Times/polyfill-library/master/polyfills/Element/prototype/nextElementSibling/polyfill.js
647
+ Object.defineProperty(Element.prototype, "nextElementSibling", {
648
+ get: function(){
649
+ var el = this.nextSibling;
650
+ while (el && el.nodeType !== 1) { el = el.nextSibling; }
651
+ return el;
652
+ }
653
+ });
764
654
 
765
- }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
655
+ }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
766
656
 
767
- (function(undefined) {
657
+ // @ts-nocheck
768
658
 
769
- // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-library/master/polyfills/Element/prototype/previousElementSibling/detect.js
770
- var detect = (
771
- 'document' in this && "previousElementSibling" in document.documentElement
772
- );
659
+ (function(undefined) {
773
660
 
774
- if (detect) return
661
+ // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-library/master/polyfills/Element/prototype/previousElementSibling/detect.js
662
+ var detect = (
663
+ 'document' in this && "previousElementSibling" in document.documentElement
664
+ );
775
665
 
776
- // Polyfill from https://raw.githubusercontent.com/Financial-Times/polyfill-library/master/polyfills/Element/prototype/previousElementSibling/polyfill.js
777
- Object.defineProperty(Element.prototype, 'previousElementSibling', {
778
- get: function(){
779
- var el = this.previousSibling;
780
- while (el && el.nodeType !== 1) { el = el.previousSibling; }
781
- return el;
782
- }
783
- });
666
+ if (detect) return
784
667
 
785
- }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
668
+ // Polyfill from https://raw.githubusercontent.com/Financial-Times/polyfill-library/master/polyfills/Element/prototype/previousElementSibling/polyfill.js
669
+ Object.defineProperty(Element.prototype, 'previousElementSibling', {
670
+ get: function(){
671
+ var el = this.previousSibling;
672
+ while (el && el.nodeType !== 1) { el = el.previousSibling; }
673
+ return el;
674
+ }
675
+ });
786
676
 
787
- (function(undefined) {
677
+ }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
788
678
 
789
- // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Window/detect.js
790
- var detect = ('Window' in this);
679
+ // @ts-nocheck
680
+ (function (undefined) {
791
681
 
792
- if (detect) return
682
+ // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Window/detect.js
683
+ var detect = ('Window' in this);
793
684
 
794
- // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Window&flags=always
795
- if ((typeof WorkerGlobalScope === "undefined") && (typeof importScripts !== "function")) {
796
- (function (global) {
797
- if (global.constructor) {
798
- global.Window = global.constructor;
799
- } else {
800
- (global.Window = global.constructor = new Function('return function Window() {}')()).prototype = this;
801
- }
802
- }(this));
803
- }
685
+ if (detect) return
804
686
 
805
- })
806
- .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
687
+ // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Window&flags=always
688
+ if ((typeof WorkerGlobalScope === "undefined") && (typeof importScripts !== "function")) {
689
+ (function (global) {
690
+ if (global.constructor) {
691
+ global.Window = global.constructor;
692
+ } else {
693
+ (global.Window = global.constructor = new Function('return function Window() {}')()).prototype = this;
694
+ }
695
+ }(this));
696
+ }
807
697
 
808
- (function(undefined) {
698
+ })
699
+ .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
809
700
 
810
- // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Event/detect.js
811
- var detect = (
812
- (function(global) {
701
+ // @ts-nocheck
813
702
 
814
- if (!('Event' in global)) return false;
815
- if (typeof global.Event === 'function') return true;
703
+ (function(undefined) {
816
704
 
817
- try {
705
+ // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Event/detect.js
706
+ var detect = (
707
+ (function(global) {
818
708
 
819
- // In IE 9-11, the Event object exists but cannot be instantiated
820
- new Event('click');
821
- return true;
822
- } catch(e) {
823
- return false;
709
+ if (!('Event' in global)) return false;
710
+ if (typeof global.Event === 'function') return true;
711
+
712
+ try {
713
+
714
+ // In IE 9-11, the Event object exists but cannot be instantiated
715
+ new Event('click');
716
+ return true;
717
+ } catch(e) {
718
+ return false;
719
+ }
720
+ }(this))
721
+ );
722
+
723
+ if (detect) return
724
+
725
+ // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Event&flags=always
726
+ (function () {
727
+ var unlistenableWindowEvents = {
728
+ click: 1,
729
+ dblclick: 1,
730
+ keyup: 1,
731
+ keypress: 1,
732
+ keydown: 1,
733
+ mousedown: 1,
734
+ mouseup: 1,
735
+ mousemove: 1,
736
+ mouseover: 1,
737
+ mouseenter: 1,
738
+ mouseleave: 1,
739
+ mouseout: 1,
740
+ storage: 1,
741
+ storagecommit: 1,
742
+ textinput: 1
743
+ };
744
+
745
+ // This polyfill depends on availability of `document` so will not run in a worker
746
+ // However, we asssume there are no browsers with worker support that lack proper
747
+ // support for `Event` within the worker
748
+ if (typeof document === 'undefined' || typeof window === 'undefined') return;
749
+
750
+ function indexOf(array, element) {
751
+ var
752
+ index = -1,
753
+ length = array.length;
754
+
755
+ while (++index < length) {
756
+ if (index in array && array[index] === element) {
757
+ return index;
758
+ }
759
+ }
760
+
761
+ return -1;
824
762
  }
825
- }(this))
826
- );
827
-
828
- if (detect) return
829
-
830
- // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Event&flags=always
831
- (function () {
832
- var unlistenableWindowEvents = {
833
- click: 1,
834
- dblclick: 1,
835
- keyup: 1,
836
- keypress: 1,
837
- keydown: 1,
838
- mousedown: 1,
839
- mouseup: 1,
840
- mousemove: 1,
841
- mouseover: 1,
842
- mouseenter: 1,
843
- mouseleave: 1,
844
- mouseout: 1,
845
- storage: 1,
846
- storagecommit: 1,
847
- textinput: 1
848
- };
849
-
850
- // This polyfill depends on availability of `document` so will not run in a worker
851
- // However, we asssume there are no browsers with worker support that lack proper
852
- // support for `Event` within the worker
853
- if (typeof document === 'undefined' || typeof window === 'undefined') return;
854
-
855
- function indexOf(array, element) {
856
- var
857
- index = -1,
858
- length = array.length;
859
-
860
- while (++index < length) {
861
- if (index in array && array[index] === element) {
862
- return index;
863
- }
864
- }
865
-
866
- return -1;
867
- }
868
-
869
- var existingProto = (window.Event && window.Event.prototype) || null;
870
- window.Event = Window.prototype.Event = function Event(type, eventInitDict) {
871
- if (!type) {
872
- throw new Error('Not enough arguments');
873
- }
874
-
875
- var event;
876
- // Shortcut if browser supports createEvent
877
- if ('createEvent' in document) {
878
- event = document.createEvent('Event');
879
- var bubbles = eventInitDict && eventInitDict.bubbles !== undefined ? eventInitDict.bubbles : false;
880
- var cancelable = eventInitDict && eventInitDict.cancelable !== undefined ? eventInitDict.cancelable : false;
881
-
882
- event.initEvent(type, bubbles, cancelable);
883
-
884
- return event;
885
- }
886
-
887
- event = document.createEventObject();
888
-
889
- event.type = type;
890
- event.bubbles = eventInitDict && eventInitDict.bubbles !== undefined ? eventInitDict.bubbles : false;
891
- event.cancelable = eventInitDict && eventInitDict.cancelable !== undefined ? eventInitDict.cancelable : false;
892
-
893
- return event;
894
- };
895
- if (existingProto) {
896
- Object.defineProperty(window.Event, 'prototype', {
897
- configurable: false,
898
- enumerable: false,
899
- writable: true,
900
- value: existingProto
901
- });
902
- }
903
-
904
- if (!('createEvent' in document)) {
905
- window.addEventListener = Window.prototype.addEventListener = Document.prototype.addEventListener = Element.prototype.addEventListener = function addEventListener() {
906
- var
907
- element = this,
908
- type = arguments[0],
909
- listener = arguments[1];
910
-
911
- if (element === window && type in unlistenableWindowEvents) {
912
- 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.');
913
- }
914
-
915
- if (!element._events) {
916
- element._events = {};
917
- }
918
-
919
- if (!element._events[type]) {
920
- element._events[type] = function (event) {
921
- var
922
- list = element._events[event.type].list,
923
- events = list.slice(),
924
- index = -1,
925
- length = events.length,
926
- eventElement;
927
-
928
- event.preventDefault = function preventDefault() {
929
- if (event.cancelable !== false) {
930
- event.returnValue = false;
931
- }
932
- };
933
-
934
- event.stopPropagation = function stopPropagation() {
935
- event.cancelBubble = true;
936
- };
937
-
938
- event.stopImmediatePropagation = function stopImmediatePropagation() {
939
- event.cancelBubble = true;
940
- event.cancelImmediate = true;
941
- };
942
-
943
- event.currentTarget = element;
944
- event.relatedTarget = event.fromElement || null;
945
- event.target = event.target || event.srcElement || element;
946
- event.timeStamp = new Date().getTime();
947
-
948
- if (event.clientX) {
949
- event.pageX = event.clientX + document.documentElement.scrollLeft;
950
- event.pageY = event.clientY + document.documentElement.scrollTop;
951
- }
952
-
953
- while (++index < length && !event.cancelImmediate) {
954
- if (index in events) {
955
- eventElement = events[index];
956
-
957
- if (indexOf(list, eventElement) !== -1 && typeof eventElement === 'function') {
958
- eventElement.call(element, event);
959
- }
960
- }
961
- }
962
- };
963
-
964
- element._events[type].list = [];
965
-
966
- if (element.attachEvent) {
967
- element.attachEvent('on' + type, element._events[type]);
968
- }
969
- }
970
-
971
- element._events[type].list.push(listener);
972
- };
973
-
974
- window.removeEventListener = Window.prototype.removeEventListener = Document.prototype.removeEventListener = Element.prototype.removeEventListener = function removeEventListener() {
975
- var
976
- element = this,
977
- type = arguments[0],
978
- listener = arguments[1],
979
- index;
980
-
981
- if (element._events && element._events[type] && element._events[type].list) {
982
- index = indexOf(element._events[type].list, listener);
983
-
984
- if (index !== -1) {
985
- element._events[type].list.splice(index, 1);
986
-
987
- if (!element._events[type].list.length) {
988
- if (element.detachEvent) {
989
- element.detachEvent('on' + type, element._events[type]);
990
- }
991
- delete element._events[type];
992
- }
993
- }
994
- }
995
- };
996
-
997
- window.dispatchEvent = Window.prototype.dispatchEvent = Document.prototype.dispatchEvent = Element.prototype.dispatchEvent = function dispatchEvent(event) {
998
- if (!arguments.length) {
999
- throw new Error('Not enough arguments');
1000
- }
1001
-
1002
- if (!event || typeof event.type !== 'string') {
1003
- throw new Error('DOM Events Exception 0');
1004
- }
1005
-
1006
- var element = this, type = event.type;
1007
-
1008
- try {
1009
- if (!event.bubbles) {
1010
- event.cancelBubble = true;
1011
-
1012
- var cancelBubbleEvent = function (event) {
1013
- event.cancelBubble = true;
1014
-
1015
- (element || window).detachEvent('on' + type, cancelBubbleEvent);
1016
- };
1017
-
1018
- this.attachEvent('on' + type, cancelBubbleEvent);
1019
- }
1020
-
1021
- this.fireEvent('on' + type, event);
1022
- } catch (error) {
1023
- event.target = element;
1024
-
1025
- do {
1026
- event.currentTarget = element;
1027
-
1028
- if ('_events' in element && typeof element._events[type] === 'function') {
1029
- element._events[type].call(element, event);
1030
- }
1031
-
1032
- if (typeof element['on' + type] === 'function') {
1033
- element['on' + type].call(element, event);
1034
- }
1035
-
1036
- element = element.nodeType === 9 ? element.parentWindow : element.parentNode;
1037
- } while (element && !event.cancelBubble);
1038
- }
1039
-
1040
- return true;
1041
- };
1042
-
1043
- // Add the DOMContentLoaded Event
1044
- document.attachEvent('onreadystatechange', function() {
1045
- if (document.readyState === 'complete') {
1046
- document.dispatchEvent(new Event('DOMContentLoaded', {
1047
- bubbles: true
1048
- }));
1049
- }
1050
- });
1051
- }
1052
- }());
1053
-
1054
- })
1055
- .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
1056
-
1057
- /**
1058
- * Common helpers which do not require polyfill.
1059
- *
1060
- * IMPORTANT: If a helper require a polyfill, please isolate it in its own module
1061
- * so that the polyfill can be properly tree-shaken and does not burden
1062
- * the components that do not need that helper
1063
- *
1064
- * @module common/index
1065
- */
1066
-
1067
- /**
1068
- * TODO: Ideally this would be a NodeList.prototype.forEach polyfill
1069
- * This seems to fail in IE8, requires more investigation.
1070
- * See: https://github.com/imagitama/nodelist-foreach-polyfill
1071
- *
1072
- * @param {NodeListOf<Element>} nodes - NodeList from querySelectorAll()
1073
- * @param {nodeListIterator} callback - Callback function to run for each node
1074
- * @returns {undefined}
1075
- */
1076
- function nodeListForEach (nodes, callback) {
1077
- if (window.NodeList.prototype.forEach) {
1078
- return nodes.forEach(callback)
1079
- }
1080
- for (var i = 0; i < nodes.length; i++) {
1081
- callback.call(window, nodes[i], i, nodes);
1082
- }
1083
- }
1084
-
1085
- /**
1086
- * @callback nodeListIterator
1087
- * @param {Element} value - The current node being iterated on
1088
- * @param {number} index - The current index in the iteration
1089
- * @param {NodeListOf<Element>} nodes - NodeList from querySelectorAll()
1090
- * @returns {undefined}
1091
- */
1092
-
1093
- /**
1094
- * Tabs component
1095
- *
1096
- * @class
1097
- * @param {HTMLElement} $module - HTML element to use for tabs
1098
- */
1099
- function Tabs ($module) {
1100
- this.$module = $module;
1101
- this.$tabs = $module.querySelectorAll('.govuk-tabs__tab');
1102
-
1103
- this.keys = { left: 37, right: 39, up: 38, down: 40 };
1104
- this.jsHiddenClass = 'govuk-tabs__panel--hidden';
1105
- }
1106
-
1107
- Tabs.prototype.init = function () {
1108
- if (typeof window.matchMedia === 'function') {
1109
- this.setupResponsiveChecks();
1110
- } else {
1111
- this.setup();
1112
- }
1113
- };
1114
-
1115
- Tabs.prototype.setupResponsiveChecks = function () {
1116
- this.mql = window.matchMedia('(min-width: 40.0625em)');
1117
- this.mql.addListener(this.checkMode.bind(this));
1118
- this.checkMode();
1119
- };
1120
-
1121
- Tabs.prototype.checkMode = function () {
1122
- if (this.mql.matches) {
1123
- this.setup();
1124
- } else {
1125
- this.teardown();
1126
- }
1127
- };
1128
763
 
1129
- Tabs.prototype.setup = function () {
1130
- var $module = this.$module;
1131
- var $tabs = this.$tabs;
1132
- var $tabList = $module.querySelector('.govuk-tabs__list');
1133
- var $tabListItems = $module.querySelectorAll('.govuk-tabs__list-item');
764
+ var existingProto = (window.Event && window.Event.prototype) || null;
765
+ window.Event = Window.prototype.Event = function Event(type, eventInitDict) {
766
+ if (!type) {
767
+ throw new Error('Not enough arguments');
768
+ }
769
+
770
+ var event;
771
+ // Shortcut if browser supports createEvent
772
+ if ('createEvent' in document) {
773
+ event = document.createEvent('Event');
774
+ var bubbles = eventInitDict && eventInitDict.bubbles !== undefined ? eventInitDict.bubbles : false;
775
+ var cancelable = eventInitDict && eventInitDict.cancelable !== undefined ? eventInitDict.cancelable : false;
776
+
777
+ event.initEvent(type, bubbles, cancelable);
778
+
779
+ return event;
780
+ }
781
+
782
+ event = document.createEventObject();
783
+
784
+ event.type = type;
785
+ event.bubbles = eventInitDict && eventInitDict.bubbles !== undefined ? eventInitDict.bubbles : false;
786
+ event.cancelable = eventInitDict && eventInitDict.cancelable !== undefined ? eventInitDict.cancelable : false;
787
+
788
+ return event;
789
+ };
790
+ if (existingProto) {
791
+ Object.defineProperty(window.Event, 'prototype', {
792
+ configurable: false,
793
+ enumerable: false,
794
+ writable: true,
795
+ value: existingProto
796
+ });
797
+ }
1134
798
 
1135
- if (!$tabs || !$tabList || !$tabListItems) {
1136
- return
1137
- }
799
+ if (!('createEvent' in document)) {
800
+ window.addEventListener = Window.prototype.addEventListener = Document.prototype.addEventListener = Element.prototype.addEventListener = function addEventListener() {
801
+ var
802
+ element = this,
803
+ type = arguments[0],
804
+ listener = arguments[1];
805
+
806
+ if (element === window && type in unlistenableWindowEvents) {
807
+ 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.');
808
+ }
809
+
810
+ if (!element._events) {
811
+ element._events = {};
812
+ }
813
+
814
+ if (!element._events[type]) {
815
+ element._events[type] = function (event) {
816
+ var
817
+ list = element._events[event.type].list,
818
+ events = list.slice(),
819
+ index = -1,
820
+ length = events.length,
821
+ eventElement;
822
+
823
+ event.preventDefault = function preventDefault() {
824
+ if (event.cancelable !== false) {
825
+ event.returnValue = false;
826
+ }
827
+ };
828
+
829
+ event.stopPropagation = function stopPropagation() {
830
+ event.cancelBubble = true;
831
+ };
832
+
833
+ event.stopImmediatePropagation = function stopImmediatePropagation() {
834
+ event.cancelBubble = true;
835
+ event.cancelImmediate = true;
836
+ };
837
+
838
+ event.currentTarget = element;
839
+ event.relatedTarget = event.fromElement || null;
840
+ event.target = event.target || event.srcElement || element;
841
+ event.timeStamp = new Date().getTime();
842
+
843
+ if (event.clientX) {
844
+ event.pageX = event.clientX + document.documentElement.scrollLeft;
845
+ event.pageY = event.clientY + document.documentElement.scrollTop;
846
+ }
847
+
848
+ while (++index < length && !event.cancelImmediate) {
849
+ if (index in events) {
850
+ eventElement = events[index];
851
+
852
+ if (indexOf(list, eventElement) !== -1 && typeof eventElement === 'function') {
853
+ eventElement.call(element, event);
854
+ }
855
+ }
856
+ }
857
+ };
858
+
859
+ element._events[type].list = [];
860
+
861
+ if (element.attachEvent) {
862
+ element.attachEvent('on' + type, element._events[type]);
863
+ }
864
+ }
865
+
866
+ element._events[type].list.push(listener);
867
+ };
868
+
869
+ window.removeEventListener = Window.prototype.removeEventListener = Document.prototype.removeEventListener = Element.prototype.removeEventListener = function removeEventListener() {
870
+ var
871
+ element = this,
872
+ type = arguments[0],
873
+ listener = arguments[1],
874
+ index;
875
+
876
+ if (element._events && element._events[type] && element._events[type].list) {
877
+ index = indexOf(element._events[type].list, listener);
878
+
879
+ if (index !== -1) {
880
+ element._events[type].list.splice(index, 1);
881
+
882
+ if (!element._events[type].list.length) {
883
+ if (element.detachEvent) {
884
+ element.detachEvent('on' + type, element._events[type]);
885
+ }
886
+ delete element._events[type];
887
+ }
888
+ }
889
+ }
890
+ };
891
+
892
+ window.dispatchEvent = Window.prototype.dispatchEvent = Document.prototype.dispatchEvent = Element.prototype.dispatchEvent = function dispatchEvent(event) {
893
+ if (!arguments.length) {
894
+ throw new Error('Not enough arguments');
895
+ }
896
+
897
+ if (!event || typeof event.type !== 'string') {
898
+ throw new Error('DOM Events Exception 0');
899
+ }
900
+
901
+ var element = this, type = event.type;
902
+
903
+ try {
904
+ if (!event.bubbles) {
905
+ event.cancelBubble = true;
906
+
907
+ var cancelBubbleEvent = function (event) {
908
+ event.cancelBubble = true;
909
+
910
+ (element || window).detachEvent('on' + type, cancelBubbleEvent);
911
+ };
912
+
913
+ this.attachEvent('on' + type, cancelBubbleEvent);
914
+ }
915
+
916
+ this.fireEvent('on' + type, event);
917
+ } catch (error) {
918
+ event.target = element;
919
+
920
+ do {
921
+ event.currentTarget = element;
922
+
923
+ if ('_events' in element && typeof element._events[type] === 'function') {
924
+ element._events[type].call(element, event);
925
+ }
926
+
927
+ if (typeof element['on' + type] === 'function') {
928
+ element['on' + type].call(element, event);
929
+ }
930
+
931
+ element = element.nodeType === 9 ? element.parentWindow : element.parentNode;
932
+ } while (element && !event.cancelBubble);
933
+ }
934
+
935
+ return true;
936
+ };
937
+
938
+ // Add the DOMContentLoaded Event
939
+ document.attachEvent('onreadystatechange', function() {
940
+ if (document.readyState === 'complete') {
941
+ document.dispatchEvent(new Event('DOMContentLoaded', {
942
+ bubbles: true
943
+ }));
944
+ }
945
+ });
946
+ }
947
+ }());
1138
948
 
1139
- $tabList.setAttribute('role', 'tablist');
949
+ })
950
+ .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
1140
951
 
1141
- nodeListForEach($tabListItems, function ($item) {
1142
- $item.setAttribute('role', 'presentation');
1143
- });
952
+ // @ts-nocheck
1144
953
 
1145
- nodeListForEach($tabs, function ($tab) {
1146
- // Set HTML attributes
1147
- this.setAttributes($tab);
954
+ (function(undefined) {
955
+ // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Function/prototype/bind/detect.js
956
+ var detect = 'bind' in Function.prototype;
1148
957
 
1149
- // Save bounded functions to use when removing event listeners during teardown
1150
- $tab.boundTabClick = this.onTabClick.bind(this);
1151
- $tab.boundTabKeydown = this.onTabKeydown.bind(this);
1152
-
1153
- // Handle events
1154
- $tab.addEventListener('click', $tab.boundTabClick, true);
1155
- $tab.addEventListener('keydown', $tab.boundTabKeydown, true);
1156
-
1157
- // Remove old active panels
1158
- this.hideTab($tab);
1159
- }.bind(this));
1160
-
1161
- // Show either the active tab according to the URL's hash or the first tab
1162
- var $activeTab = this.getTab(window.location.hash) || this.$tabs[0];
1163
- this.showTab($activeTab);
1164
-
1165
- // Handle hashchange events
1166
- $module.boundOnHashChange = this.onHashChange.bind(this);
1167
- window.addEventListener('hashchange', $module.boundOnHashChange, true);
1168
- };
1169
-
1170
- Tabs.prototype.teardown = function () {
1171
- var $module = this.$module;
1172
- var $tabs = this.$tabs;
1173
- var $tabList = $module.querySelector('.govuk-tabs__list');
1174
- var $tabListItems = $module.querySelectorAll('.govuk-tabs__list-item');
1175
-
1176
- if (!$tabs || !$tabList || !$tabListItems) {
1177
- return
1178
- }
958
+ if (detect) return
1179
959
 
1180
- $tabList.removeAttribute('role');
960
+ // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Function.prototype.bind&flags=always
961
+ Object.defineProperty(Function.prototype, 'bind', {
962
+ value: function bind(that) { // .length is 1
963
+ // add necessary es5-shim utilities
964
+ var $Array = Array;
965
+ var $Object = Object;
966
+ var ObjectPrototype = $Object.prototype;
967
+ var ArrayPrototype = $Array.prototype;
968
+ var Empty = function Empty() {};
969
+ var to_string = ObjectPrototype.toString;
970
+ var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';
971
+ 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; };
972
+ var array_slice = ArrayPrototype.slice;
973
+ var array_concat = ArrayPrototype.concat;
974
+ var array_push = ArrayPrototype.push;
975
+ var max = Math.max;
976
+ // /add necessary es5-shim utilities
977
+
978
+ // 1. Let Target be the this value.
979
+ var target = this;
980
+ // 2. If IsCallable(Target) is false, throw a TypeError exception.
981
+ if (!isCallable(target)) {
982
+ throw new TypeError('Function.prototype.bind called on incompatible ' + target);
983
+ }
984
+ // 3. Let A be a new (possibly empty) internal list of all of the
985
+ // argument values provided after thisArg (arg1, arg2 etc), in order.
986
+ // XXX slicedArgs will stand in for "A" if used
987
+ var args = array_slice.call(arguments, 1); // for normal call
988
+ // 4. Let F be a new native ECMAScript object.
989
+ // 11. Set the [[Prototype]] internal property of F to the standard
990
+ // built-in Function prototype object as specified in 15.3.3.1.
991
+ // 12. Set the [[Call]] internal property of F as described in
992
+ // 15.3.4.5.1.
993
+ // 13. Set the [[Construct]] internal property of F as described in
994
+ // 15.3.4.5.2.
995
+ // 14. Set the [[HasInstance]] internal property of F as described in
996
+ // 15.3.4.5.3.
997
+ var bound;
998
+ var binder = function () {
999
+
1000
+ if (this instanceof bound) {
1001
+ // 15.3.4.5.2 [[Construct]]
1002
+ // When the [[Construct]] internal method of a function object,
1003
+ // F that was created using the bind function is called with a
1004
+ // list of arguments ExtraArgs, the following steps are taken:
1005
+ // 1. Let target be the value of F's [[TargetFunction]]
1006
+ // internal property.
1007
+ // 2. If target has no [[Construct]] internal method, a
1008
+ // TypeError exception is thrown.
1009
+ // 3. Let boundArgs be the value of F's [[BoundArgs]] internal
1010
+ // property.
1011
+ // 4. Let args be a new list containing the same values as the
1012
+ // list boundArgs in the same order followed by the same
1013
+ // values as the list ExtraArgs in the same order.
1014
+ // 5. Return the result of calling the [[Construct]] internal
1015
+ // method of target providing args as the arguments.
1016
+
1017
+ var result = target.apply(
1018
+ this,
1019
+ array_concat.call(args, array_slice.call(arguments))
1020
+ );
1021
+ if ($Object(result) === result) {
1022
+ return result;
1023
+ }
1024
+ return this;
1181
1025
 
1182
- nodeListForEach($tabListItems, function ($item) {
1183
- $item.removeAttribute('role', 'presentation');
1184
- });
1026
+ } else {
1027
+ // 15.3.4.5.1 [[Call]]
1028
+ // When the [[Call]] internal method of a function object, F,
1029
+ // which was created using the bind function is called with a
1030
+ // this value and a list of arguments ExtraArgs, the following
1031
+ // steps are taken:
1032
+ // 1. Let boundArgs be the value of F's [[BoundArgs]] internal
1033
+ // property.
1034
+ // 2. Let boundThis be the value of F's [[BoundThis]] internal
1035
+ // property.
1036
+ // 3. Let target be the value of F's [[TargetFunction]] internal
1037
+ // property.
1038
+ // 4. Let args be a new list containing the same values as the
1039
+ // list boundArgs in the same order followed by the same
1040
+ // values as the list ExtraArgs in the same order.
1041
+ // 5. Return the result of calling the [[Call]] internal method
1042
+ // of target providing boundThis as the this value and
1043
+ // providing args as the arguments.
1044
+
1045
+ // equiv: target.call(this, ...boundArgs, ...args)
1046
+ return target.apply(
1047
+ that,
1048
+ array_concat.call(args, array_slice.call(arguments))
1049
+ );
1185
1050
 
1186
- nodeListForEach($tabs, function ($tab) {
1187
- // Remove events
1188
- $tab.removeEventListener('click', $tab.boundTabClick, true);
1189
- $tab.removeEventListener('keydown', $tab.boundTabKeydown, true);
1051
+ }
1190
1052
 
1191
- // Unset HTML attributes
1192
- this.unsetAttributes($tab);
1193
- }.bind(this));
1053
+ };
1054
+
1055
+ // 15. If the [[Class]] internal property of Target is "Function", then
1056
+ // a. Let L be the length property of Target minus the length of A.
1057
+ // b. Set the length own property of F to either 0 or L, whichever is
1058
+ // larger.
1059
+ // 16. Else set the length own property of F to 0.
1060
+
1061
+ var boundLength = max(0, target.length - args.length);
1062
+
1063
+ // 17. Set the attributes of the length own property of F to the values
1064
+ // specified in 15.3.5.1.
1065
+ var boundArgs = [];
1066
+ for (var i = 0; i < boundLength; i++) {
1067
+ array_push.call(boundArgs, '$' + i);
1068
+ }
1069
+
1070
+ // XXX Build a dynamic function with desired amount of arguments is the only
1071
+ // way to set the length property of a function.
1072
+ // In environments where Content Security Policies enabled (Chrome extensions,
1073
+ // for ex.) all use of eval or Function costructor throws an exception.
1074
+ // However in all of these environments Function.prototype.bind exists
1075
+ // and so this code will never be executed.
1076
+ bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this, arguments); }')(binder);
1077
+
1078
+ if (target.prototype) {
1079
+ Empty.prototype = target.prototype;
1080
+ bound.prototype = new Empty();
1081
+ // Clean up dangling references.
1082
+ Empty.prototype = null;
1083
+ }
1084
+
1085
+ // TODO
1086
+ // 18. Set the [[Extensible]] internal property of F to true.
1087
+
1088
+ // TODO
1089
+ // 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3).
1090
+ // 20. Call the [[DefineOwnProperty]] internal method of F with
1091
+ // arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]:
1092
+ // thrower, [[Enumerable]]: false, [[Configurable]]: false}, and
1093
+ // false.
1094
+ // 21. Call the [[DefineOwnProperty]] internal method of F with
1095
+ // arguments "arguments", PropertyDescriptor {[[Get]]: thrower,
1096
+ // [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false},
1097
+ // and false.
1098
+
1099
+ // TODO
1100
+ // NOTE Function objects created using Function.prototype.bind do not
1101
+ // have a prototype property or the [[Code]], [[FormalParameters]], and
1102
+ // [[Scope]] internal properties.
1103
+ // XXX can't delete prototype in pure-js.
1104
+
1105
+ // 22. Return F.
1106
+ return bound;
1107
+ }
1108
+ });
1109
+ })
1110
+ .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
1194
1111
 
1195
- // Remove hashchange event handler
1196
- window.removeEventListener('hashchange', $module.boundOnHashChange, true);
1197
- };
1112
+ /* eslint-disable es-x/no-function-prototype-bind -- Polyfill imported */
1198
1113
 
1199
- Tabs.prototype.onHashChange = function (e) {
1200
- var hash = window.location.hash;
1201
- var $tabWithHash = this.getTab(hash);
1202
- if (!$tabWithHash) {
1203
- return
1204
- }
1114
+ /**
1115
+ * Tabs component
1116
+ *
1117
+ * @class
1118
+ * @param {Element} $module - HTML element to use for tabs
1119
+ */
1120
+ function Tabs ($module) {
1121
+ if (!($module instanceof HTMLElement)) {
1122
+ return this
1123
+ }
1124
+
1125
+ var $tabs = $module.querySelectorAll('a.govuk-tabs__tab');
1126
+ if (!$tabs.length) {
1127
+ return this
1128
+ }
1129
+
1130
+ /** @deprecated Will be made private in v5.0 */
1131
+ this.$module = $module;
1132
+
1133
+ /** @deprecated Will be made private in v5.0 */
1134
+ this.$tabs = $tabs;
1135
+
1136
+ /** @deprecated Will be made private in v5.0 */
1137
+ this.keys = { left: 37, right: 39, up: 38, down: 40 };
1138
+
1139
+ /** @deprecated Will be made private in v5.0 */
1140
+ this.jsHiddenClass = 'govuk-tabs__panel--hidden';
1141
+
1142
+ // Save bounded functions to use when removing event listeners during teardown
1143
+
1144
+ /** @deprecated Will be made private in v5.0 */
1145
+ this.boundTabClick = this.onTabClick.bind(this);
1205
1146
 
1206
- // Prevent changing the hash
1207
- if (this.changingHash) {
1147
+ /** @deprecated Will be made private in v5.0 */
1148
+ this.boundTabKeydown = this.onTabKeydown.bind(this);
1149
+
1150
+ /** @deprecated Will be made private in v5.0 */
1151
+ this.boundOnHashChange = this.onHashChange.bind(this);
1152
+
1153
+ /** @deprecated Will be made private in v5.0 */
1208
1154
  this.changingHash = false;
1209
- return
1210
1155
  }
1211
1156
 
1212
- // Show either the active tab according to the URL's hash or the first tab
1213
- var $previousTab = this.getCurrentTab();
1214
-
1215
- this.hideTab($previousTab);
1216
- this.showTab($tabWithHash);
1217
- $tabWithHash.focus();
1218
- };
1219
-
1220
- Tabs.prototype.hideTab = function ($tab) {
1221
- this.unhighlightTab($tab);
1222
- this.hidePanel($tab);
1223
- };
1224
-
1225
- Tabs.prototype.showTab = function ($tab) {
1226
- this.highlightTab($tab);
1227
- this.showPanel($tab);
1228
- };
1229
-
1230
- Tabs.prototype.getTab = function (hash) {
1231
- return this.$module.querySelector('.govuk-tabs__tab[href="' + hash + '"]')
1232
- };
1233
-
1234
- Tabs.prototype.setAttributes = function ($tab) {
1235
- // set tab attributes
1236
- var panelId = this.getHref($tab).slice(1);
1237
- $tab.setAttribute('id', 'tab_' + panelId);
1238
- $tab.setAttribute('role', 'tab');
1239
- $tab.setAttribute('aria-controls', panelId);
1240
- $tab.setAttribute('aria-selected', 'false');
1241
- $tab.setAttribute('tabindex', '-1');
1242
-
1243
- // set panel attributes
1244
- var $panel = this.getPanel($tab);
1245
- $panel.setAttribute('role', 'tabpanel');
1246
- $panel.setAttribute('aria-labelledby', $tab.id);
1247
- $panel.classList.add(this.jsHiddenClass);
1248
- };
1249
-
1250
- Tabs.prototype.unsetAttributes = function ($tab) {
1251
- // unset tab attributes
1252
- $tab.removeAttribute('id');
1253
- $tab.removeAttribute('role');
1254
- $tab.removeAttribute('aria-controls');
1255
- $tab.removeAttribute('aria-selected');
1256
- $tab.removeAttribute('tabindex');
1257
-
1258
- // unset panel attributes
1259
- var $panel = this.getPanel($tab);
1260
- $panel.removeAttribute('role');
1261
- $panel.removeAttribute('aria-labelledby');
1262
- $panel.classList.remove(this.jsHiddenClass);
1263
- };
1264
-
1265
- Tabs.prototype.onTabClick = function (e) {
1266
- if (!e.target.classList.contains('govuk-tabs__tab')) {
1267
- // Allow events on child DOM elements to bubble up to tab parent
1268
- return false
1269
- }
1270
- e.preventDefault();
1271
- var $newTab = e.target;
1272
- var $currentTab = this.getCurrentTab();
1273
- this.hideTab($currentTab);
1274
- this.showTab($newTab);
1275
- this.createHistoryEntry($newTab);
1276
- };
1277
-
1278
- Tabs.prototype.createHistoryEntry = function ($tab) {
1279
- var $panel = this.getPanel($tab);
1280
-
1281
- // Save and restore the id
1282
- // so the page doesn't jump when a user clicks a tab (which changes the hash)
1283
- var id = $panel.id;
1284
- $panel.id = '';
1285
- this.changingHash = true;
1286
- window.location.hash = this.getHref($tab).slice(1);
1287
- $panel.id = id;
1288
- };
1289
-
1290
- Tabs.prototype.onTabKeydown = function (e) {
1291
- switch (e.keyCode) {
1292
- case this.keys.left:
1293
- case this.keys.up:
1294
- this.activatePreviousTab();
1295
- e.preventDefault();
1296
- break
1297
- case this.keys.right:
1298
- case this.keys.down:
1299
- this.activateNextTab();
1300
- e.preventDefault();
1301
- break
1302
- }
1303
- };
1157
+ /**
1158
+ * Initialise component
1159
+ */
1160
+ Tabs.prototype.init = function () {
1161
+ // Check that required elements are present
1162
+ if (!this.$module || !this.$tabs) {
1163
+ return
1164
+ }
1165
+
1166
+ if (typeof window.matchMedia === 'function') {
1167
+ this.setupResponsiveChecks();
1168
+ } else {
1169
+ this.setup();
1170
+ }
1171
+ };
1172
+
1173
+ /**
1174
+ * Setup viewport resize check
1175
+ *
1176
+ * @deprecated Will be made private in v5.0
1177
+ */
1178
+ Tabs.prototype.setupResponsiveChecks = function () {
1179
+ /** @deprecated Will be made private in v5.0 */
1180
+ this.mql = window.matchMedia('(min-width: 40.0625em)');
1181
+ this.mql.addListener(this.checkMode.bind(this));
1182
+ this.checkMode();
1183
+ };
1184
+
1185
+ /**
1186
+ * Setup or teardown handler for viewport resize check
1187
+ *
1188
+ * @deprecated Will be made private in v5.0
1189
+ */
1190
+ Tabs.prototype.checkMode = function () {
1191
+ if (this.mql.matches) {
1192
+ this.setup();
1193
+ } else {
1194
+ this.teardown();
1195
+ }
1196
+ };
1197
+
1198
+ /**
1199
+ * Setup tab component
1200
+ *
1201
+ * @deprecated Will be made private in v5.0
1202
+ */
1203
+ Tabs.prototype.setup = function () {
1204
+ var $component = this;
1205
+ var $module = this.$module;
1206
+ var $tabs = this.$tabs;
1207
+ var $tabList = $module.querySelector('.govuk-tabs__list');
1208
+ var $tabListItems = $module.querySelectorAll('.govuk-tabs__list-item');
1209
+
1210
+ if (!$tabs || !$tabList || !$tabListItems) {
1211
+ return
1212
+ }
1213
+
1214
+ $tabList.setAttribute('role', 'tablist');
1215
+
1216
+ nodeListForEach($tabListItems, function ($item) {
1217
+ $item.setAttribute('role', 'presentation');
1218
+ });
1304
1219
 
1305
- Tabs.prototype.activateNextTab = function () {
1306
- var currentTab = this.getCurrentTab();
1307
- var nextTabListItem = currentTab.parentNode.nextElementSibling;
1308
- if (nextTabListItem) {
1309
- var nextTab = nextTabListItem.querySelector('.govuk-tabs__tab');
1310
- }
1311
- if (nextTab) {
1312
- this.hideTab(currentTab);
1313
- this.showTab(nextTab);
1314
- nextTab.focus();
1315
- this.createHistoryEntry(nextTab);
1316
- }
1317
- };
1220
+ nodeListForEach($tabs, function ($tab) {
1221
+ // Set HTML attributes
1222
+ $component.setAttributes($tab);
1318
1223
 
1319
- Tabs.prototype.activatePreviousTab = function () {
1320
- var currentTab = this.getCurrentTab();
1321
- var previousTabListItem = currentTab.parentNode.previousElementSibling;
1322
- if (previousTabListItem) {
1323
- var previousTab = previousTabListItem.querySelector('.govuk-tabs__tab');
1324
- }
1325
- if (previousTab) {
1326
- this.hideTab(currentTab);
1327
- this.showTab(previousTab);
1328
- previousTab.focus();
1329
- this.createHistoryEntry(previousTab);
1330
- }
1331
- };
1332
-
1333
- Tabs.prototype.getPanel = function ($tab) {
1334
- var $panel = this.$module.querySelector(this.getHref($tab));
1335
- return $panel
1336
- };
1337
-
1338
- Tabs.prototype.showPanel = function ($tab) {
1339
- var $panel = this.getPanel($tab);
1340
- $panel.classList.remove(this.jsHiddenClass);
1341
- };
1342
-
1343
- Tabs.prototype.hidePanel = function (tab) {
1344
- var $panel = this.getPanel(tab);
1345
- $panel.classList.add(this.jsHiddenClass);
1346
- };
1347
-
1348
- Tabs.prototype.unhighlightTab = function ($tab) {
1349
- $tab.setAttribute('aria-selected', 'false');
1350
- $tab.parentNode.classList.remove('govuk-tabs__list-item--selected');
1351
- $tab.setAttribute('tabindex', '-1');
1352
- };
1353
-
1354
- Tabs.prototype.highlightTab = function ($tab) {
1355
- $tab.setAttribute('aria-selected', 'true');
1356
- $tab.parentNode.classList.add('govuk-tabs__list-item--selected');
1357
- $tab.setAttribute('tabindex', '0');
1358
- };
1359
-
1360
- Tabs.prototype.getCurrentTab = function () {
1361
- return this.$module.querySelector('.govuk-tabs__list-item--selected .govuk-tabs__tab')
1362
- };
1363
-
1364
- // this is because IE doesn't always return the actual value but a relative full path
1365
- // should be a utility function most prob
1366
- // http://labs.thesedays.com/blog/2010/01/08/getting-the-href-value-with-jquery-in-ie/
1367
- Tabs.prototype.getHref = function ($tab) {
1368
- var href = $tab.getAttribute('href');
1369
- var hash = href.slice(href.indexOf('#'), href.length);
1370
- return hash
1371
- };
1372
-
1373
- return Tabs;
1224
+ // Handle events
1225
+ $tab.addEventListener('click', $component.boundTabClick, true);
1226
+ $tab.addEventListener('keydown', $component.boundTabKeydown, true);
1227
+
1228
+ // Remove old active panels
1229
+ $component.hideTab($tab);
1230
+ });
1231
+
1232
+ // Show either the active tab according to the URL's hash or the first tab
1233
+ var $activeTab = this.getTab(window.location.hash) || this.$tabs[0];
1234
+ if (!$activeTab) {
1235
+ return
1236
+ }
1237
+
1238
+ this.showTab($activeTab);
1239
+
1240
+ // Handle hashchange events
1241
+ window.addEventListener('hashchange', this.boundOnHashChange, true);
1242
+ };
1243
+
1244
+ /**
1245
+ * Teardown tab component
1246
+ *
1247
+ * @deprecated Will be made private in v5.0
1248
+ */
1249
+ Tabs.prototype.teardown = function () {
1250
+ var $component = this;
1251
+ var $module = this.$module;
1252
+ var $tabs = this.$tabs;
1253
+ var $tabList = $module.querySelector('.govuk-tabs__list');
1254
+ var $tabListItems = $module.querySelectorAll('a.govuk-tabs__list-item');
1255
+
1256
+ if (!$tabs || !$tabList || !$tabListItems) {
1257
+ return
1258
+ }
1259
+
1260
+ $tabList.removeAttribute('role');
1261
+
1262
+ nodeListForEach($tabListItems, function ($item) {
1263
+ $item.removeAttribute('role');
1264
+ });
1265
+
1266
+ nodeListForEach($tabs, function ($tab) {
1267
+ // Remove events
1268
+ $tab.removeEventListener('click', $component.boundTabClick, true);
1269
+ $tab.removeEventListener('keydown', $component.boundTabKeydown, true);
1270
+
1271
+ // Unset HTML attributes
1272
+ $component.unsetAttributes($tab);
1273
+ });
1274
+
1275
+ // Remove hashchange event handler
1276
+ window.removeEventListener('hashchange', this.boundOnHashChange, true);
1277
+ };
1278
+
1279
+ /**
1280
+ * Handle hashchange event
1281
+ *
1282
+ * @deprecated Will be made private in v5.0
1283
+ * @returns {void | undefined} Returns void, or undefined when prevented
1284
+ */
1285
+ Tabs.prototype.onHashChange = function () {
1286
+ var hash = window.location.hash;
1287
+ var $tabWithHash = this.getTab(hash);
1288
+ if (!$tabWithHash) {
1289
+ return
1290
+ }
1291
+
1292
+ // Prevent changing the hash
1293
+ if (this.changingHash) {
1294
+ this.changingHash = false;
1295
+ return
1296
+ }
1297
+
1298
+ // Show either the active tab according to the URL's hash or the first tab
1299
+ var $previousTab = this.getCurrentTab();
1300
+ if (!$previousTab) {
1301
+ return
1302
+ }
1303
+
1304
+ this.hideTab($previousTab);
1305
+ this.showTab($tabWithHash);
1306
+ $tabWithHash.focus();
1307
+ };
1308
+
1309
+ /**
1310
+ * Hide panel for tab link
1311
+ *
1312
+ * @deprecated Will be made private in v5.0
1313
+ * @param {HTMLAnchorElement} $tab - Tab link
1314
+ */
1315
+ Tabs.prototype.hideTab = function ($tab) {
1316
+ this.unhighlightTab($tab);
1317
+ this.hidePanel($tab);
1318
+ };
1319
+
1320
+ /**
1321
+ * Show panel for tab link
1322
+ *
1323
+ * @deprecated Will be made private in v5.0
1324
+ * @param {HTMLAnchorElement} $tab - Tab link
1325
+ */
1326
+ Tabs.prototype.showTab = function ($tab) {
1327
+ this.highlightTab($tab);
1328
+ this.showPanel($tab);
1329
+ };
1330
+
1331
+ /**
1332
+ * Get tab link by hash
1333
+ *
1334
+ * @deprecated Will be made private in v5.0
1335
+ * @param {string} hash - Hash fragment including #
1336
+ * @returns {HTMLAnchorElement | null} Tab link
1337
+ */
1338
+ Tabs.prototype.getTab = function (hash) {
1339
+ // @ts-expect-error `HTMLAnchorElement` type expected
1340
+ return this.$module.querySelector('a.govuk-tabs__tab[href="' + hash + '"]')
1341
+ };
1342
+
1343
+ /**
1344
+ * Set tab link and panel attributes
1345
+ *
1346
+ * @deprecated Will be made private in v5.0
1347
+ * @param {HTMLAnchorElement} $tab - Tab link
1348
+ */
1349
+ Tabs.prototype.setAttributes = function ($tab) {
1350
+ // set tab attributes
1351
+ var panelId = this.getHref($tab).slice(1);
1352
+ $tab.setAttribute('id', 'tab_' + panelId);
1353
+ $tab.setAttribute('role', 'tab');
1354
+ $tab.setAttribute('aria-controls', panelId);
1355
+ $tab.setAttribute('aria-selected', 'false');
1356
+ $tab.setAttribute('tabindex', '-1');
1357
+
1358
+ // set panel attributes
1359
+ var $panel = this.getPanel($tab);
1360
+ if (!$panel) {
1361
+ return
1362
+ }
1363
+
1364
+ $panel.setAttribute('role', 'tabpanel');
1365
+ $panel.setAttribute('aria-labelledby', $tab.id);
1366
+ $panel.classList.add(this.jsHiddenClass);
1367
+ };
1368
+
1369
+ /**
1370
+ * Unset tab link and panel attributes
1371
+ *
1372
+ * @deprecated Will be made private in v5.0
1373
+ * @param {HTMLAnchorElement} $tab - Tab link
1374
+ */
1375
+ Tabs.prototype.unsetAttributes = function ($tab) {
1376
+ // unset tab attributes
1377
+ $tab.removeAttribute('id');
1378
+ $tab.removeAttribute('role');
1379
+ $tab.removeAttribute('aria-controls');
1380
+ $tab.removeAttribute('aria-selected');
1381
+ $tab.removeAttribute('tabindex');
1382
+
1383
+ // unset panel attributes
1384
+ var $panel = this.getPanel($tab);
1385
+ if (!$panel) {
1386
+ return
1387
+ }
1388
+
1389
+ $panel.removeAttribute('role');
1390
+ $panel.removeAttribute('aria-labelledby');
1391
+ $panel.classList.remove(this.jsHiddenClass);
1392
+ };
1393
+
1394
+ /**
1395
+ * Handle tab link clicks
1396
+ *
1397
+ * @deprecated Will be made private in v5.0
1398
+ * @param {MouseEvent} event - Mouse click event
1399
+ * @returns {void} Returns void
1400
+ */
1401
+ Tabs.prototype.onTabClick = function (event) {
1402
+ var $currentTab = this.getCurrentTab();
1403
+ var $nextTab = event.currentTarget;
1404
+
1405
+ if (!$currentTab || !($nextTab instanceof HTMLAnchorElement)) {
1406
+ return
1407
+ }
1408
+
1409
+ event.preventDefault();
1410
+
1411
+ this.hideTab($currentTab);
1412
+ this.showTab($nextTab);
1413
+ this.createHistoryEntry($nextTab);
1414
+ };
1415
+
1416
+ /**
1417
+ * Update browser URL hash fragment for tab
1418
+ *
1419
+ * - Allows back/forward to navigate tabs
1420
+ * - Avoids page jump when hash changes
1421
+ *
1422
+ * @deprecated Will be made private in v5.0
1423
+ * @param {HTMLAnchorElement} $tab - Tab link
1424
+ */
1425
+ Tabs.prototype.createHistoryEntry = function ($tab) {
1426
+ var $panel = this.getPanel($tab);
1427
+ if (!$panel) {
1428
+ return
1429
+ }
1430
+
1431
+ // Save and restore the id
1432
+ // so the page doesn't jump when a user clicks a tab (which changes the hash)
1433
+ var panelId = $panel.id;
1434
+ $panel.id = '';
1435
+ this.changingHash = true;
1436
+ window.location.hash = this.getHref($tab).slice(1);
1437
+ $panel.id = panelId;
1438
+ };
1439
+
1440
+ /**
1441
+ * Handle tab keydown event
1442
+ *
1443
+ * - Press right/down arrow for next tab
1444
+ * - Press left/up arrow for previous tab
1445
+ *
1446
+ * @deprecated Will be made private in v5.0
1447
+ * @param {KeyboardEvent} event - Keydown event
1448
+ */
1449
+ Tabs.prototype.onTabKeydown = function (event) {
1450
+ switch (event.keyCode) {
1451
+ case this.keys.left:
1452
+ case this.keys.up:
1453
+ this.activatePreviousTab();
1454
+ event.preventDefault();
1455
+ break
1456
+ case this.keys.right:
1457
+ case this.keys.down:
1458
+ this.activateNextTab();
1459
+ event.preventDefault();
1460
+ break
1461
+ }
1462
+ };
1463
+
1464
+ /**
1465
+ * Activate next tab
1466
+ *
1467
+ * @deprecated Will be made private in v5.0
1468
+ */
1469
+ Tabs.prototype.activateNextTab = function () {
1470
+ var $currentTab = this.getCurrentTab();
1471
+ if (!$currentTab || !$currentTab.parentElement) {
1472
+ return
1473
+ }
1474
+
1475
+ var $nextTabListItem = $currentTab.parentElement.nextElementSibling;
1476
+ if (!$nextTabListItem) {
1477
+ return
1478
+ }
1479
+
1480
+ var $nextTab = $nextTabListItem.querySelector('a.govuk-tabs__tab');
1481
+ if (!$nextTab) {
1482
+ return
1483
+ }
1484
+
1485
+ this.hideTab($currentTab);
1486
+ this.showTab($nextTab);
1487
+ $nextTab.focus();
1488
+ this.createHistoryEntry($nextTab);
1489
+ };
1490
+
1491
+ /**
1492
+ * Activate previous tab
1493
+ *
1494
+ * @deprecated Will be made private in v5.0
1495
+ */
1496
+ Tabs.prototype.activatePreviousTab = function () {
1497
+ var $currentTab = this.getCurrentTab();
1498
+ if (!$currentTab || !$currentTab.parentElement) {
1499
+ return
1500
+ }
1501
+
1502
+ var $previousTabListItem = $currentTab.parentElement.previousElementSibling;
1503
+ if (!$previousTabListItem) {
1504
+ return
1505
+ }
1506
+
1507
+ var $previousTab = $previousTabListItem.querySelector('a.govuk-tabs__tab');
1508
+ if (!$previousTab) {
1509
+ return
1510
+ }
1511
+
1512
+ this.hideTab($currentTab);
1513
+ this.showTab($previousTab);
1514
+ $previousTab.focus();
1515
+ this.createHistoryEntry($previousTab);
1516
+ };
1517
+
1518
+ /**
1519
+ * Get tab panel for tab link
1520
+ *
1521
+ * @deprecated Will be made private in v5.0
1522
+ * @param {HTMLAnchorElement} $tab - Tab link
1523
+ * @returns {Element | null} Tab panel
1524
+ */
1525
+ Tabs.prototype.getPanel = function ($tab) {
1526
+ return this.$module.querySelector(this.getHref($tab))
1527
+ };
1528
+
1529
+ /**
1530
+ * Show tab panel for tab link
1531
+ *
1532
+ * @deprecated Will be made private in v5.0
1533
+ * @param {HTMLAnchorElement} $tab - Tab link
1534
+ */
1535
+ Tabs.prototype.showPanel = function ($tab) {
1536
+ var $panel = this.getPanel($tab);
1537
+ if (!$panel) {
1538
+ return
1539
+ }
1540
+
1541
+ $panel.classList.remove(this.jsHiddenClass);
1542
+ };
1543
+
1544
+ /**
1545
+ * Hide tab panel for tab link
1546
+ *
1547
+ * @deprecated Will be made private in v5.0
1548
+ * @param {HTMLAnchorElement} $tab - Tab link
1549
+ */
1550
+ Tabs.prototype.hidePanel = function ($tab) {
1551
+ var $panel = this.getPanel($tab);
1552
+ if (!$panel) {
1553
+ return
1554
+ }
1555
+
1556
+ $panel.classList.add(this.jsHiddenClass);
1557
+ };
1558
+
1559
+ /**
1560
+ * Unset 'selected' state for tab link
1561
+ *
1562
+ * @deprecated Will be made private in v5.0
1563
+ * @param {HTMLAnchorElement} $tab - Tab link
1564
+ */
1565
+ Tabs.prototype.unhighlightTab = function ($tab) {
1566
+ if (!$tab.parentElement) {
1567
+ return
1568
+ }
1569
+
1570
+ $tab.setAttribute('aria-selected', 'false');
1571
+ $tab.parentElement.classList.remove('govuk-tabs__list-item--selected');
1572
+ $tab.setAttribute('tabindex', '-1');
1573
+ };
1574
+
1575
+ /**
1576
+ * Set 'selected' state for tab link
1577
+ *
1578
+ * @deprecated Will be made private in v5.0
1579
+ * @param {HTMLAnchorElement} $tab - Tab link
1580
+ */
1581
+ Tabs.prototype.highlightTab = function ($tab) {
1582
+ if (!$tab.parentElement) {
1583
+ return
1584
+ }
1585
+
1586
+ $tab.setAttribute('aria-selected', 'true');
1587
+ $tab.parentElement.classList.add('govuk-tabs__list-item--selected');
1588
+ $tab.setAttribute('tabindex', '0');
1589
+ };
1590
+
1591
+ /**
1592
+ * Get current tab link
1593
+ *
1594
+ * @deprecated Will be made private in v5.0
1595
+ * @returns {HTMLAnchorElement | null} Tab link
1596
+ */
1597
+ Tabs.prototype.getCurrentTab = function () {
1598
+ return this.$module.querySelector('.govuk-tabs__list-item--selected a.govuk-tabs__tab')
1599
+ };
1600
+
1601
+ /**
1602
+ * Get link hash fragment for href attribute
1603
+ *
1604
+ * this is because IE doesn't always return the actual value but a relative full path
1605
+ * should be a utility function most prob
1606
+ * {@link http://labs.thesedays.com/blog/2010/01/08/getting-the-href-value-with-jquery-in-ie/}
1607
+ *
1608
+ * @deprecated Will be made private in v5.0
1609
+ * @param {HTMLAnchorElement} $tab - Tab link
1610
+ * @returns {string} Hash fragment including #
1611
+ */
1612
+ Tabs.prototype.getHref = function ($tab) {
1613
+ var href = $tab.getAttribute('href');
1614
+ var hash = href.slice(href.indexOf('#'), href.length);
1615
+ return hash
1616
+ };
1617
+
1618
+ return Tabs;
1374
1619
 
1375
1620
  })));
1621
+ //# sourceMappingURL=tabs.js.map