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,846 +1,873 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3
- typeof define === 'function' && define.amd ? define('GOVUKFrontend.Details', factory) :
4
- (global.GOVUKFrontend = global.GOVUKFrontend || {}, global.GOVUKFrontend.Details = factory());
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3
+ typeof define === 'function' && define.amd ? define('GOVUKFrontend.Details', factory) :
4
+ (global.GOVUKFrontend = global.GOVUKFrontend || {}, global.GOVUKFrontend.Details = 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;
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
+ * Used to generate a unique string, allows multiple instances of the component
19
+ * without them conflicting with each other.
20
+ * https://stackoverflow.com/a/8809472
21
+ *
22
+ * @deprecated Will be made private in v5.0
23
+ * @returns {string} Unique ID
24
+ */
25
+ function generateUniqueID () {
26
+ var d = new Date().getTime();
27
+ if (typeof window.performance !== 'undefined' && typeof window.performance.now === 'function') {
28
+ d += window.performance.now(); // use high-precision timer if available
29
+ }
30
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
31
+ var r = (d + Math.random() * 16) % 16 | 0;
32
+ d = Math.floor(d / 16);
33
+ return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16)
34
+ })
35
+ }
36
+
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/Window/detect.js
50
+ var detect = ('Window' in this);
97
51
 
98
52
  if (detect) return
99
53
 
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
- };
194
-
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
- }
54
+ // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Window&flags=always
55
+ if ((typeof WorkerGlobalScope === "undefined") && (typeof importScripts !== "function")) {
56
+ (function (global) {
57
+ if (global.constructor) {
58
+ global.Window = global.constructor;
59
+ } else {
60
+ (global.Window = global.constructor = new Function('return function Window() {}')()).prototype = this;
61
+ }
62
+ }(this));
63
+ }
209
64
 
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
- }
65
+ })
66
+ .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
224
67
 
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 || {});
68
+ // @ts-nocheck
69
+ (function (undefined) {
251
70
 
252
- (function(undefined) {
71
+ // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Document/detect.js
72
+ var detect = ("Document" in this);
253
73
 
254
- // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Window/detect.js
255
- var detect = ('Window' in this);
74
+ if (detect) return
256
75
 
257
- if (detect) return
76
+ // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Document&flags=always
77
+ if ((typeof WorkerGlobalScope === "undefined") && (typeof importScripts !== "function")) {
258
78
 
259
- // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Window&flags=always
260
- if ((typeof WorkerGlobalScope === "undefined") && (typeof importScripts !== "function")) {
261
- (function (global) {
262
- if (global.constructor) {
263
- global.Window = global.constructor;
264
- } else {
265
- (global.Window = global.constructor = new Function('return function Window() {}')()).prototype = this;
266
- }
267
- }(this));
268
- }
79
+ if (this.HTMLDocument) { // IE8
269
80
 
270
- })
271
- .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
81
+ // HTMLDocument is an extension of Document. If the browser has HTMLDocument but not Document, the former will suffice as an alias for the latter.
82
+ this.Document = this.HTMLDocument;
272
83
 
273
- (function(undefined) {
84
+ } else {
274
85
 
275
- // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Document/detect.js
276
- var detect = ("Document" in this);
86
+ // 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.
87
+ this.Document = this.HTMLDocument = document.constructor = (new Function('return function Document() {}')());
88
+ this.Document.prototype = document;
89
+ }
90
+ }
277
91
 
278
- if (detect) return
279
92
 
280
- // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Document&flags=always
281
- if ((typeof WorkerGlobalScope === "undefined") && (typeof importScripts !== "function")) {
93
+ })
94
+ .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
282
95
 
283
- if (this.HTMLDocument) { // IE8
96
+ // @ts-nocheck
284
97
 
285
- // HTMLDocument is an extension of Document. If the browser has HTMLDocument but not Document, the former will suffice as an alias for the latter.
286
- this.Document = this.HTMLDocument;
98
+ (function(undefined) {
287
99
 
288
- } else {
100
+ // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Element/detect.js
101
+ var detect = ('Element' in this && 'HTMLElement' in this);
289
102
 
290
- // 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.
291
- this.Document = this.HTMLDocument = document.constructor = (new Function('return function Document() {}')());
292
- this.Document.prototype = document;
293
- }
294
- }
295
-
296
-
297
- })
298
- .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
299
-
300
- (function(undefined) {
301
-
302
- // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Element/detect.js
303
- var detect = ('Element' in this && 'HTMLElement' in this);
304
-
305
- if (detect) return
306
-
307
- // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Element&flags=always
308
- (function () {
309
-
310
- // IE8
311
- if (window.Element && !window.HTMLElement) {
312
- window.HTMLElement = window.Element;
313
- return;
314
- }
315
-
316
- // create Element constructor
317
- window.Element = window.HTMLElement = new Function('return function Element() {}')();
318
-
319
- // generate sandboxed iframe
320
- var vbody = document.appendChild(document.createElement('body'));
321
- var frame = vbody.appendChild(document.createElement('iframe'));
322
-
323
- // use sandboxed iframe to replicate Element functionality
324
- var frameDocument = frame.contentWindow.document;
325
- var prototype = Element.prototype = frameDocument.appendChild(frameDocument.createElement('*'));
326
- var cache = {};
327
-
328
- // polyfill Element.prototype on an element
329
- var shiv = function (element, deep) {
330
- var
331
- childNodes = element.childNodes || [],
332
- index = -1,
333
- key, value, childNode;
334
-
335
- if (element.nodeType === 1 && element.constructor !== Element) {
336
- element.constructor = Element;
337
-
338
- for (key in cache) {
339
- value = cache[key];
340
- element[key] = value;
341
- }
342
- }
343
-
344
- while (childNode = deep && childNodes[++index]) {
345
- shiv(childNode, deep);
346
- }
347
-
348
- return element;
349
- };
350
-
351
- var elements = document.getElementsByTagName('*');
352
- var nativeCreateElement = document.createElement;
353
- var interval;
354
- var loopLimit = 100;
355
-
356
- prototype.attachEvent('onpropertychange', function (event) {
357
- var
358
- propertyName = event.propertyName,
359
- nonValue = !cache.hasOwnProperty(propertyName),
360
- newValue = prototype[propertyName],
361
- oldValue = cache[propertyName],
362
- index = -1,
363
- element;
364
-
365
- while (element = elements[++index]) {
366
- if (element.nodeType === 1) {
367
- if (nonValue || element[propertyName] === oldValue) {
368
- element[propertyName] = newValue;
369
- }
370
- }
371
- }
372
-
373
- cache[propertyName] = newValue;
374
- });
375
-
376
- prototype.constructor = Element;
377
-
378
- if (!prototype.hasAttribute) {
379
- // <Element>.hasAttribute
380
- prototype.hasAttribute = function hasAttribute(name) {
381
- return this.getAttribute(name) !== null;
382
- };
383
- }
384
-
385
- // Apply Element prototype to the pre-existing DOM as soon as the body element appears.
386
- function bodyCheck() {
387
- if (!(loopLimit--)) clearTimeout(interval);
388
- if (document.body && !document.body.prototype && /(complete|interactive)/.test(document.readyState)) {
389
- shiv(document, true);
390
- if (interval && document.body.prototype) clearTimeout(interval);
391
- return (!!document.body.prototype);
392
- }
393
- return false;
394
- }
395
- if (!bodyCheck()) {
396
- document.onreadystatechange = bodyCheck;
397
- interval = setInterval(bodyCheck, 25);
398
- }
399
-
400
- // Apply to any new elements created after load
401
- document.createElement = function createElement(nodeName) {
402
- var element = nativeCreateElement(String(nodeName).toLowerCase());
403
- return shiv(element);
404
- };
405
-
406
- // remove sandboxed iframe
407
- document.removeChild(vbody);
408
- }());
409
-
410
- })
411
- .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
412
-
413
- (function(undefined) {
414
-
415
- // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Event/detect.js
416
- var detect = (
417
- (function(global) {
418
-
419
- if (!('Event' in global)) return false;
420
- if (typeof global.Event === 'function') return true;
421
-
422
- try {
423
-
424
- // In IE 9-11, the Event object exists but cannot be instantiated
425
- new Event('click');
426
- return true;
427
- } catch(e) {
103
+ if (detect) return
104
+
105
+ // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Element&flags=always
106
+ (function () {
107
+
108
+ // IE8
109
+ if (window.Element && !window.HTMLElement) {
110
+ window.HTMLElement = window.Element;
111
+ return;
112
+ }
113
+
114
+ // create Element constructor
115
+ window.Element = window.HTMLElement = new Function('return function Element() {}')();
116
+
117
+ // generate sandboxed iframe
118
+ var vbody = document.appendChild(document.createElement('body'));
119
+ var frame = vbody.appendChild(document.createElement('iframe'));
120
+
121
+ // use sandboxed iframe to replicate Element functionality
122
+ var frameDocument = frame.contentWindow.document;
123
+ var prototype = Element.prototype = frameDocument.appendChild(frameDocument.createElement('*'));
124
+ var cache = {};
125
+
126
+ // polyfill Element.prototype on an element
127
+ var shiv = function (element, deep) {
128
+ var
129
+ childNodes = element.childNodes || [],
130
+ index = -1,
131
+ key, value, childNode;
132
+
133
+ if (element.nodeType === 1 && element.constructor !== Element) {
134
+ element.constructor = Element;
135
+
136
+ for (key in cache) {
137
+ value = cache[key];
138
+ element[key] = value;
139
+ }
140
+ }
141
+
142
+ while (childNode = deep && childNodes[++index]) {
143
+ shiv(childNode, deep);
144
+ }
145
+
146
+ return element;
147
+ };
148
+
149
+ var elements = document.getElementsByTagName('*');
150
+ var nativeCreateElement = document.createElement;
151
+ var interval;
152
+ var loopLimit = 100;
153
+
154
+ prototype.attachEvent('onpropertychange', function (event) {
155
+ var
156
+ propertyName = event.propertyName,
157
+ nonValue = !cache.hasOwnProperty(propertyName),
158
+ newValue = prototype[propertyName],
159
+ oldValue = cache[propertyName],
160
+ index = -1,
161
+ element;
162
+
163
+ while (element = elements[++index]) {
164
+ if (element.nodeType === 1) {
165
+ if (nonValue || element[propertyName] === oldValue) {
166
+ element[propertyName] = newValue;
167
+ }
168
+ }
169
+ }
170
+
171
+ cache[propertyName] = newValue;
172
+ });
173
+
174
+ prototype.constructor = Element;
175
+
176
+ if (!prototype.hasAttribute) {
177
+ // <Element>.hasAttribute
178
+ prototype.hasAttribute = function hasAttribute(name) {
179
+ return this.getAttribute(name) !== null;
180
+ };
181
+ }
182
+
183
+ // Apply Element prototype to the pre-existing DOM as soon as the body element appears.
184
+ function bodyCheck() {
185
+ if (!(loopLimit--)) clearTimeout(interval);
186
+ if (document.body && !document.body.prototype && /(complete|interactive)/.test(document.readyState)) {
187
+ shiv(document, true);
188
+ if (interval && document.body.prototype) clearTimeout(interval);
189
+ return (!!document.body.prototype);
190
+ }
428
191
  return false;
429
192
  }
430
- }(this))
431
- );
432
-
433
- if (detect) return
434
-
435
- // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Event&flags=always
436
- (function () {
437
- var unlistenableWindowEvents = {
438
- click: 1,
439
- dblclick: 1,
440
- keyup: 1,
441
- keypress: 1,
442
- keydown: 1,
443
- mousedown: 1,
444
- mouseup: 1,
445
- mousemove: 1,
446
- mouseover: 1,
447
- mouseenter: 1,
448
- mouseleave: 1,
449
- mouseout: 1,
450
- storage: 1,
451
- storagecommit: 1,
452
- textinput: 1
453
- };
454
-
455
- // This polyfill depends on availability of `document` so will not run in a worker
456
- // However, we asssume there are no browsers with worker support that lack proper
457
- // support for `Event` within the worker
458
- if (typeof document === 'undefined' || typeof window === 'undefined') return;
459
-
460
- function indexOf(array, element) {
461
- var
462
- index = -1,
463
- length = array.length;
464
-
465
- while (++index < length) {
466
- if (index in array && array[index] === element) {
467
- return index;
468
- }
469
- }
470
-
471
- return -1;
472
- }
473
-
474
- var existingProto = (window.Event && window.Event.prototype) || null;
475
- window.Event = Window.prototype.Event = function Event(type, eventInitDict) {
476
- if (!type) {
477
- throw new Error('Not enough arguments');
478
- }
479
-
480
- var event;
481
- // Shortcut if browser supports createEvent
482
- if ('createEvent' in document) {
483
- event = document.createEvent('Event');
484
- var bubbles = eventInitDict && eventInitDict.bubbles !== undefined ? eventInitDict.bubbles : false;
485
- var cancelable = eventInitDict && eventInitDict.cancelable !== undefined ? eventInitDict.cancelable : false;
486
-
487
- event.initEvent(type, bubbles, cancelable);
488
-
489
- return event;
490
- }
491
-
492
- event = document.createEventObject();
493
-
494
- event.type = type;
495
- event.bubbles = eventInitDict && eventInitDict.bubbles !== undefined ? eventInitDict.bubbles : false;
496
- event.cancelable = eventInitDict && eventInitDict.cancelable !== undefined ? eventInitDict.cancelable : false;
497
-
498
- return event;
499
- };
500
- if (existingProto) {
501
- Object.defineProperty(window.Event, 'prototype', {
502
- configurable: false,
503
- enumerable: false,
504
- writable: true,
505
- value: existingProto
506
- });
507
- }
508
-
509
- if (!('createEvent' in document)) {
510
- window.addEventListener = Window.prototype.addEventListener = Document.prototype.addEventListener = Element.prototype.addEventListener = function addEventListener() {
511
- var
512
- element = this,
513
- type = arguments[0],
514
- listener = arguments[1];
515
-
516
- if (element === window && type in unlistenableWindowEvents) {
517
- 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.');
518
- }
519
-
520
- if (!element._events) {
521
- element._events = {};
522
- }
523
-
524
- if (!element._events[type]) {
525
- element._events[type] = function (event) {
526
- var
527
- list = element._events[event.type].list,
528
- events = list.slice(),
529
- index = -1,
530
- length = events.length,
531
- eventElement;
532
-
533
- event.preventDefault = function preventDefault() {
534
- if (event.cancelable !== false) {
535
- event.returnValue = false;
536
- }
537
- };
538
-
539
- event.stopPropagation = function stopPropagation() {
540
- event.cancelBubble = true;
541
- };
542
-
543
- event.stopImmediatePropagation = function stopImmediatePropagation() {
544
- event.cancelBubble = true;
545
- event.cancelImmediate = true;
546
- };
547
-
548
- event.currentTarget = element;
549
- event.relatedTarget = event.fromElement || null;
550
- event.target = event.target || event.srcElement || element;
551
- event.timeStamp = new Date().getTime();
552
-
553
- if (event.clientX) {
554
- event.pageX = event.clientX + document.documentElement.scrollLeft;
555
- event.pageY = event.clientY + document.documentElement.scrollTop;
556
- }
557
-
558
- while (++index < length && !event.cancelImmediate) {
559
- if (index in events) {
560
- eventElement = events[index];
561
-
562
- if (indexOf(list, eventElement) !== -1 && typeof eventElement === 'function') {
563
- eventElement.call(element, event);
564
- }
565
- }
566
- }
567
- };
568
-
569
- element._events[type].list = [];
570
-
571
- if (element.attachEvent) {
572
- element.attachEvent('on' + type, element._events[type]);
573
- }
574
- }
575
-
576
- element._events[type].list.push(listener);
577
- };
578
-
579
- window.removeEventListener = Window.prototype.removeEventListener = Document.prototype.removeEventListener = Element.prototype.removeEventListener = function removeEventListener() {
580
- var
581
- element = this,
582
- type = arguments[0],
583
- listener = arguments[1],
584
- index;
585
-
586
- if (element._events && element._events[type] && element._events[type].list) {
587
- index = indexOf(element._events[type].list, listener);
588
-
589
- if (index !== -1) {
590
- element._events[type].list.splice(index, 1);
591
-
592
- if (!element._events[type].list.length) {
593
- if (element.detachEvent) {
594
- element.detachEvent('on' + type, element._events[type]);
595
- }
596
- delete element._events[type];
597
- }
598
- }
599
- }
600
- };
601
-
602
- window.dispatchEvent = Window.prototype.dispatchEvent = Document.prototype.dispatchEvent = Element.prototype.dispatchEvent = function dispatchEvent(event) {
603
- if (!arguments.length) {
604
- throw new Error('Not enough arguments');
605
- }
606
-
607
- if (!event || typeof event.type !== 'string') {
608
- throw new Error('DOM Events Exception 0');
609
- }
610
-
611
- var element = this, type = event.type;
612
-
613
- try {
614
- if (!event.bubbles) {
615
- event.cancelBubble = true;
616
-
617
- var cancelBubbleEvent = function (event) {
618
- event.cancelBubble = true;
619
-
620
- (element || window).detachEvent('on' + type, cancelBubbleEvent);
621
- };
622
-
623
- this.attachEvent('on' + type, cancelBubbleEvent);
624
- }
625
-
626
- this.fireEvent('on' + type, event);
627
- } catch (error) {
628
- event.target = element;
629
-
630
- do {
631
- event.currentTarget = element;
632
-
633
- if ('_events' in element && typeof element._events[type] === 'function') {
634
- element._events[type].call(element, event);
635
- }
636
-
637
- if (typeof element['on' + type] === 'function') {
638
- element['on' + type].call(element, event);
639
- }
640
-
641
- element = element.nodeType === 9 ? element.parentWindow : element.parentNode;
642
- } while (element && !event.cancelBubble);
643
- }
644
-
645
- return true;
646
- };
647
-
648
- // Add the DOMContentLoaded Event
649
- document.attachEvent('onreadystatechange', function() {
650
- if (document.readyState === 'complete') {
651
- document.dispatchEvent(new Event('DOMContentLoaded', {
652
- bubbles: true
653
- }));
654
- }
655
- });
656
- }
657
- }());
658
-
659
- })
660
- .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
661
-
662
- /**
663
- * Common helpers which do not require polyfill.
664
- *
665
- * IMPORTANT: If a helper require a polyfill, please isolate it in its own module
666
- * so that the polyfill can be properly tree-shaken and does not burden
667
- * the components that do not need that helper
668
- *
669
- * @module common/index
670
- */
671
-
672
- /**
673
- * Used to generate a unique string, allows multiple instances of the component
674
- * without them conflicting with each other.
675
- * https://stackoverflow.com/a/8809472
676
- *
677
- * @returns {string} Unique ID
678
- */
679
- function generateUniqueID () {
680
- var d = new Date().getTime();
681
- if (typeof window.performance !== 'undefined' && typeof window.performance.now === 'function') {
682
- d += window.performance.now(); // use high-precision timer if available
683
- }
684
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
685
- var r = (d + Math.random() * 16) % 16 | 0;
686
- d = Math.floor(d / 16);
687
- return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16)
193
+ if (!bodyCheck()) {
194
+ document.onreadystatechange = bodyCheck;
195
+ interval = setInterval(bodyCheck, 25);
196
+ }
197
+
198
+ // Apply to any new elements created after load
199
+ document.createElement = function createElement(nodeName) {
200
+ var element = nativeCreateElement(String(nodeName).toLowerCase());
201
+ return shiv(element);
202
+ };
203
+
204
+ // remove sandboxed iframe
205
+ document.removeChild(vbody);
206
+ }());
207
+
688
208
  })
689
- }
690
-
691
- /**
692
- * @callback nodeListIterator
693
- * @param {Element} value - The current node being iterated on
694
- * @param {number} index - The current index in the iteration
695
- * @param {NodeListOf<Element>} nodes - NodeList from querySelectorAll()
696
- * @returns {undefined}
697
- */
698
-
699
- /**
700
- * JavaScript 'polyfill' for HTML5's <details> and <summary> elements
701
- * and 'shim' to add accessiblity enhancements for all browsers
702
- *
703
- * http://caniuse.com/#feat=details
704
- */
705
-
706
- var KEY_ENTER = 13;
707
- var KEY_SPACE = 32;
708
-
709
- /**
710
- * Details component
711
- *
712
- * @class
713
- * @param {HTMLElement} $module - HTML element to use for details
714
- */
715
- function Details ($module) {
716
- this.$module = $module;
717
- }
718
-
719
- Details.prototype.init = function () {
720
- if (!this.$module) {
721
- return
722
- }
209
+ .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
210
+
211
+ // @ts-nocheck
212
+ (function (undefined) {
213
+
214
+ // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Object/defineProperty/detect.js
215
+ var detect = (
216
+ // In IE8, defineProperty could only act on DOM elements, so full support
217
+ // for the feature requires the ability to set a property on an arbitrary object
218
+ 'defineProperty' in Object && (function() {
219
+ try {
220
+ var a = {};
221
+ Object.defineProperty(a, 'test', {value:42});
222
+ return true;
223
+ } catch(e) {
224
+ return false
225
+ }
226
+ }())
227
+ );
723
228
 
724
- // If there is native details support, we want to avoid running code to polyfill native behaviour.
725
- var hasNativeDetails = typeof this.$module.open === 'boolean';
229
+ if (detect) return
726
230
 
727
- if (hasNativeDetails) {
728
- return
729
- }
231
+ // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Object.defineProperty&flags=always
232
+ (function (nativeDefineProperty) {
233
+
234
+ var supportsAccessors = Object.prototype.hasOwnProperty('__defineGetter__');
235
+ var ERR_ACCESSORS_NOT_SUPPORTED = 'Getters & setters cannot be defined on this javascript engine';
236
+ var ERR_VALUE_ACCESSORS = 'A property cannot both have accessors and be writable or have a value';
237
+
238
+ Object.defineProperty = function defineProperty(object, property, descriptor) {
239
+
240
+ // Where native support exists, assume it
241
+ if (nativeDefineProperty && (object === window || object === document || object === Element.prototype || object instanceof Element)) {
242
+ return nativeDefineProperty(object, property, descriptor);
243
+ }
244
+
245
+ if (object === null || !(object instanceof Object || typeof object === 'object')) {
246
+ throw new TypeError('Object.defineProperty called on non-object');
247
+ }
248
+
249
+ if (!(descriptor instanceof Object)) {
250
+ throw new TypeError('Property description must be an object');
251
+ }
252
+
253
+ var propertyString = String(property);
254
+ var hasValueOrWritable = 'value' in descriptor || 'writable' in descriptor;
255
+ var getterType = 'get' in descriptor && typeof descriptor.get;
256
+ var setterType = 'set' in descriptor && typeof descriptor.set;
257
+
258
+ // handle descriptor.get
259
+ if (getterType) {
260
+ if (getterType !== 'function') {
261
+ throw new TypeError('Getter must be a function');
262
+ }
263
+ if (!supportsAccessors) {
264
+ throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
265
+ }
266
+ if (hasValueOrWritable) {
267
+ throw new TypeError(ERR_VALUE_ACCESSORS);
268
+ }
269
+ Object.__defineGetter__.call(object, propertyString, descriptor.get);
270
+ } else {
271
+ object[propertyString] = descriptor.value;
272
+ }
273
+
274
+ // handle descriptor.set
275
+ if (setterType) {
276
+ if (setterType !== 'function') {
277
+ throw new TypeError('Setter must be a function');
278
+ }
279
+ if (!supportsAccessors) {
280
+ throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
281
+ }
282
+ if (hasValueOrWritable) {
283
+ throw new TypeError(ERR_VALUE_ACCESSORS);
284
+ }
285
+ Object.__defineSetter__.call(object, propertyString, descriptor.set);
286
+ }
287
+
288
+ // OK to define value unconditionally - if a getter has been specified as well, an error would be thrown above
289
+ if ('value' in descriptor) {
290
+ object[propertyString] = descriptor.value;
291
+ }
292
+
293
+ return object;
294
+ };
295
+ }(Object.defineProperty));
296
+ })
297
+ .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
730
298
 
731
- this.polyfillDetails();
732
- };
299
+ // @ts-nocheck
733
300
 
734
- Details.prototype.polyfillDetails = function () {
735
- var $module = this.$module;
301
+ (function(undefined) {
736
302
 
737
- // Save shortcuts to the inner summary and content elements
738
- var $summary = this.$summary = $module.getElementsByTagName('summary').item(0);
739
- var $content = this.$content = $module.getElementsByTagName('div').item(0);
303
+ // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Event/detect.js
304
+ var detect = (
305
+ (function(global) {
740
306
 
741
- // If <details> doesn't have a <summary> and a <div> representing the content
742
- // it means the required HTML structure is not met so the script will stop
743
- if (!$summary || !$content) {
744
- return
745
- }
307
+ if (!('Event' in global)) return false;
308
+ if (typeof global.Event === 'function') return true;
746
309
 
747
- // If the content doesn't have an ID, assign it one now
748
- // which we'll need for the summary's aria-controls assignment
749
- if (!$content.id) {
750
- $content.id = 'details-content-' + generateUniqueID();
751
- }
310
+ try {
752
311
 
753
- // Add ARIA role="group" to details
754
- $module.setAttribute('role', 'group');
312
+ // In IE 9-11, the Event object exists but cannot be instantiated
313
+ new Event('click');
314
+ return true;
315
+ } catch(e) {
316
+ return false;
317
+ }
318
+ }(this))
319
+ );
755
320
 
756
- // Add role=button to summary
757
- $summary.setAttribute('role', 'button');
321
+ if (detect) return
758
322
 
759
- // Add aria-controls
760
- $summary.setAttribute('aria-controls', $content.id);
323
+ // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Event&flags=always
324
+ (function () {
325
+ var unlistenableWindowEvents = {
326
+ click: 1,
327
+ dblclick: 1,
328
+ keyup: 1,
329
+ keypress: 1,
330
+ keydown: 1,
331
+ mousedown: 1,
332
+ mouseup: 1,
333
+ mousemove: 1,
334
+ mouseover: 1,
335
+ mouseenter: 1,
336
+ mouseleave: 1,
337
+ mouseout: 1,
338
+ storage: 1,
339
+ storagecommit: 1,
340
+ textinput: 1
341
+ };
342
+
343
+ // This polyfill depends on availability of `document` so will not run in a worker
344
+ // However, we asssume there are no browsers with worker support that lack proper
345
+ // support for `Event` within the worker
346
+ if (typeof document === 'undefined' || typeof window === 'undefined') return;
347
+
348
+ function indexOf(array, element) {
349
+ var
350
+ index = -1,
351
+ length = array.length;
352
+
353
+ while (++index < length) {
354
+ if (index in array && array[index] === element) {
355
+ return index;
356
+ }
357
+ }
358
+
359
+ return -1;
360
+ }
761
361
 
762
- // Set tabIndex so the summary is keyboard accessible for non-native elements
763
- //
764
- // We have to use the camelcase `tabIndex` property as there is a bug in IE6/IE7 when we set the correct attribute lowercase:
765
- // See http://web.archive.org/web/20170120194036/http://www.saliences.com/browserBugs/tabIndex.html for more information.
766
- $summary.tabIndex = 0;
362
+ var existingProto = (window.Event && window.Event.prototype) || null;
363
+ window.Event = Window.prototype.Event = function Event(type, eventInitDict) {
364
+ if (!type) {
365
+ throw new Error('Not enough arguments');
366
+ }
367
+
368
+ var event;
369
+ // Shortcut if browser supports createEvent
370
+ if ('createEvent' in document) {
371
+ event = document.createEvent('Event');
372
+ var bubbles = eventInitDict && eventInitDict.bubbles !== undefined ? eventInitDict.bubbles : false;
373
+ var cancelable = eventInitDict && eventInitDict.cancelable !== undefined ? eventInitDict.cancelable : false;
374
+
375
+ event.initEvent(type, bubbles, cancelable);
376
+
377
+ return event;
378
+ }
379
+
380
+ event = document.createEventObject();
381
+
382
+ event.type = type;
383
+ event.bubbles = eventInitDict && eventInitDict.bubbles !== undefined ? eventInitDict.bubbles : false;
384
+ event.cancelable = eventInitDict && eventInitDict.cancelable !== undefined ? eventInitDict.cancelable : false;
385
+
386
+ return event;
387
+ };
388
+ if (existingProto) {
389
+ Object.defineProperty(window.Event, 'prototype', {
390
+ configurable: false,
391
+ enumerable: false,
392
+ writable: true,
393
+ value: existingProto
394
+ });
395
+ }
767
396
 
768
- // Detect initial open state
769
- if (this.$module.hasAttribute('open')) {
770
- $summary.setAttribute('aria-expanded', 'true');
771
- } else {
772
- $summary.setAttribute('aria-expanded', 'false');
773
- $content.style.display = 'none';
774
- }
397
+ if (!('createEvent' in document)) {
398
+ window.addEventListener = Window.prototype.addEventListener = Document.prototype.addEventListener = Element.prototype.addEventListener = function addEventListener() {
399
+ var
400
+ element = this,
401
+ type = arguments[0],
402
+ listener = arguments[1];
403
+
404
+ if (element === window && type in unlistenableWindowEvents) {
405
+ 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.');
406
+ }
407
+
408
+ if (!element._events) {
409
+ element._events = {};
410
+ }
411
+
412
+ if (!element._events[type]) {
413
+ element._events[type] = function (event) {
414
+ var
415
+ list = element._events[event.type].list,
416
+ events = list.slice(),
417
+ index = -1,
418
+ length = events.length,
419
+ eventElement;
420
+
421
+ event.preventDefault = function preventDefault() {
422
+ if (event.cancelable !== false) {
423
+ event.returnValue = false;
424
+ }
425
+ };
426
+
427
+ event.stopPropagation = function stopPropagation() {
428
+ event.cancelBubble = true;
429
+ };
430
+
431
+ event.stopImmediatePropagation = function stopImmediatePropagation() {
432
+ event.cancelBubble = true;
433
+ event.cancelImmediate = true;
434
+ };
435
+
436
+ event.currentTarget = element;
437
+ event.relatedTarget = event.fromElement || null;
438
+ event.target = event.target || event.srcElement || element;
439
+ event.timeStamp = new Date().getTime();
440
+
441
+ if (event.clientX) {
442
+ event.pageX = event.clientX + document.documentElement.scrollLeft;
443
+ event.pageY = event.clientY + document.documentElement.scrollTop;
444
+ }
445
+
446
+ while (++index < length && !event.cancelImmediate) {
447
+ if (index in events) {
448
+ eventElement = events[index];
449
+
450
+ if (indexOf(list, eventElement) !== -1 && typeof eventElement === 'function') {
451
+ eventElement.call(element, event);
452
+ }
453
+ }
454
+ }
455
+ };
456
+
457
+ element._events[type].list = [];
458
+
459
+ if (element.attachEvent) {
460
+ element.attachEvent('on' + type, element._events[type]);
461
+ }
462
+ }
463
+
464
+ element._events[type].list.push(listener);
465
+ };
466
+
467
+ window.removeEventListener = Window.prototype.removeEventListener = Document.prototype.removeEventListener = Element.prototype.removeEventListener = function removeEventListener() {
468
+ var
469
+ element = this,
470
+ type = arguments[0],
471
+ listener = arguments[1],
472
+ index;
473
+
474
+ if (element._events && element._events[type] && element._events[type].list) {
475
+ index = indexOf(element._events[type].list, listener);
476
+
477
+ if (index !== -1) {
478
+ element._events[type].list.splice(index, 1);
479
+
480
+ if (!element._events[type].list.length) {
481
+ if (element.detachEvent) {
482
+ element.detachEvent('on' + type, element._events[type]);
483
+ }
484
+ delete element._events[type];
485
+ }
486
+ }
487
+ }
488
+ };
489
+
490
+ window.dispatchEvent = Window.prototype.dispatchEvent = Document.prototype.dispatchEvent = Element.prototype.dispatchEvent = function dispatchEvent(event) {
491
+ if (!arguments.length) {
492
+ throw new Error('Not enough arguments');
493
+ }
494
+
495
+ if (!event || typeof event.type !== 'string') {
496
+ throw new Error('DOM Events Exception 0');
497
+ }
498
+
499
+ var element = this, type = event.type;
500
+
501
+ try {
502
+ if (!event.bubbles) {
503
+ event.cancelBubble = true;
504
+
505
+ var cancelBubbleEvent = function (event) {
506
+ event.cancelBubble = true;
507
+
508
+ (element || window).detachEvent('on' + type, cancelBubbleEvent);
509
+ };
510
+
511
+ this.attachEvent('on' + type, cancelBubbleEvent);
512
+ }
513
+
514
+ this.fireEvent('on' + type, event);
515
+ } catch (error) {
516
+ event.target = element;
517
+
518
+ do {
519
+ event.currentTarget = element;
520
+
521
+ if ('_events' in element && typeof element._events[type] === 'function') {
522
+ element._events[type].call(element, event);
523
+ }
524
+
525
+ if (typeof element['on' + type] === 'function') {
526
+ element['on' + type].call(element, event);
527
+ }
528
+
529
+ element = element.nodeType === 9 ? element.parentWindow : element.parentNode;
530
+ } while (element && !event.cancelBubble);
531
+ }
532
+
533
+ return true;
534
+ };
535
+
536
+ // Add the DOMContentLoaded Event
537
+ document.attachEvent('onreadystatechange', function() {
538
+ if (document.readyState === 'complete') {
539
+ document.dispatchEvent(new Event('DOMContentLoaded', {
540
+ bubbles: true
541
+ }));
542
+ }
543
+ });
544
+ }
545
+ }());
775
546
 
776
- // Bind an event to handle summary elements
777
- this.polyfillHandleInputs($summary, this.polyfillSetAttributes.bind(this));
778
- };
779
-
780
- /**
781
- * Define a statechange function that updates aria-expanded and style.display
782
- *
783
- * @returns {boolean} Returns true
784
- */
785
- Details.prototype.polyfillSetAttributes = function () {
786
- if (this.$module.hasAttribute('open')) {
787
- this.$module.removeAttribute('open');
788
- this.$summary.setAttribute('aria-expanded', 'false');
789
- this.$content.style.display = 'none';
790
- } else {
791
- this.$module.setAttribute('open', 'open');
792
- this.$summary.setAttribute('aria-expanded', 'true');
793
- this.$content.style.display = '';
547
+ })
548
+ .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
549
+
550
+ // @ts-nocheck
551
+
552
+ (function(undefined) {
553
+ // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Function/prototype/bind/detect.js
554
+ var detect = 'bind' in Function.prototype;
555
+
556
+ if (detect) return
557
+
558
+ // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Function.prototype.bind&flags=always
559
+ Object.defineProperty(Function.prototype, 'bind', {
560
+ value: function bind(that) { // .length is 1
561
+ // add necessary es5-shim utilities
562
+ var $Array = Array;
563
+ var $Object = Object;
564
+ var ObjectPrototype = $Object.prototype;
565
+ var ArrayPrototype = $Array.prototype;
566
+ var Empty = function Empty() {};
567
+ var to_string = ObjectPrototype.toString;
568
+ var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';
569
+ 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; };
570
+ var array_slice = ArrayPrototype.slice;
571
+ var array_concat = ArrayPrototype.concat;
572
+ var array_push = ArrayPrototype.push;
573
+ var max = Math.max;
574
+ // /add necessary es5-shim utilities
575
+
576
+ // 1. Let Target be the this value.
577
+ var target = this;
578
+ // 2. If IsCallable(Target) is false, throw a TypeError exception.
579
+ if (!isCallable(target)) {
580
+ throw new TypeError('Function.prototype.bind called on incompatible ' + target);
581
+ }
582
+ // 3. Let A be a new (possibly empty) internal list of all of the
583
+ // argument values provided after thisArg (arg1, arg2 etc), in order.
584
+ // XXX slicedArgs will stand in for "A" if used
585
+ var args = array_slice.call(arguments, 1); // for normal call
586
+ // 4. Let F be a new native ECMAScript object.
587
+ // 11. Set the [[Prototype]] internal property of F to the standard
588
+ // built-in Function prototype object as specified in 15.3.3.1.
589
+ // 12. Set the [[Call]] internal property of F as described in
590
+ // 15.3.4.5.1.
591
+ // 13. Set the [[Construct]] internal property of F as described in
592
+ // 15.3.4.5.2.
593
+ // 14. Set the [[HasInstance]] internal property of F as described in
594
+ // 15.3.4.5.3.
595
+ var bound;
596
+ var binder = function () {
597
+
598
+ if (this instanceof bound) {
599
+ // 15.3.4.5.2 [[Construct]]
600
+ // When the [[Construct]] internal method of a function object,
601
+ // F that was created using the bind function is called with a
602
+ // list of arguments ExtraArgs, the following steps are taken:
603
+ // 1. Let target be the value of F's [[TargetFunction]]
604
+ // internal property.
605
+ // 2. If target has no [[Construct]] internal method, a
606
+ // TypeError exception is thrown.
607
+ // 3. Let boundArgs be the value of F's [[BoundArgs]] internal
608
+ // property.
609
+ // 4. Let args be a new list containing the same values as the
610
+ // list boundArgs in the same order followed by the same
611
+ // values as the list ExtraArgs in the same order.
612
+ // 5. Return the result of calling the [[Construct]] internal
613
+ // method of target providing args as the arguments.
614
+
615
+ var result = target.apply(
616
+ this,
617
+ array_concat.call(args, array_slice.call(arguments))
618
+ );
619
+ if ($Object(result) === result) {
620
+ return result;
621
+ }
622
+ return this;
623
+
624
+ } else {
625
+ // 15.3.4.5.1 [[Call]]
626
+ // When the [[Call]] internal method of a function object, F,
627
+ // which was created using the bind function is called with a
628
+ // this value and a list of arguments ExtraArgs, the following
629
+ // steps are taken:
630
+ // 1. Let boundArgs be the value of F's [[BoundArgs]] internal
631
+ // property.
632
+ // 2. Let boundThis be the value of F's [[BoundThis]] internal
633
+ // property.
634
+ // 3. Let target be the value of F's [[TargetFunction]] internal
635
+ // property.
636
+ // 4. Let args be a new list containing the same values as the
637
+ // list boundArgs in the same order followed by the same
638
+ // values as the list ExtraArgs in the same order.
639
+ // 5. Return the result of calling the [[Call]] internal method
640
+ // of target providing boundThis as the this value and
641
+ // providing args as the arguments.
642
+
643
+ // equiv: target.call(this, ...boundArgs, ...args)
644
+ return target.apply(
645
+ that,
646
+ array_concat.call(args, array_slice.call(arguments))
647
+ );
648
+
649
+ }
650
+
651
+ };
652
+
653
+ // 15. If the [[Class]] internal property of Target is "Function", then
654
+ // a. Let L be the length property of Target minus the length of A.
655
+ // b. Set the length own property of F to either 0 or L, whichever is
656
+ // larger.
657
+ // 16. Else set the length own property of F to 0.
658
+
659
+ var boundLength = max(0, target.length - args.length);
660
+
661
+ // 17. Set the attributes of the length own property of F to the values
662
+ // specified in 15.3.5.1.
663
+ var boundArgs = [];
664
+ for (var i = 0; i < boundLength; i++) {
665
+ array_push.call(boundArgs, '$' + i);
666
+ }
667
+
668
+ // XXX Build a dynamic function with desired amount of arguments is the only
669
+ // way to set the length property of a function.
670
+ // In environments where Content Security Policies enabled (Chrome extensions,
671
+ // for ex.) all use of eval or Function costructor throws an exception.
672
+ // However in all of these environments Function.prototype.bind exists
673
+ // and so this code will never be executed.
674
+ bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this, arguments); }')(binder);
675
+
676
+ if (target.prototype) {
677
+ Empty.prototype = target.prototype;
678
+ bound.prototype = new Empty();
679
+ // Clean up dangling references.
680
+ Empty.prototype = null;
681
+ }
682
+
683
+ // TODO
684
+ // 18. Set the [[Extensible]] internal property of F to true.
685
+
686
+ // TODO
687
+ // 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3).
688
+ // 20. Call the [[DefineOwnProperty]] internal method of F with
689
+ // arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]:
690
+ // thrower, [[Enumerable]]: false, [[Configurable]]: false}, and
691
+ // false.
692
+ // 21. Call the [[DefineOwnProperty]] internal method of F with
693
+ // arguments "arguments", PropertyDescriptor {[[Get]]: thrower,
694
+ // [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false},
695
+ // and false.
696
+
697
+ // TODO
698
+ // NOTE Function objects created using Function.prototype.bind do not
699
+ // have a prototype property or the [[Code]], [[FormalParameters]], and
700
+ // [[Scope]] internal properties.
701
+ // XXX can't delete prototype in pure-js.
702
+
703
+ // 22. Return F.
704
+ return bound;
705
+ }
706
+ });
707
+ })
708
+ .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
709
+
710
+ /* eslint-disable es-x/no-function-prototype-bind -- Polyfill imported */
711
+
712
+ var KEY_ENTER = 13;
713
+ var KEY_SPACE = 32;
714
+
715
+ /**
716
+ * Details component
717
+ *
718
+ * @class
719
+ * @param {Element} $module - HTML element to use for details
720
+ */
721
+ function Details ($module) {
722
+ if (!($module instanceof HTMLElement)) {
723
+ return this
724
+ }
725
+
726
+ /** @deprecated Will be made private in v5.0 */
727
+ this.$module = $module;
728
+
729
+ /** @deprecated Will be made private in v5.0 */
730
+ this.$summary = null;
731
+
732
+ /** @deprecated Will be made private in v5.0 */
733
+ this.$content = null;
794
734
  }
795
735
 
796
- return true
797
- };
798
-
799
- /**
800
- * Handle cross-modal click events
801
- *
802
- * @param {object} node - element
803
- * @param {polyfillHandleInputsCallback} callback - function
804
- */
805
- Details.prototype.polyfillHandleInputs = function (node, callback) {
806
- node.addEventListener('keypress', function (event) {
807
- var target = event.target;
808
- // When the key gets pressed - check if it is enter or space
809
- if (event.keyCode === KEY_ENTER || event.keyCode === KEY_SPACE) {
810
- if (target.nodeName.toLowerCase() === 'summary') {
811
- // Prevent space from scrolling the page
812
- // and enter from submitting a form
813
- event.preventDefault();
814
- // Click to let the click event do all the necessary action
815
- if (target.click) {
816
- target.click();
817
- } else {
818
- // except Safari 5.1 and under don't support .click() here
819
- callback(event);
736
+ /**
737
+ * Initialise component
738
+ */
739
+ Details.prototype.init = function () {
740
+ // Check that required elements are present
741
+ if (!this.$module) {
742
+ return
743
+ }
744
+
745
+ // If there is native details support, we want to avoid running code to polyfill native behaviour.
746
+ var hasNativeDetails = 'HTMLDetailsElement' in window &&
747
+ this.$module instanceof HTMLDetailsElement;
748
+
749
+ if (!hasNativeDetails) {
750
+ this.polyfillDetails();
751
+ }
752
+ };
753
+
754
+ /**
755
+ * Polyfill component in older browsers
756
+ *
757
+ * @deprecated Will be made private in v5.0
758
+ */
759
+ Details.prototype.polyfillDetails = function () {
760
+ var $module = this.$module;
761
+
762
+ // Save shortcuts to the inner summary and content elements
763
+ var $summary = this.$summary = $module.getElementsByTagName('summary').item(0);
764
+ var $content = this.$content = $module.getElementsByTagName('div').item(0);
765
+
766
+ // If <details> doesn't have a <summary> and a <div> representing the content
767
+ // it means the required HTML structure is not met so the script will stop
768
+ if (!$summary || !$content) {
769
+ return
770
+ }
771
+
772
+ // If the content doesn't have an ID, assign it one now
773
+ // which we'll need for the summary's aria-controls assignment
774
+ if (!$content.id) {
775
+ $content.id = 'details-content-' + generateUniqueID();
776
+ }
777
+
778
+ // Add ARIA role="group" to details
779
+ $module.setAttribute('role', 'group');
780
+
781
+ // Add role=button to summary
782
+ $summary.setAttribute('role', 'button');
783
+
784
+ // Add aria-controls
785
+ $summary.setAttribute('aria-controls', $content.id);
786
+
787
+ // Set tabIndex so the summary is keyboard accessible for non-native elements
788
+ //
789
+ // We have to use the camelcase `tabIndex` property as there is a bug in IE6/IE7 when we set the correct attribute lowercase:
790
+ // See http://web.archive.org/web/20170120194036/http://www.saliences.com/browserBugs/tabIndex.html for more information.
791
+ $summary.tabIndex = 0;
792
+
793
+ // Detect initial open state
794
+ if (this.$module.hasAttribute('open')) {
795
+ $summary.setAttribute('aria-expanded', 'true');
796
+ } else {
797
+ $summary.setAttribute('aria-expanded', 'false');
798
+ $content.style.display = 'none';
799
+ }
800
+
801
+ // Bind an event to handle summary elements
802
+ this.polyfillHandleInputs(this.polyfillSetAttributes.bind(this));
803
+ };
804
+
805
+ /**
806
+ * Define a statechange function that updates aria-expanded and style.display
807
+ *
808
+ * @deprecated Will be made private in v5.0
809
+ * @returns {boolean} Returns true
810
+ */
811
+ Details.prototype.polyfillSetAttributes = function () {
812
+ if (this.$module.hasAttribute('open')) {
813
+ this.$module.removeAttribute('open');
814
+ this.$summary.setAttribute('aria-expanded', 'false');
815
+ this.$content.style.display = 'none';
816
+ } else {
817
+ this.$module.setAttribute('open', 'open');
818
+ this.$summary.setAttribute('aria-expanded', 'true');
819
+ this.$content.style.display = '';
820
+ }
821
+
822
+ return true
823
+ };
824
+
825
+ /**
826
+ * Handle cross-modal click events
827
+ *
828
+ * @deprecated Will be made private in v5.0
829
+ * @param {polyfillHandleInputsCallback} callback - function
830
+ */
831
+ Details.prototype.polyfillHandleInputs = function (callback) {
832
+ this.$summary.addEventListener('keypress', function (event) {
833
+ var $target = event.target;
834
+ // When the key gets pressed - check if it is enter or space
835
+ if (event.keyCode === KEY_ENTER || event.keyCode === KEY_SPACE) {
836
+ if ($target instanceof HTMLElement && $target.nodeName.toLowerCase() === 'summary') {
837
+ // Prevent space from scrolling the page
838
+ // and enter from submitting a form
839
+ event.preventDefault();
840
+ // Click to let the click event do all the necessary action
841
+ if ($target.click) {
842
+ $target.click();
843
+ } else {
844
+ // except Safari 5.1 and under don't support .click() here
845
+ callback(event);
846
+ }
820
847
  }
821
848
  }
822
- }
823
- });
824
-
825
- // Prevent keyup to prevent clicking twice in Firefox when using space key
826
- node.addEventListener('keyup', function (event) {
827
- var target = event.target;
828
- if (event.keyCode === KEY_SPACE) {
829
- if (target.nodeName.toLowerCase() === 'summary') {
830
- event.preventDefault();
849
+ });
850
+
851
+ // Prevent keyup to prevent clicking twice in Firefox when using space key
852
+ this.$summary.addEventListener('keyup', function (event) {
853
+ var $target = event.target;
854
+ if (event.keyCode === KEY_SPACE) {
855
+ if ($target instanceof HTMLElement && $target.nodeName.toLowerCase() === 'summary') {
856
+ event.preventDefault();
857
+ }
831
858
  }
832
- }
833
- });
859
+ });
834
860
 
835
- node.addEventListener('click', callback);
836
- };
861
+ this.$summary.addEventListener('click', callback);
862
+ };
837
863
 
838
- /**
839
- * @callback polyfillHandleInputsCallback
840
- * @param {KeyboardEvent} event - Keyboard event
841
- * @returns {undefined}
842
- */
864
+ /**
865
+ * @callback polyfillHandleInputsCallback
866
+ * @param {UIEvent} event - Keyboard or mouse event
867
+ * @returns {void}
868
+ */
843
869
 
844
- return Details;
870
+ return Details;
845
871
 
846
872
  })));
873
+ //# sourceMappingURL=details.js.map