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