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