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