hof 20.0.0-beta.23 → 20.0.0-beta.26

Sign up to get free protection for your applications and to get access to all the features.
@@ -36,7 +36,7 @@ function showCookieBannerSubmitted() {
36
36
  document.getElementById('cookie-banner-info').style.display = 'none';
37
37
  document.getElementById('cookie-banner-actions').style.display = 'none';
38
38
  var cookieBannerSubmitted = document.getElementById('cookie-banner-submitted');
39
- cookieBannerSubmitted.style.display = 'flex';
39
+ cookieBannerSubmitted.style.display = 'block';
40
40
  cookieBannerSubmitted.focus();
41
41
  }
42
42
 
@@ -146,7 +146,130 @@ module.exports = {
146
146
  };
147
147
 
148
148
  },{}],2:[function(require,module,exports){
149
- /* eslint-disable no-var */
149
+ /* eslint-disable no-undef, no-param-reassign, no-unused-vars */
150
+ (function () {
151
+ 'use strict';
152
+ const root = this;
153
+ if(typeof root.GOVUK === 'undefined') { root.GOVUK = {}; }
154
+
155
+ /*
156
+ Cookie methods
157
+ ==============
158
+
159
+ Usage:
160
+
161
+ Setting a cookie:
162
+ GOVUK.cookie('hobnob', 'tasty', { days: 30 });
163
+
164
+ Reading a cookie:
165
+ GOVUK.cookie('hobnob');
166
+
167
+ Deleting a cookie:
168
+ GOVUK.cookie('hobnob', null);
169
+ */
170
+ GOVUK.cookie = function (name, value, options) {
171
+ if(typeof value !== 'undefined') {
172
+ if(value === false || value === null) {
173
+ return GOVUK.setCookie(name, '', { days: -1 });
174
+ }
175
+ return GOVUK.setCookie(name, value, options);
176
+ }
177
+ return GOVUK.getCookie(name);
178
+ };
179
+ GOVUK.setCookie = function (name, value, options) {
180
+ if(typeof options === 'undefined') {
181
+ options = {};
182
+ }
183
+ let cookieString = name + '=' + value + '; path=/';
184
+ if (options.days) {
185
+ const date = new Date();
186
+ date.setTime(date.getTime() + (options.days * 24 * 60 * 60 * 1000));
187
+ cookieString = cookieString + '; expires=' + date.toGMTString();
188
+ }
189
+ if (document.location.protocol === 'https:') {
190
+ cookieString = cookieString + '; Secure';
191
+ }
192
+ document.cookie = cookieString;
193
+ };
194
+ GOVUK.getCookie = function (name) {
195
+ const nameEQ = name + '=';
196
+ const cookies = document.cookie.split(';');
197
+ for(let i = 0, len = cookies.length; i < len; i++) {
198
+ let cookie = cookies[i];
199
+ while (cookie.charAt(0) === ' ') {
200
+ cookie = cookie.substring(1, cookie.length);
201
+ }
202
+ if (cookie.indexOf(nameEQ) === 0) {
203
+ return decodeURIComponent(cookie.substring(nameEQ.length));
204
+ }
205
+ }
206
+ return null;
207
+ };
208
+ }).call(this);
209
+ (function () {
210
+ 'use strict';
211
+ const root = this;
212
+ if (typeof root.GOVUK === 'undefined') { root.GOVUK = {}; }
213
+
214
+ GOVUK.addCookieMessage = function () {
215
+ const message = document.getElementById('global-cookie-message');
216
+
217
+ const hasCookieMessage = (message && GOVUK.cookie('seen_cookie_message') === null);
218
+
219
+ if (hasCookieMessage) {
220
+ message.style.display = 'block';
221
+ GOVUK.cookie('seen_cookie_message', 'yes', { days: 28 });
222
+
223
+ document.addEventListener('DOMContentLoaded', function (event) {
224
+ if (GOVUK.analytics && typeof GOVUK.analytics.trackEvent === 'function') {
225
+ GOVUK.analytics.trackEvent('cookieBanner', 'Cookie banner shown', {
226
+ value: 1,
227
+ nonInteraction: true
228
+ });
229
+ }
230
+ });
231
+ }
232
+ };
233
+ }).call(this)
234
+ ;
235
+ (function () {
236
+ 'use strict';
237
+
238
+ // add cookie message
239
+ if (window.GOVUK && GOVUK.addCookieMessage) {
240
+ GOVUK.addCookieMessage();
241
+ }
242
+
243
+ // header navigation toggle
244
+ if (document.querySelectorAll && document.addEventListener) {
245
+ const els = document.querySelectorAll('.js-header-toggle');
246
+ let i; let _i;
247
+ for(i = 0, _i = els.length; i < _i; i++) {
248
+ els[i].addEventListener('click', function (e) {
249
+ e.preventDefault();
250
+ const target = document.getElementById(this.getAttribute('href').substr(1));
251
+ const targetClass = target.getAttribute('class') || '';
252
+ const sourceClass = this.getAttribute('class') || '';
253
+
254
+ if(targetClass.indexOf('js-visible') !== -1) {
255
+ target.setAttribute('class', targetClass.replace(/(^|\s)js-visible(\s|$)/, ''));
256
+ } else {
257
+ target.setAttribute('class', targetClass + ' js-visible');
258
+ }
259
+ if(sourceClass.indexOf('js-visible') !== -1) {
260
+ this.setAttribute('class', sourceClass.replace(/(^|\s)js-visible(\s|$)/, ''));
261
+ } else {
262
+ this.setAttribute('class', sourceClass + ' js-visible');
263
+ }
264
+ this.setAttribute('aria-expanded', this.getAttribute('aria-expanded') !== 'true');
265
+ target.setAttribute('aria-hidden', target.getAttribute('aria-hidden') === 'false');
266
+ });
267
+ }
268
+ }
269
+ }).call(this);
270
+
271
+ },{}],3:[function(require,module,exports){
272
+ /* eslint-disable no-var, vars-on-top, no-unused-vars */
150
273
  'use strict';
151
274
 
152
275
  var toolkit = require('../../../toolkit');
@@ -156,6 +279,11 @@ var formFocus = toolkit.formFocus;
156
279
  var characterCount = toolkit.characterCount;
157
280
  var validation = toolkit.validation;
158
281
 
282
+ var GOVUK = require('govuk-frontend');
283
+ GOVUK.initAll();
284
+ window.GOVUK = GOVUK;
285
+ var skipToMain = require('./skip-to-main');
286
+ var cookie = require('./govuk-cookies');
159
287
  var cookieSettings = require('./cookieSettings');
160
288
 
161
289
  toolkit.detailsSummary();
@@ -168,7 +296,28 @@ helpers.documentReady(cookieSettings.onLoad);
168
296
  helpers.documentReady(characterCount);
169
297
  helpers.documentReady(validation);
170
298
 
171
- },{"../../../toolkit":9,"./cookieSettings":1}],3:[function(require,module,exports){
299
+ },{"../../../toolkit":11,"./cookieSettings":1,"./govuk-cookies":2,"./skip-to-main":4,"govuk-frontend":12}],4:[function(require,module,exports){
300
+ const skipToMain = function () {
301
+ const skipToMainLink = document.getElementById('skip-to-main');
302
+ const firstControlId = skipToMainLink.hash.split('#')[1] ? skipToMainLink.hash.split('#')[1] : 'main-content';
303
+ if(firstControlId === 'main-content') {
304
+ skipToMainLink.setAttribute('href', '#main-content');
305
+ }
306
+ if(firstControlId) {
307
+ // eslint-disable-next-line no-unused-vars
308
+ skipToMainLink.onclick = function (e) {
309
+ // here timeout added just to make this functionality asynchronous
310
+ // to focus on form as well as non form contents
311
+ setTimeout(() => {
312
+ const firstControl = document.getElementById(firstControlId);
313
+ firstControl.focus();
314
+ }, 10);
315
+ };
316
+ }
317
+ };
318
+ skipToMain();
319
+
320
+ },{}],5:[function(require,module,exports){
172
321
  /* eslint-disable max-len, no-var, no-use-before-define, no-param-reassign, vars-on-top, radix */
173
322
  'use strict';
174
323
 
@@ -201,12 +350,12 @@ CharacterCount.prototype.updateCount = function () {
201
350
  this.$maxlengthHint.innerHTML = 'You have ' + number + characterNoun + remainderSuffix;
202
351
 
203
352
  if (currentLength >= this.maxLength + 1) {
204
- helpers.removeClass(this.$maxlengthHint, 'form-hint');
205
- helpers.addClass(this.$maxlengthHint, 'error-message');
353
+ helpers.removeClass(this.$maxlengthHint, 'govuk-hint');
354
+ helpers.addClass(this.$maxlengthHint, 'govuk-error-message');
206
355
  helpers.addClass(this.$textarea, 'textarea-error');
207
356
  } else {
208
- helpers.addClass(this.$maxlengthHint, 'form-hint');
209
- helpers.removeClass(this.$maxlengthHint, 'error-message');
357
+ helpers.addClass(this.$maxlengthHint, 'govuk-hint');
358
+ helpers.removeClass(this.$maxlengthHint, 'govuk-error-message');
210
359
  helpers.removeClass(this.$textarea, 'textarea-error');
211
360
  }
212
361
  };
@@ -269,7 +418,7 @@ function characterCountAll() {
269
418
 
270
419
  module.exports = characterCountAll;
271
420
 
272
- },{"./helpers":5}],4:[function(require,module,exports){
421
+ },{"./helpers":7}],6:[function(require,module,exports){
273
422
  /* eslint-disable max-len, no-var, no-param-reassign, vars-on-top */
274
423
  /**
275
424
  * This module adds the yellow focus border to:
@@ -343,11 +492,20 @@ function formFocus() {
343
492
  var labels;
344
493
  var summaries;
345
494
 
346
- if (getElementFromSummaryLink && getEditPath === 'edit') {
495
+ var editMode = getElementFromSummaryLink && getEditPath === 'edit';
496
+
497
+ if (getElementFromSummaryLink && document.getElementById(getElementFromSummaryLink) && editMode) {
347
498
  document.getElementById(getElementFromSummaryLink).focus();
499
+ }
500
+
501
+ if (getElementFromSummaryLink && document.getElementById(getElementFromSummaryLink + '-group') && editMode) {
348
502
  document.getElementById(getElementFromSummaryLink + '-group').scrollIntoView();
349
503
  }
350
504
 
505
+ if (document.getElementById(getElementFromSummaryLink + '-day') && forms.length === 1 && editMode) {
506
+ document.getElementById(getElementFromSummaryLink + '-day').focus();
507
+ }
508
+
351
509
  if (forms.length > 0) {
352
510
  labels = document.getElementsByTagName('label');
353
511
  if (labels) {
@@ -363,7 +521,7 @@ function formFocus() {
363
521
 
364
522
  module.exports = formFocus;
365
523
 
366
- },{"./helpers":5,"lodash":10}],5:[function(require,module,exports){
524
+ },{"./helpers":7,"lodash":13}],7:[function(require,module,exports){
367
525
  /* eslint-disable max-len, no-var, no-param-reassign, vars-on-top, no-extend-native */
368
526
  'use strict';
369
527
 
@@ -542,7 +700,7 @@ helpers.pagehide = function (func) {
542
700
 
543
701
  module.exports = helpers;
544
702
 
545
- },{"lodash":10}],6:[function(require,module,exports){
703
+ },{"lodash":13}],8:[function(require,module,exports){
546
704
  /* eslint-disable max-len, no-var, no-param-reassign, vars-on-top */
547
705
  'use strict';
548
706
 
@@ -614,7 +772,7 @@ function progressiveReveal() {
614
772
 
615
773
  module.exports = progressiveReveal;
616
774
 
617
- },{"./helpers":5,"lodash":10}],7:[function(require,module,exports){
775
+ },{"./helpers":7,"lodash":13}],9:[function(require,module,exports){
618
776
  /* eslint-disable max-len, no-var, no-shadow, vars-on-top */
619
777
  var each = require('lodash').forEach;
620
778
 
@@ -641,7 +799,12 @@ function clicked(e) {
641
799
  }
642
800
 
643
801
  if (inputs) {
644
- inputs[0].focus();
802
+ if (inputs[0].getAttribute('type') === 'hidden') {
803
+ var getVisibleElements = group.querySelectorAll('input[type=text]');
804
+ getVisibleElements[0].focus();
805
+ } else {
806
+ inputs[0].focus();
807
+ }
645
808
  }
646
809
  }
647
810
  }
@@ -678,7 +841,7 @@ function validation() {
678
841
 
679
842
  module.exports = validation;
680
843
 
681
- },{"./helpers":5,"lodash":10}],8:[function(require,module,exports){
844
+ },{"./helpers":7,"lodash":13}],10:[function(require,module,exports){
682
845
  /* eslint-disable max-len, no-var, no-cond-assign, no-param-reassign, vars-on-top */
683
846
  // <details> polyfill
684
847
  // http://caniuse.com/#feat=details
@@ -869,7 +1032,7 @@ module.exports = validation;
869
1032
  addEvent(window, 'load', addDetailsPolyfill);
870
1033
  })();
871
1034
 
872
- },{}],9:[function(require,module,exports){
1035
+ },{}],11:[function(require,module,exports){
873
1036
  module.exports = {
874
1037
  helpers: require('./assets/javascript/helpers'),
875
1038
  formFocus: require('./assets/javascript/form-focus'),
@@ -881,7 +1044,2627 @@ module.exports = {
881
1044
  characterCount: require('./assets/javascript/character-count')
882
1045
  };
883
1046
 
884
- },{"./assets/javascript/character-count":3,"./assets/javascript/form-focus":4,"./assets/javascript/helpers":5,"./assets/javascript/progressive-reveal":6,"./assets/javascript/validation":7,"./assets/javascript/vendor/details.polyfill":8}],10:[function(require,module,exports){
1047
+ },{"./assets/javascript/character-count":5,"./assets/javascript/form-focus":6,"./assets/javascript/helpers":7,"./assets/javascript/progressive-reveal":8,"./assets/javascript/validation":9,"./assets/javascript/vendor/details.polyfill":10}],12:[function(require,module,exports){
1048
+ (function (global){(function (){
1049
+ (function (global, factory) {
1050
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
1051
+ typeof define === 'function' && define.amd ? define('GOVUKFrontend', ['exports'], factory) :
1052
+ (factory((global.GOVUKFrontend = {})));
1053
+ }(this, (function (exports) { 'use strict';
1054
+
1055
+ /**
1056
+ * TODO: Ideally this would be a NodeList.prototype.forEach polyfill
1057
+ * This seems to fail in IE8, requires more investigation.
1058
+ * See: https://github.com/imagitama/nodelist-foreach-polyfill
1059
+ */
1060
+ function nodeListForEach (nodes, callback) {
1061
+ if (window.NodeList.prototype.forEach) {
1062
+ return nodes.forEach(callback)
1063
+ }
1064
+ for (var i = 0; i < nodes.length; i++) {
1065
+ callback.call(window, nodes[i], i, nodes);
1066
+ }
1067
+ }
1068
+
1069
+ // Used to generate a unique string, allows multiple instances of the component without
1070
+ // Them conflicting with each other.
1071
+ // https://stackoverflow.com/a/8809472
1072
+ function generateUniqueID () {
1073
+ var d = new Date().getTime();
1074
+ if (typeof window.performance !== 'undefined' && typeof window.performance.now === 'function') {
1075
+ d += window.performance.now(); // use high-precision timer if available
1076
+ }
1077
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
1078
+ var r = (d + Math.random() * 16) % 16 | 0;
1079
+ d = Math.floor(d / 16);
1080
+ return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16)
1081
+ })
1082
+ }
1083
+
1084
+ (function(undefined) {
1085
+
1086
+ // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Object/defineProperty/detect.js
1087
+ var detect = (
1088
+ // In IE8, defineProperty could only act on DOM elements, so full support
1089
+ // for the feature requires the ability to set a property on an arbitrary object
1090
+ 'defineProperty' in Object && (function() {
1091
+ try {
1092
+ var a = {};
1093
+ Object.defineProperty(a, 'test', {value:42});
1094
+ return true;
1095
+ } catch(e) {
1096
+ return false
1097
+ }
1098
+ }())
1099
+ );
1100
+
1101
+ if (detect) return
1102
+
1103
+ // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Object.defineProperty&flags=always
1104
+ (function (nativeDefineProperty) {
1105
+
1106
+ var supportsAccessors = Object.prototype.hasOwnProperty('__defineGetter__');
1107
+ var ERR_ACCESSORS_NOT_SUPPORTED = 'Getters & setters cannot be defined on this javascript engine';
1108
+ var ERR_VALUE_ACCESSORS = 'A property cannot both have accessors and be writable or have a value';
1109
+
1110
+ Object.defineProperty = function defineProperty(object, property, descriptor) {
1111
+
1112
+ // Where native support exists, assume it
1113
+ if (nativeDefineProperty && (object === window || object === document || object === Element.prototype || object instanceof Element)) {
1114
+ return nativeDefineProperty(object, property, descriptor);
1115
+ }
1116
+
1117
+ if (object === null || !(object instanceof Object || typeof object === 'object')) {
1118
+ throw new TypeError('Object.defineProperty called on non-object');
1119
+ }
1120
+
1121
+ if (!(descriptor instanceof Object)) {
1122
+ throw new TypeError('Property description must be an object');
1123
+ }
1124
+
1125
+ var propertyString = String(property);
1126
+ var hasValueOrWritable = 'value' in descriptor || 'writable' in descriptor;
1127
+ var getterType = 'get' in descriptor && typeof descriptor.get;
1128
+ var setterType = 'set' in descriptor && typeof descriptor.set;
1129
+
1130
+ // handle descriptor.get
1131
+ if (getterType) {
1132
+ if (getterType !== 'function') {
1133
+ throw new TypeError('Getter must be a function');
1134
+ }
1135
+ if (!supportsAccessors) {
1136
+ throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
1137
+ }
1138
+ if (hasValueOrWritable) {
1139
+ throw new TypeError(ERR_VALUE_ACCESSORS);
1140
+ }
1141
+ Object.__defineGetter__.call(object, propertyString, descriptor.get);
1142
+ } else {
1143
+ object[propertyString] = descriptor.value;
1144
+ }
1145
+
1146
+ // handle descriptor.set
1147
+ if (setterType) {
1148
+ if (setterType !== 'function') {
1149
+ throw new TypeError('Setter must be a function');
1150
+ }
1151
+ if (!supportsAccessors) {
1152
+ throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
1153
+ }
1154
+ if (hasValueOrWritable) {
1155
+ throw new TypeError(ERR_VALUE_ACCESSORS);
1156
+ }
1157
+ Object.__defineSetter__.call(object, propertyString, descriptor.set);
1158
+ }
1159
+
1160
+ // OK to define value unconditionally - if a getter has been specified as well, an error would be thrown above
1161
+ if ('value' in descriptor) {
1162
+ object[propertyString] = descriptor.value;
1163
+ }
1164
+
1165
+ return object;
1166
+ };
1167
+ }(Object.defineProperty));
1168
+ })
1169
+ .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
1170
+
1171
+ (function(undefined) {
1172
+ // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Function/prototype/bind/detect.js
1173
+ var detect = 'bind' in Function.prototype;
1174
+
1175
+ if (detect) return
1176
+
1177
+ // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Function.prototype.bind&flags=always
1178
+ Object.defineProperty(Function.prototype, 'bind', {
1179
+ value: function bind(that) { // .length is 1
1180
+ // add necessary es5-shim utilities
1181
+ var $Array = Array;
1182
+ var $Object = Object;
1183
+ var ObjectPrototype = $Object.prototype;
1184
+ var ArrayPrototype = $Array.prototype;
1185
+ var Empty = function Empty() {};
1186
+ var to_string = ObjectPrototype.toString;
1187
+ var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';
1188
+ 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; };
1189
+ var array_slice = ArrayPrototype.slice;
1190
+ var array_concat = ArrayPrototype.concat;
1191
+ var array_push = ArrayPrototype.push;
1192
+ var max = Math.max;
1193
+ // /add necessary es5-shim utilities
1194
+
1195
+ // 1. Let Target be the this value.
1196
+ var target = this;
1197
+ // 2. If IsCallable(Target) is false, throw a TypeError exception.
1198
+ if (!isCallable(target)) {
1199
+ throw new TypeError('Function.prototype.bind called on incompatible ' + target);
1200
+ }
1201
+ // 3. Let A be a new (possibly empty) internal list of all of the
1202
+ // argument values provided after thisArg (arg1, arg2 etc), in order.
1203
+ // XXX slicedArgs will stand in for "A" if used
1204
+ var args = array_slice.call(arguments, 1); // for normal call
1205
+ // 4. Let F be a new native ECMAScript object.
1206
+ // 11. Set the [[Prototype]] internal property of F to the standard
1207
+ // built-in Function prototype object as specified in 15.3.3.1.
1208
+ // 12. Set the [[Call]] internal property of F as described in
1209
+ // 15.3.4.5.1.
1210
+ // 13. Set the [[Construct]] internal property of F as described in
1211
+ // 15.3.4.5.2.
1212
+ // 14. Set the [[HasInstance]] internal property of F as described in
1213
+ // 15.3.4.5.3.
1214
+ var bound;
1215
+ var binder = function () {
1216
+
1217
+ if (this instanceof bound) {
1218
+ // 15.3.4.5.2 [[Construct]]
1219
+ // When the [[Construct]] internal method of a function object,
1220
+ // F that was created using the bind function is called with a
1221
+ // list of arguments ExtraArgs, the following steps are taken:
1222
+ // 1. Let target be the value of F's [[TargetFunction]]
1223
+ // internal property.
1224
+ // 2. If target has no [[Construct]] internal method, a
1225
+ // TypeError exception is thrown.
1226
+ // 3. Let boundArgs be the value of F's [[BoundArgs]] internal
1227
+ // property.
1228
+ // 4. Let args be a new list containing the same values as the
1229
+ // list boundArgs in the same order followed by the same
1230
+ // values as the list ExtraArgs in the same order.
1231
+ // 5. Return the result of calling the [[Construct]] internal
1232
+ // method of target providing args as the arguments.
1233
+
1234
+ var result = target.apply(
1235
+ this,
1236
+ array_concat.call(args, array_slice.call(arguments))
1237
+ );
1238
+ if ($Object(result) === result) {
1239
+ return result;
1240
+ }
1241
+ return this;
1242
+
1243
+ } else {
1244
+ // 15.3.4.5.1 [[Call]]
1245
+ // When the [[Call]] internal method of a function object, F,
1246
+ // which was created using the bind function is called with a
1247
+ // this value and a list of arguments ExtraArgs, the following
1248
+ // steps are taken:
1249
+ // 1. Let boundArgs be the value of F's [[BoundArgs]] internal
1250
+ // property.
1251
+ // 2. Let boundThis be the value of F's [[BoundThis]] internal
1252
+ // property.
1253
+ // 3. Let target be the value of F's [[TargetFunction]] internal
1254
+ // property.
1255
+ // 4. Let args be a new list containing the same values as the
1256
+ // list boundArgs in the same order followed by the same
1257
+ // values as the list ExtraArgs in the same order.
1258
+ // 5. Return the result of calling the [[Call]] internal method
1259
+ // of target providing boundThis as the this value and
1260
+ // providing args as the arguments.
1261
+
1262
+ // equiv: target.call(this, ...boundArgs, ...args)
1263
+ return target.apply(
1264
+ that,
1265
+ array_concat.call(args, array_slice.call(arguments))
1266
+ );
1267
+
1268
+ }
1269
+
1270
+ };
1271
+
1272
+ // 15. If the [[Class]] internal property of Target is "Function", then
1273
+ // a. Let L be the length property of Target minus the length of A.
1274
+ // b. Set the length own property of F to either 0 or L, whichever is
1275
+ // larger.
1276
+ // 16. Else set the length own property of F to 0.
1277
+
1278
+ var boundLength = max(0, target.length - args.length);
1279
+
1280
+ // 17. Set the attributes of the length own property of F to the values
1281
+ // specified in 15.3.5.1.
1282
+ var boundArgs = [];
1283
+ for (var i = 0; i < boundLength; i++) {
1284
+ array_push.call(boundArgs, '$' + i);
1285
+ }
1286
+
1287
+ // XXX Build a dynamic function with desired amount of arguments is the only
1288
+ // way to set the length property of a function.
1289
+ // In environments where Content Security Policies enabled (Chrome extensions,
1290
+ // for ex.) all use of eval or Function costructor throws an exception.
1291
+ // However in all of these environments Function.prototype.bind exists
1292
+ // and so this code will never be executed.
1293
+ bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this, arguments); }')(binder);
1294
+
1295
+ if (target.prototype) {
1296
+ Empty.prototype = target.prototype;
1297
+ bound.prototype = new Empty();
1298
+ // Clean up dangling references.
1299
+ Empty.prototype = null;
1300
+ }
1301
+
1302
+ // TODO
1303
+ // 18. Set the [[Extensible]] internal property of F to true.
1304
+
1305
+ // TODO
1306
+ // 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3).
1307
+ // 20. Call the [[DefineOwnProperty]] internal method of F with
1308
+ // arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]:
1309
+ // thrower, [[Enumerable]]: false, [[Configurable]]: false}, and
1310
+ // false.
1311
+ // 21. Call the [[DefineOwnProperty]] internal method of F with
1312
+ // arguments "arguments", PropertyDescriptor {[[Get]]: thrower,
1313
+ // [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false},
1314
+ // and false.
1315
+
1316
+ // TODO
1317
+ // NOTE Function objects created using Function.prototype.bind do not
1318
+ // have a prototype property or the [[Code]], [[FormalParameters]], and
1319
+ // [[Scope]] internal properties.
1320
+ // XXX can't delete prototype in pure-js.
1321
+
1322
+ // 22. Return F.
1323
+ return bound;
1324
+ }
1325
+ });
1326
+ })
1327
+ .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
1328
+
1329
+ (function(undefined) {
1330
+
1331
+ // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-service/master/packages/polyfill-library/polyfills/DOMTokenList/detect.js
1332
+ var detect = (
1333
+ 'DOMTokenList' in this && (function (x) {
1334
+ return 'classList' in x ? !x.classList.toggle('x', false) && !x.className : true;
1335
+ })(document.createElement('x'))
1336
+ );
1337
+
1338
+ if (detect) return
1339
+
1340
+ // Polyfill from https://raw.githubusercontent.com/Financial-Times/polyfill-service/master/packages/polyfill-library/polyfills/DOMTokenList/polyfill.js
1341
+ (function (global) {
1342
+ var nativeImpl = "DOMTokenList" in global && global.DOMTokenList;
1343
+
1344
+ if (
1345
+ !nativeImpl ||
1346
+ (
1347
+ !!document.createElementNS &&
1348
+ !!document.createElementNS('http://www.w3.org/2000/svg', 'svg') &&
1349
+ !(document.createElementNS("http://www.w3.org/2000/svg", "svg").classList instanceof DOMTokenList)
1350
+ )
1351
+ ) {
1352
+ global.DOMTokenList = (function() { // eslint-disable-line no-unused-vars
1353
+ var dpSupport = true;
1354
+ var defineGetter = function (object, name, fn, configurable) {
1355
+ if (Object.defineProperty)
1356
+ Object.defineProperty(object, name, {
1357
+ configurable: false === dpSupport ? true : !!configurable,
1358
+ get: fn
1359
+ });
1360
+
1361
+ else object.__defineGetter__(name, fn);
1362
+ };
1363
+
1364
+ /** Ensure the browser allows Object.defineProperty to be used on native JavaScript objects. */
1365
+ try {
1366
+ defineGetter({}, "support");
1367
+ }
1368
+ catch (e) {
1369
+ dpSupport = false;
1370
+ }
1371
+
1372
+
1373
+ var _DOMTokenList = function (el, prop) {
1374
+ var that = this;
1375
+ var tokens = [];
1376
+ var tokenMap = {};
1377
+ var length = 0;
1378
+ var maxLength = 0;
1379
+ var addIndexGetter = function (i) {
1380
+ defineGetter(that, i, function () {
1381
+ preop();
1382
+ return tokens[i];
1383
+ }, false);
1384
+
1385
+ };
1386
+ var reindex = function () {
1387
+
1388
+ /** Define getter functions for array-like access to the tokenList's contents. */
1389
+ if (length >= maxLength)
1390
+ for (; maxLength < length; ++maxLength) {
1391
+ addIndexGetter(maxLength);
1392
+ }
1393
+ };
1394
+
1395
+ /** Helper function called at the start of each class method. Internal use only. */
1396
+ var preop = function () {
1397
+ var error;
1398
+ var i;
1399
+ var args = arguments;
1400
+ var rSpace = /\s+/;
1401
+
1402
+ /** Validate the token/s passed to an instance method, if any. */
1403
+ if (args.length)
1404
+ for (i = 0; i < args.length; ++i)
1405
+ if (rSpace.test(args[i])) {
1406
+ error = new SyntaxError('String "' + args[i] + '" ' + "contains" + ' an invalid character');
1407
+ error.code = 5;
1408
+ error.name = "InvalidCharacterError";
1409
+ throw error;
1410
+ }
1411
+
1412
+
1413
+ /** Split the new value apart by whitespace*/
1414
+ if (typeof el[prop] === "object") {
1415
+ tokens = ("" + el[prop].baseVal).replace(/^\s+|\s+$/g, "").split(rSpace);
1416
+ } else {
1417
+ tokens = ("" + el[prop]).replace(/^\s+|\s+$/g, "").split(rSpace);
1418
+ }
1419
+
1420
+ /** Avoid treating blank strings as single-item token lists */
1421
+ if ("" === tokens[0]) tokens = [];
1422
+
1423
+ /** Repopulate the internal token lists */
1424
+ tokenMap = {};
1425
+ for (i = 0; i < tokens.length; ++i)
1426
+ tokenMap[tokens[i]] = true;
1427
+ length = tokens.length;
1428
+ reindex();
1429
+ };
1430
+
1431
+ /** Populate our internal token list if the targeted attribute of the subject element isn't empty. */
1432
+ preop();
1433
+
1434
+ /** Return the number of tokens in the underlying string. Read-only. */
1435
+ defineGetter(that, "length", function () {
1436
+ preop();
1437
+ return length;
1438
+ });
1439
+
1440
+ /** Override the default toString/toLocaleString methods to return a space-delimited list of tokens when typecast. */
1441
+ that.toLocaleString =
1442
+ that.toString = function () {
1443
+ preop();
1444
+ return tokens.join(" ");
1445
+ };
1446
+
1447
+ that.item = function (idx) {
1448
+ preop();
1449
+ return tokens[idx];
1450
+ };
1451
+
1452
+ that.contains = function (token) {
1453
+ preop();
1454
+ return !!tokenMap[token];
1455
+ };
1456
+
1457
+ that.add = function () {
1458
+ preop.apply(that, args = arguments);
1459
+
1460
+ for (var args, token, i = 0, l = args.length; i < l; ++i) {
1461
+ token = args[i];
1462
+ if (!tokenMap[token]) {
1463
+ tokens.push(token);
1464
+ tokenMap[token] = true;
1465
+ }
1466
+ }
1467
+
1468
+ /** Update the targeted attribute of the attached element if the token list's changed. */
1469
+ if (length !== tokens.length) {
1470
+ length = tokens.length >>> 0;
1471
+ if (typeof el[prop] === "object") {
1472
+ el[prop].baseVal = tokens.join(" ");
1473
+ } else {
1474
+ el[prop] = tokens.join(" ");
1475
+ }
1476
+ reindex();
1477
+ }
1478
+ };
1479
+
1480
+ that.remove = function () {
1481
+ preop.apply(that, args = arguments);
1482
+
1483
+ /** Build a hash of token names to compare against when recollecting our token list. */
1484
+ for (var args, ignore = {}, i = 0, t = []; i < args.length; ++i) {
1485
+ ignore[args[i]] = true;
1486
+ delete tokenMap[args[i]];
1487
+ }
1488
+
1489
+ /** Run through our tokens list and reassign only those that aren't defined in the hash declared above. */
1490
+ for (i = 0; i < tokens.length; ++i)
1491
+ if (!ignore[tokens[i]]) t.push(tokens[i]);
1492
+
1493
+ tokens = t;
1494
+ length = t.length >>> 0;
1495
+
1496
+ /** Update the targeted attribute of the attached element. */
1497
+ if (typeof el[prop] === "object") {
1498
+ el[prop].baseVal = tokens.join(" ");
1499
+ } else {
1500
+ el[prop] = tokens.join(" ");
1501
+ }
1502
+ reindex();
1503
+ };
1504
+
1505
+ that.toggle = function (token, force) {
1506
+ preop.apply(that, [token]);
1507
+
1508
+ /** Token state's being forced. */
1509
+ if (undefined !== force) {
1510
+ if (force) {
1511
+ that.add(token);
1512
+ return true;
1513
+ } else {
1514
+ that.remove(token);
1515
+ return false;
1516
+ }
1517
+ }
1518
+
1519
+ /** Token already exists in tokenList. Remove it, and return FALSE. */
1520
+ if (tokenMap[token]) {
1521
+ that.remove(token);
1522
+ return false;
1523
+ }
1524
+
1525
+ /** Otherwise, add the token and return TRUE. */
1526
+ that.add(token);
1527
+ return true;
1528
+ };
1529
+
1530
+ return that;
1531
+ };
1532
+
1533
+ return _DOMTokenList;
1534
+ }());
1535
+ }
1536
+
1537
+ // Add second argument to native DOMTokenList.toggle() if necessary
1538
+ (function () {
1539
+ var e = document.createElement('span');
1540
+ if (!('classList' in e)) return;
1541
+ e.classList.toggle('x', false);
1542
+ if (!e.classList.contains('x')) return;
1543
+ e.classList.constructor.prototype.toggle = function toggle(token /*, force*/) {
1544
+ var force = arguments[1];
1545
+ if (force === undefined) {
1546
+ var add = !this.contains(token);
1547
+ this[add ? 'add' : 'remove'](token);
1548
+ return add;
1549
+ }
1550
+ force = !!force;
1551
+ this[force ? 'add' : 'remove'](token);
1552
+ return force;
1553
+ };
1554
+ }());
1555
+
1556
+ // Add multiple arguments to native DOMTokenList.add() if necessary
1557
+ (function () {
1558
+ var e = document.createElement('span');
1559
+ if (!('classList' in e)) return;
1560
+ e.classList.add('a', 'b');
1561
+ if (e.classList.contains('b')) return;
1562
+ var native = e.classList.constructor.prototype.add;
1563
+ e.classList.constructor.prototype.add = function () {
1564
+ var args = arguments;
1565
+ var l = arguments.length;
1566
+ for (var i = 0; i < l; i++) {
1567
+ native.call(this, args[i]);
1568
+ }
1569
+ };
1570
+ }());
1571
+
1572
+ // Add multiple arguments to native DOMTokenList.remove() if necessary
1573
+ (function () {
1574
+ var e = document.createElement('span');
1575
+ if (!('classList' in e)) return;
1576
+ e.classList.add('a');
1577
+ e.classList.add('b');
1578
+ e.classList.remove('a', 'b');
1579
+ if (!e.classList.contains('b')) return;
1580
+ var native = e.classList.constructor.prototype.remove;
1581
+ e.classList.constructor.prototype.remove = function () {
1582
+ var args = arguments;
1583
+ var l = arguments.length;
1584
+ for (var i = 0; i < l; i++) {
1585
+ native.call(this, args[i]);
1586
+ }
1587
+ };
1588
+ }());
1589
+
1590
+ }(this));
1591
+
1592
+ }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
1593
+
1594
+ (function(undefined) {
1595
+
1596
+ // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Document/detect.js
1597
+ var detect = ("Document" in this);
1598
+
1599
+ if (detect) return
1600
+
1601
+ // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Document&flags=always
1602
+ if ((typeof WorkerGlobalScope === "undefined") && (typeof importScripts !== "function")) {
1603
+
1604
+ if (this.HTMLDocument) { // IE8
1605
+
1606
+ // HTMLDocument is an extension of Document. If the browser has HTMLDocument but not Document, the former will suffice as an alias for the latter.
1607
+ this.Document = this.HTMLDocument;
1608
+
1609
+ } else {
1610
+
1611
+ // 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.
1612
+ this.Document = this.HTMLDocument = document.constructor = (new Function('return function Document() {}')());
1613
+ this.Document.prototype = document;
1614
+ }
1615
+ }
1616
+
1617
+
1618
+ })
1619
+ .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
1620
+
1621
+ (function(undefined) {
1622
+
1623
+ // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Element/detect.js
1624
+ var detect = ('Element' in this && 'HTMLElement' in this);
1625
+
1626
+ if (detect) return
1627
+
1628
+ // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Element&flags=always
1629
+ (function () {
1630
+
1631
+ // IE8
1632
+ if (window.Element && !window.HTMLElement) {
1633
+ window.HTMLElement = window.Element;
1634
+ return;
1635
+ }
1636
+
1637
+ // create Element constructor
1638
+ window.Element = window.HTMLElement = new Function('return function Element() {}')();
1639
+
1640
+ // generate sandboxed iframe
1641
+ var vbody = document.appendChild(document.createElement('body'));
1642
+ var frame = vbody.appendChild(document.createElement('iframe'));
1643
+
1644
+ // use sandboxed iframe to replicate Element functionality
1645
+ var frameDocument = frame.contentWindow.document;
1646
+ var prototype = Element.prototype = frameDocument.appendChild(frameDocument.createElement('*'));
1647
+ var cache = {};
1648
+
1649
+ // polyfill Element.prototype on an element
1650
+ var shiv = function (element, deep) {
1651
+ var
1652
+ childNodes = element.childNodes || [],
1653
+ index = -1,
1654
+ key, value, childNode;
1655
+
1656
+ if (element.nodeType === 1 && element.constructor !== Element) {
1657
+ element.constructor = Element;
1658
+
1659
+ for (key in cache) {
1660
+ value = cache[key];
1661
+ element[key] = value;
1662
+ }
1663
+ }
1664
+
1665
+ while (childNode = deep && childNodes[++index]) {
1666
+ shiv(childNode, deep);
1667
+ }
1668
+
1669
+ return element;
1670
+ };
1671
+
1672
+ var elements = document.getElementsByTagName('*');
1673
+ var nativeCreateElement = document.createElement;
1674
+ var interval;
1675
+ var loopLimit = 100;
1676
+
1677
+ prototype.attachEvent('onpropertychange', function (event) {
1678
+ var
1679
+ propertyName = event.propertyName,
1680
+ nonValue = !cache.hasOwnProperty(propertyName),
1681
+ newValue = prototype[propertyName],
1682
+ oldValue = cache[propertyName],
1683
+ index = -1,
1684
+ element;
1685
+
1686
+ while (element = elements[++index]) {
1687
+ if (element.nodeType === 1) {
1688
+ if (nonValue || element[propertyName] === oldValue) {
1689
+ element[propertyName] = newValue;
1690
+ }
1691
+ }
1692
+ }
1693
+
1694
+ cache[propertyName] = newValue;
1695
+ });
1696
+
1697
+ prototype.constructor = Element;
1698
+
1699
+ if (!prototype.hasAttribute) {
1700
+ // <Element>.hasAttribute
1701
+ prototype.hasAttribute = function hasAttribute(name) {
1702
+ return this.getAttribute(name) !== null;
1703
+ };
1704
+ }
1705
+
1706
+ // Apply Element prototype to the pre-existing DOM as soon as the body element appears.
1707
+ function bodyCheck() {
1708
+ if (!(loopLimit--)) clearTimeout(interval);
1709
+ if (document.body && !document.body.prototype && /(complete|interactive)/.test(document.readyState)) {
1710
+ shiv(document, true);
1711
+ if (interval && document.body.prototype) clearTimeout(interval);
1712
+ return (!!document.body.prototype);
1713
+ }
1714
+ return false;
1715
+ }
1716
+ if (!bodyCheck()) {
1717
+ document.onreadystatechange = bodyCheck;
1718
+ interval = setInterval(bodyCheck, 25);
1719
+ }
1720
+
1721
+ // Apply to any new elements created after load
1722
+ document.createElement = function createElement(nodeName) {
1723
+ var element = nativeCreateElement(String(nodeName).toLowerCase());
1724
+ return shiv(element);
1725
+ };
1726
+
1727
+ // remove sandboxed iframe
1728
+ document.removeChild(vbody);
1729
+ }());
1730
+
1731
+ })
1732
+ .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
1733
+
1734
+ (function(undefined) {
1735
+
1736
+ // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-service/8717a9e04ac7aff99b4980fbedead98036b0929a/packages/polyfill-library/polyfills/Element/prototype/classList/detect.js
1737
+ var detect = (
1738
+ 'document' in this && "classList" in document.documentElement && 'Element' in this && 'classList' in Element.prototype && (function () {
1739
+ var e = document.createElement('span');
1740
+ e.classList.add('a', 'b');
1741
+ return e.classList.contains('b');
1742
+ }())
1743
+ );
1744
+
1745
+ if (detect) return
1746
+
1747
+ // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Element.prototype.classList&flags=always
1748
+ (function (global) {
1749
+ var dpSupport = true;
1750
+ var defineGetter = function (object, name, fn, configurable) {
1751
+ if (Object.defineProperty)
1752
+ Object.defineProperty(object, name, {
1753
+ configurable: false === dpSupport ? true : !!configurable,
1754
+ get: fn
1755
+ });
1756
+
1757
+ else object.__defineGetter__(name, fn);
1758
+ };
1759
+ /** Ensure the browser allows Object.defineProperty to be used on native JavaScript objects. */
1760
+ try {
1761
+ defineGetter({}, "support");
1762
+ }
1763
+ catch (e) {
1764
+ dpSupport = false;
1765
+ }
1766
+ /** Polyfills a property with a DOMTokenList */
1767
+ var addProp = function (o, name, attr) {
1768
+
1769
+ defineGetter(o.prototype, name, function () {
1770
+ var tokenList;
1771
+
1772
+ var THIS = this,
1773
+
1774
+ /** Prevent this from firing twice for some reason. What the hell, IE. */
1775
+ gibberishProperty = "__defineGetter__" + "DEFINE_PROPERTY" + name;
1776
+ if(THIS[gibberishProperty]) return tokenList;
1777
+ THIS[gibberishProperty] = true;
1778
+
1779
+ /**
1780
+ * IE8 can't define properties on native JavaScript objects, so we'll use a dumb hack instead.
1781
+ *
1782
+ * What this is doing is creating a dummy element ("reflection") inside a detached phantom node ("mirror")
1783
+ * that serves as the target of Object.defineProperty instead. While we could simply use the subject HTML
1784
+ * element instead, this would conflict with element types which use indexed properties (such as forms and
1785
+ * select lists).
1786
+ */
1787
+ if (false === dpSupport) {
1788
+
1789
+ var visage;
1790
+ var mirror = addProp.mirror || document.createElement("div");
1791
+ var reflections = mirror.childNodes;
1792
+ var l = reflections.length;
1793
+
1794
+ for (var i = 0; i < l; ++i)
1795
+ if (reflections[i]._R === THIS) {
1796
+ visage = reflections[i];
1797
+ break;
1798
+ }
1799
+
1800
+ /** Couldn't find an element's reflection inside the mirror. Materialise one. */
1801
+ visage || (visage = mirror.appendChild(document.createElement("div")));
1802
+
1803
+ tokenList = DOMTokenList.call(visage, THIS, attr);
1804
+ } else tokenList = new DOMTokenList(THIS, attr);
1805
+
1806
+ defineGetter(THIS, name, function () {
1807
+ return tokenList;
1808
+ });
1809
+ delete THIS[gibberishProperty];
1810
+
1811
+ return tokenList;
1812
+ }, true);
1813
+ };
1814
+
1815
+ addProp(global.Element, "classList", "className");
1816
+ addProp(global.HTMLElement, "classList", "className");
1817
+ addProp(global.HTMLLinkElement, "relList", "rel");
1818
+ addProp(global.HTMLAnchorElement, "relList", "rel");
1819
+ addProp(global.HTMLAreaElement, "relList", "rel");
1820
+ }(this));
1821
+
1822
+ }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
1823
+
1824
+ function Accordion ($module) {
1825
+ this.$module = $module;
1826
+ this.moduleId = $module.getAttribute('id');
1827
+ this.$sections = $module.querySelectorAll('.govuk-accordion__section');
1828
+ this.$openAllButton = '';
1829
+ this.browserSupportsSessionStorage = helper.checkForSessionStorage();
1830
+
1831
+ this.controlsClass = 'govuk-accordion__controls';
1832
+ this.openAllClass = 'govuk-accordion__open-all';
1833
+ this.iconClass = 'govuk-accordion__icon';
1834
+
1835
+ this.sectionHeaderClass = 'govuk-accordion__section-header';
1836
+ this.sectionHeaderFocusedClass = 'govuk-accordion__section-header--focused';
1837
+ this.sectionHeadingClass = 'govuk-accordion__section-heading';
1838
+ this.sectionSummaryClass = 'govuk-accordion__section-summary';
1839
+ this.sectionButtonClass = 'govuk-accordion__section-button';
1840
+ this.sectionExpandedClass = 'govuk-accordion__section--expanded';
1841
+ }
1842
+
1843
+ // Initialize component
1844
+ Accordion.prototype.init = function () {
1845
+ // Check for module
1846
+ if (!this.$module) {
1847
+ return
1848
+ }
1849
+
1850
+ this.initControls();
1851
+
1852
+ this.initSectionHeaders();
1853
+
1854
+ // See if "Open all" button text should be updated
1855
+ var areAllSectionsOpen = this.checkIfAllSectionsOpen();
1856
+ this.updateOpenAllButton(areAllSectionsOpen);
1857
+ };
1858
+
1859
+ // Initialise controls and set attributes
1860
+ Accordion.prototype.initControls = function () {
1861
+ // Create "Open all" button and set attributes
1862
+ this.$openAllButton = document.createElement('button');
1863
+ this.$openAllButton.setAttribute('type', 'button');
1864
+ this.$openAllButton.innerHTML = 'Open all <span class="govuk-visually-hidden">sections</span>';
1865
+ this.$openAllButton.setAttribute('class', this.openAllClass);
1866
+ this.$openAllButton.setAttribute('aria-expanded', 'false');
1867
+ this.$openAllButton.setAttribute('type', 'button');
1868
+
1869
+ // Create control wrapper and add controls to it
1870
+ var accordionControls = document.createElement('div');
1871
+ accordionControls.setAttribute('class', this.controlsClass);
1872
+ accordionControls.appendChild(this.$openAllButton);
1873
+ this.$module.insertBefore(accordionControls, this.$module.firstChild);
1874
+
1875
+ // Handle events for the controls
1876
+ this.$openAllButton.addEventListener('click', this.onOpenOrCloseAllToggle.bind(this));
1877
+ };
1878
+
1879
+ // Initialise section headers
1880
+ Accordion.prototype.initSectionHeaders = function () {
1881
+ // Loop through section headers
1882
+ nodeListForEach(this.$sections, function ($section, i) {
1883
+ // Set header attributes
1884
+ var header = $section.querySelector('.' + this.sectionHeaderClass);
1885
+ this.initHeaderAttributes(header, i);
1886
+
1887
+ this.setExpanded(this.isExpanded($section), $section);
1888
+
1889
+ // Handle events
1890
+ header.addEventListener('click', this.onSectionToggle.bind(this, $section));
1891
+
1892
+ // See if there is any state stored in sessionStorage and set the sections to
1893
+ // open or closed.
1894
+ this.setInitialState($section);
1895
+ }.bind(this));
1896
+ };
1897
+
1898
+ // Set individual header attributes
1899
+ Accordion.prototype.initHeaderAttributes = function ($headerWrapper, index) {
1900
+ var $module = this;
1901
+ var $span = $headerWrapper.querySelector('.' + this.sectionButtonClass);
1902
+ var $heading = $headerWrapper.querySelector('.' + this.sectionHeadingClass);
1903
+ var $summary = $headerWrapper.querySelector('.' + this.sectionSummaryClass);
1904
+
1905
+ // Copy existing span element to an actual button element, for improved accessibility.
1906
+ var $button = document.createElement('button');
1907
+ $button.setAttribute('type', 'button');
1908
+ $button.setAttribute('id', this.moduleId + '-heading-' + (index + 1));
1909
+ $button.setAttribute('aria-controls', this.moduleId + '-content-' + (index + 1));
1910
+
1911
+ // Copy all attributes (https://developer.mozilla.org/en-US/docs/Web/API/Element/attributes) from $span to $button
1912
+ for (var i = 0; i < $span.attributes.length; i++) {
1913
+ var attr = $span.attributes.item(i);
1914
+ $button.setAttribute(attr.nodeName, attr.nodeValue);
1915
+ }
1916
+
1917
+ $button.addEventListener('focusin', function (e) {
1918
+ if (!$headerWrapper.classList.contains($module.sectionHeaderFocusedClass)) {
1919
+ $headerWrapper.className += ' ' + $module.sectionHeaderFocusedClass;
1920
+ }
1921
+ });
1922
+
1923
+ $button.addEventListener('blur', function (e) {
1924
+ $headerWrapper.classList.remove($module.sectionHeaderFocusedClass);
1925
+ });
1926
+
1927
+ if (typeof ($summary) !== 'undefined' && $summary !== null) {
1928
+ $button.setAttribute('aria-describedby', this.moduleId + '-summary-' + (index + 1));
1929
+ }
1930
+
1931
+ // $span could contain HTML elements (see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content)
1932
+ $button.innerHTML = $span.innerHTML;
1933
+
1934
+ $heading.removeChild($span);
1935
+ $heading.appendChild($button);
1936
+
1937
+ // Add "+/-" icon
1938
+ var icon = document.createElement('span');
1939
+ icon.className = this.iconClass;
1940
+ icon.setAttribute('aria-hidden', 'true');
1941
+
1942
+ $button.appendChild(icon);
1943
+ };
1944
+
1945
+ // When section toggled, set and store state
1946
+ Accordion.prototype.onSectionToggle = function ($section) {
1947
+ var expanded = this.isExpanded($section);
1948
+ this.setExpanded(!expanded, $section);
1949
+
1950
+ // Store the state in sessionStorage when a change is triggered
1951
+ this.storeState($section);
1952
+ };
1953
+
1954
+ // When Open/Close All toggled, set and store state
1955
+ Accordion.prototype.onOpenOrCloseAllToggle = function () {
1956
+ var $module = this;
1957
+ var $sections = this.$sections;
1958
+
1959
+ var nowExpanded = !this.checkIfAllSectionsOpen();
1960
+
1961
+ nodeListForEach($sections, function ($section) {
1962
+ $module.setExpanded(nowExpanded, $section);
1963
+ // Store the state in sessionStorage when a change is triggered
1964
+ $module.storeState($section);
1965
+ });
1966
+
1967
+ $module.updateOpenAllButton(nowExpanded);
1968
+ };
1969
+
1970
+ // Set section attributes when opened/closed
1971
+ Accordion.prototype.setExpanded = function (expanded, $section) {
1972
+ var $button = $section.querySelector('.' + this.sectionButtonClass);
1973
+ $button.setAttribute('aria-expanded', expanded);
1974
+
1975
+ if (expanded) {
1976
+ $section.classList.add(this.sectionExpandedClass);
1977
+ } else {
1978
+ $section.classList.remove(this.sectionExpandedClass);
1979
+ }
1980
+
1981
+ // See if "Open all" button text should be updated
1982
+ var areAllSectionsOpen = this.checkIfAllSectionsOpen();
1983
+ this.updateOpenAllButton(areAllSectionsOpen);
1984
+ };
1985
+
1986
+ // Get state of section
1987
+ Accordion.prototype.isExpanded = function ($section) {
1988
+ return $section.classList.contains(this.sectionExpandedClass)
1989
+ };
1990
+
1991
+ // Check if all sections are open
1992
+ Accordion.prototype.checkIfAllSectionsOpen = function () {
1993
+ // Get a count of all the Accordion sections
1994
+ var sectionsCount = this.$sections.length;
1995
+ // Get a count of all Accordion sections that are expanded
1996
+ var expandedSectionCount = this.$module.querySelectorAll('.' + this.sectionExpandedClass).length;
1997
+ var areAllSectionsOpen = sectionsCount === expandedSectionCount;
1998
+
1999
+ return areAllSectionsOpen
2000
+ };
2001
+
2002
+ // Update "Open all" button
2003
+ Accordion.prototype.updateOpenAllButton = function (expanded) {
2004
+ var newButtonText = expanded ? 'Close all' : 'Open all';
2005
+ newButtonText += '<span class="govuk-visually-hidden"> sections</span>';
2006
+ this.$openAllButton.setAttribute('aria-expanded', expanded);
2007
+ this.$openAllButton.innerHTML = newButtonText;
2008
+ };
2009
+
2010
+ // Check for `window.sessionStorage`, and that it actually works.
2011
+ var helper = {
2012
+ checkForSessionStorage: function () {
2013
+ var testString = 'this is the test string';
2014
+ var result;
2015
+ try {
2016
+ window.sessionStorage.setItem(testString, testString);
2017
+ result = window.sessionStorage.getItem(testString) === testString.toString();
2018
+ window.sessionStorage.removeItem(testString);
2019
+ return result
2020
+ } catch (exception) {
2021
+ if ((typeof console === 'undefined' || typeof console.log === 'undefined')) {
2022
+ console.log('Notice: sessionStorage not available.');
2023
+ }
2024
+ }
2025
+ }
2026
+ };
2027
+
2028
+ // Set the state of the accordions in sessionStorage
2029
+ Accordion.prototype.storeState = function ($section) {
2030
+ if (this.browserSupportsSessionStorage) {
2031
+ // We need a unique way of identifying each content in the accordion. Since
2032
+ // an `#id` should be unique and an `id` is required for `aria-` attributes
2033
+ // `id` can be safely used.
2034
+ var $button = $section.querySelector('.' + this.sectionButtonClass);
2035
+
2036
+ if ($button) {
2037
+ var contentId = $button.getAttribute('aria-controls');
2038
+ var contentState = $button.getAttribute('aria-expanded');
2039
+
2040
+ if (typeof contentId === 'undefined' && (typeof console === 'undefined' || typeof console.log === 'undefined')) {
2041
+ console.error(new Error('No aria controls present in accordion section heading.'));
2042
+ }
2043
+
2044
+ if (typeof contentState === 'undefined' && (typeof console === 'undefined' || typeof console.log === 'undefined')) {
2045
+ console.error(new Error('No aria expanded present in accordion section heading.'));
2046
+ }
2047
+
2048
+ // Only set the state when both `contentId` and `contentState` are taken from the DOM.
2049
+ if (contentId && contentState) {
2050
+ window.sessionStorage.setItem(contentId, contentState);
2051
+ }
2052
+ }
2053
+ }
2054
+ };
2055
+
2056
+ // Read the state of the accordions from sessionStorage
2057
+ Accordion.prototype.setInitialState = function ($section) {
2058
+ if (this.browserSupportsSessionStorage) {
2059
+ var $button = $section.querySelector('.' + this.sectionButtonClass);
2060
+
2061
+ if ($button) {
2062
+ var contentId = $button.getAttribute('aria-controls');
2063
+ var contentState = contentId ? window.sessionStorage.getItem(contentId) : null;
2064
+
2065
+ if (contentState !== null) {
2066
+ this.setExpanded(contentState === 'true', $section);
2067
+ }
2068
+ }
2069
+ }
2070
+ };
2071
+
2072
+ (function(undefined) {
2073
+
2074
+ // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Window/detect.js
2075
+ var detect = ('Window' in this);
2076
+
2077
+ if (detect) return
2078
+
2079
+ // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Window&flags=always
2080
+ if ((typeof WorkerGlobalScope === "undefined") && (typeof importScripts !== "function")) {
2081
+ (function (global) {
2082
+ if (global.constructor) {
2083
+ global.Window = global.constructor;
2084
+ } else {
2085
+ (global.Window = global.constructor = new Function('return function Window() {}')()).prototype = this;
2086
+ }
2087
+ }(this));
2088
+ }
2089
+
2090
+ })
2091
+ .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
2092
+
2093
+ (function(undefined) {
2094
+
2095
+ // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Event/detect.js
2096
+ var detect = (
2097
+ (function(global) {
2098
+
2099
+ if (!('Event' in global)) return false;
2100
+ if (typeof global.Event === 'function') return true;
2101
+
2102
+ try {
2103
+
2104
+ // In IE 9-11, the Event object exists but cannot be instantiated
2105
+ new Event('click');
2106
+ return true;
2107
+ } catch(e) {
2108
+ return false;
2109
+ }
2110
+ }(this))
2111
+ );
2112
+
2113
+ if (detect) return
2114
+
2115
+ // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Event&flags=always
2116
+ (function () {
2117
+ var unlistenableWindowEvents = {
2118
+ click: 1,
2119
+ dblclick: 1,
2120
+ keyup: 1,
2121
+ keypress: 1,
2122
+ keydown: 1,
2123
+ mousedown: 1,
2124
+ mouseup: 1,
2125
+ mousemove: 1,
2126
+ mouseover: 1,
2127
+ mouseenter: 1,
2128
+ mouseleave: 1,
2129
+ mouseout: 1,
2130
+ storage: 1,
2131
+ storagecommit: 1,
2132
+ textinput: 1
2133
+ };
2134
+
2135
+ // This polyfill depends on availability of `document` so will not run in a worker
2136
+ // However, we asssume there are no browsers with worker support that lack proper
2137
+ // support for `Event` within the worker
2138
+ if (typeof document === 'undefined' || typeof window === 'undefined') return;
2139
+
2140
+ function indexOf(array, element) {
2141
+ var
2142
+ index = -1,
2143
+ length = array.length;
2144
+
2145
+ while (++index < length) {
2146
+ if (index in array && array[index] === element) {
2147
+ return index;
2148
+ }
2149
+ }
2150
+
2151
+ return -1;
2152
+ }
2153
+
2154
+ var existingProto = (window.Event && window.Event.prototype) || null;
2155
+ window.Event = Window.prototype.Event = function Event(type, eventInitDict) {
2156
+ if (!type) {
2157
+ throw new Error('Not enough arguments');
2158
+ }
2159
+
2160
+ var event;
2161
+ // Shortcut if browser supports createEvent
2162
+ if ('createEvent' in document) {
2163
+ event = document.createEvent('Event');
2164
+ var bubbles = eventInitDict && eventInitDict.bubbles !== undefined ? eventInitDict.bubbles : false;
2165
+ var cancelable = eventInitDict && eventInitDict.cancelable !== undefined ? eventInitDict.cancelable : false;
2166
+
2167
+ event.initEvent(type, bubbles, cancelable);
2168
+
2169
+ return event;
2170
+ }
2171
+
2172
+ event = document.createEventObject();
2173
+
2174
+ event.type = type;
2175
+ event.bubbles = eventInitDict && eventInitDict.bubbles !== undefined ? eventInitDict.bubbles : false;
2176
+ event.cancelable = eventInitDict && eventInitDict.cancelable !== undefined ? eventInitDict.cancelable : false;
2177
+
2178
+ return event;
2179
+ };
2180
+ if (existingProto) {
2181
+ Object.defineProperty(window.Event, 'prototype', {
2182
+ configurable: false,
2183
+ enumerable: false,
2184
+ writable: true,
2185
+ value: existingProto
2186
+ });
2187
+ }
2188
+
2189
+ if (!('createEvent' in document)) {
2190
+ window.addEventListener = Window.prototype.addEventListener = Document.prototype.addEventListener = Element.prototype.addEventListener = function addEventListener() {
2191
+ var
2192
+ element = this,
2193
+ type = arguments[0],
2194
+ listener = arguments[1];
2195
+
2196
+ if (element === window && type in unlistenableWindowEvents) {
2197
+ 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.');
2198
+ }
2199
+
2200
+ if (!element._events) {
2201
+ element._events = {};
2202
+ }
2203
+
2204
+ if (!element._events[type]) {
2205
+ element._events[type] = function (event) {
2206
+ var
2207
+ list = element._events[event.type].list,
2208
+ events = list.slice(),
2209
+ index = -1,
2210
+ length = events.length,
2211
+ eventElement;
2212
+
2213
+ event.preventDefault = function preventDefault() {
2214
+ if (event.cancelable !== false) {
2215
+ event.returnValue = false;
2216
+ }
2217
+ };
2218
+
2219
+ event.stopPropagation = function stopPropagation() {
2220
+ event.cancelBubble = true;
2221
+ };
2222
+
2223
+ event.stopImmediatePropagation = function stopImmediatePropagation() {
2224
+ event.cancelBubble = true;
2225
+ event.cancelImmediate = true;
2226
+ };
2227
+
2228
+ event.currentTarget = element;
2229
+ event.relatedTarget = event.fromElement || null;
2230
+ event.target = event.target || event.srcElement || element;
2231
+ event.timeStamp = new Date().getTime();
2232
+
2233
+ if (event.clientX) {
2234
+ event.pageX = event.clientX + document.documentElement.scrollLeft;
2235
+ event.pageY = event.clientY + document.documentElement.scrollTop;
2236
+ }
2237
+
2238
+ while (++index < length && !event.cancelImmediate) {
2239
+ if (index in events) {
2240
+ eventElement = events[index];
2241
+
2242
+ if (indexOf(list, eventElement) !== -1 && typeof eventElement === 'function') {
2243
+ eventElement.call(element, event);
2244
+ }
2245
+ }
2246
+ }
2247
+ };
2248
+
2249
+ element._events[type].list = [];
2250
+
2251
+ if (element.attachEvent) {
2252
+ element.attachEvent('on' + type, element._events[type]);
2253
+ }
2254
+ }
2255
+
2256
+ element._events[type].list.push(listener);
2257
+ };
2258
+
2259
+ window.removeEventListener = Window.prototype.removeEventListener = Document.prototype.removeEventListener = Element.prototype.removeEventListener = function removeEventListener() {
2260
+ var
2261
+ element = this,
2262
+ type = arguments[0],
2263
+ listener = arguments[1],
2264
+ index;
2265
+
2266
+ if (element._events && element._events[type] && element._events[type].list) {
2267
+ index = indexOf(element._events[type].list, listener);
2268
+
2269
+ if (index !== -1) {
2270
+ element._events[type].list.splice(index, 1);
2271
+
2272
+ if (!element._events[type].list.length) {
2273
+ if (element.detachEvent) {
2274
+ element.detachEvent('on' + type, element._events[type]);
2275
+ }
2276
+ delete element._events[type];
2277
+ }
2278
+ }
2279
+ }
2280
+ };
2281
+
2282
+ window.dispatchEvent = Window.prototype.dispatchEvent = Document.prototype.dispatchEvent = Element.prototype.dispatchEvent = function dispatchEvent(event) {
2283
+ if (!arguments.length) {
2284
+ throw new Error('Not enough arguments');
2285
+ }
2286
+
2287
+ if (!event || typeof event.type !== 'string') {
2288
+ throw new Error('DOM Events Exception 0');
2289
+ }
2290
+
2291
+ var element = this, type = event.type;
2292
+
2293
+ try {
2294
+ if (!event.bubbles) {
2295
+ event.cancelBubble = true;
2296
+
2297
+ var cancelBubbleEvent = function (event) {
2298
+ event.cancelBubble = true;
2299
+
2300
+ (element || window).detachEvent('on' + type, cancelBubbleEvent);
2301
+ };
2302
+
2303
+ this.attachEvent('on' + type, cancelBubbleEvent);
2304
+ }
2305
+
2306
+ this.fireEvent('on' + type, event);
2307
+ } catch (error) {
2308
+ event.target = element;
2309
+
2310
+ do {
2311
+ event.currentTarget = element;
2312
+
2313
+ if ('_events' in element && typeof element._events[type] === 'function') {
2314
+ element._events[type].call(element, event);
2315
+ }
2316
+
2317
+ if (typeof element['on' + type] === 'function') {
2318
+ element['on' + type].call(element, event);
2319
+ }
2320
+
2321
+ element = element.nodeType === 9 ? element.parentWindow : element.parentNode;
2322
+ } while (element && !event.cancelBubble);
2323
+ }
2324
+
2325
+ return true;
2326
+ };
2327
+
2328
+ // Add the DOMContentLoaded Event
2329
+ document.attachEvent('onreadystatechange', function() {
2330
+ if (document.readyState === 'complete') {
2331
+ document.dispatchEvent(new Event('DOMContentLoaded', {
2332
+ bubbles: true
2333
+ }));
2334
+ }
2335
+ });
2336
+ }
2337
+ }());
2338
+
2339
+ })
2340
+ .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
2341
+
2342
+ var KEY_SPACE = 32;
2343
+ var DEBOUNCE_TIMEOUT_IN_SECONDS = 1;
2344
+
2345
+ function Button ($module) {
2346
+ this.$module = $module;
2347
+ this.debounceFormSubmitTimer = null;
2348
+ }
2349
+
2350
+ /**
2351
+ * JavaScript 'shim' to trigger the click event of element(s) when the space key is pressed.
2352
+ *
2353
+ * Created since some Assistive Technologies (for example some Screenreaders)
2354
+ * will tell a user to press space on a 'button', so this functionality needs to be shimmed
2355
+ * See https://github.com/alphagov/govuk_elements/pull/272#issuecomment-233028270
2356
+ *
2357
+ * @param {object} event event
2358
+ */
2359
+ Button.prototype.handleKeyDown = function (event) {
2360
+ // get the target element
2361
+ var target = event.target;
2362
+ // if the element has a role='button' and the pressed key is a space, we'll simulate a click
2363
+ if (target.getAttribute('role') === 'button' && event.keyCode === KEY_SPACE) {
2364
+ event.preventDefault();
2365
+ // trigger the target's click event
2366
+ target.click();
2367
+ }
2368
+ };
2369
+
2370
+ /**
2371
+ * If the click quickly succeeds a previous click then nothing will happen.
2372
+ * This stops people accidentally causing multiple form submissions by
2373
+ * double clicking buttons.
2374
+ */
2375
+ Button.prototype.debounce = function (event) {
2376
+ var target = event.target;
2377
+ // Check the button that is clicked on has the preventDoubleClick feature enabled
2378
+ if (target.getAttribute('data-prevent-double-click') !== 'true') {
2379
+ return
2380
+ }
2381
+
2382
+ // If the timer is still running then we want to prevent the click from submitting the form
2383
+ if (this.debounceFormSubmitTimer) {
2384
+ event.preventDefault();
2385
+ return false
2386
+ }
2387
+
2388
+ this.debounceFormSubmitTimer = setTimeout(function () {
2389
+ this.debounceFormSubmitTimer = null;
2390
+ }.bind(this), DEBOUNCE_TIMEOUT_IN_SECONDS * 1000);
2391
+ };
2392
+
2393
+ /**
2394
+ * Initialise an event listener for keydown at document level
2395
+ * this will help listening for later inserted elements with a role="button"
2396
+ */
2397
+ Button.prototype.init = function () {
2398
+ this.$module.addEventListener('keydown', this.handleKeyDown);
2399
+ this.$module.addEventListener('click', this.debounce);
2400
+ };
2401
+
2402
+ /**
2403
+ * JavaScript 'polyfill' for HTML5's <details> and <summary> elements
2404
+ * and 'shim' to add accessiblity enhancements for all browsers
2405
+ *
2406
+ * http://caniuse.com/#feat=details
2407
+ */
2408
+
2409
+ var KEY_ENTER = 13;
2410
+ var KEY_SPACE$1 = 32;
2411
+
2412
+ function Details ($module) {
2413
+ this.$module = $module;
2414
+ }
2415
+
2416
+ Details.prototype.init = function () {
2417
+ if (!this.$module) {
2418
+ return
2419
+ }
2420
+
2421
+ // If there is native details support, we want to avoid running code to polyfill native behaviour.
2422
+ var hasNativeDetails = typeof this.$module.open === 'boolean';
2423
+
2424
+ if (hasNativeDetails) {
2425
+ return
2426
+ }
2427
+
2428
+ this.polyfillDetails();
2429
+ };
2430
+
2431
+ Details.prototype.polyfillDetails = function () {
2432
+ var $module = this.$module;
2433
+
2434
+ // Save shortcuts to the inner summary and content elements
2435
+ var $summary = this.$summary = $module.getElementsByTagName('summary').item(0);
2436
+ var $content = this.$content = $module.getElementsByTagName('div').item(0);
2437
+
2438
+ // If <details> doesn't have a <summary> and a <div> representing the content
2439
+ // it means the required HTML structure is not met so the script will stop
2440
+ if (!$summary || !$content) {
2441
+ return
2442
+ }
2443
+
2444
+ // If the content doesn't have an ID, assign it one now
2445
+ // which we'll need for the summary's aria-controls assignment
2446
+ if (!$content.id) {
2447
+ $content.id = 'details-content-' + generateUniqueID();
2448
+ }
2449
+
2450
+ // Add ARIA role="group" to details
2451
+ $module.setAttribute('role', 'group');
2452
+
2453
+ // Add role=button to summary
2454
+ $summary.setAttribute('role', 'button');
2455
+
2456
+ // Add aria-controls
2457
+ $summary.setAttribute('aria-controls', $content.id);
2458
+
2459
+ // Set tabIndex so the summary is keyboard accessible for non-native elements
2460
+ //
2461
+ // We have to use the camelcase `tabIndex` property as there is a bug in IE6/IE7 when we set the correct attribute lowercase:
2462
+ // See http://web.archive.org/web/20170120194036/http://www.saliences.com/browserBugs/tabIndex.html for more information.
2463
+ $summary.tabIndex = 0;
2464
+
2465
+ // Detect initial open state
2466
+ var openAttr = $module.getAttribute('open') !== null;
2467
+ if (openAttr === true) {
2468
+ $summary.setAttribute('aria-expanded', 'true');
2469
+ $content.setAttribute('aria-hidden', 'false');
2470
+ } else {
2471
+ $summary.setAttribute('aria-expanded', 'false');
2472
+ $content.setAttribute('aria-hidden', 'true');
2473
+ $content.style.display = 'none';
2474
+ }
2475
+
2476
+ // Bind an event to handle summary elements
2477
+ this.polyfillHandleInputs($summary, this.polyfillSetAttributes.bind(this));
2478
+ };
2479
+
2480
+ /**
2481
+ * Define a statechange function that updates aria-expanded and style.display
2482
+ * @param {object} summary element
2483
+ */
2484
+ Details.prototype.polyfillSetAttributes = function () {
2485
+ var $module = this.$module;
2486
+ var $summary = this.$summary;
2487
+ var $content = this.$content;
2488
+
2489
+ var expanded = $summary.getAttribute('aria-expanded') === 'true';
2490
+ var hidden = $content.getAttribute('aria-hidden') === 'true';
2491
+
2492
+ $summary.setAttribute('aria-expanded', (expanded ? 'false' : 'true'));
2493
+ $content.setAttribute('aria-hidden', (hidden ? 'false' : 'true'));
2494
+
2495
+ $content.style.display = (expanded ? 'none' : '');
2496
+
2497
+ var hasOpenAttr = $module.getAttribute('open') !== null;
2498
+ if (!hasOpenAttr) {
2499
+ $module.setAttribute('open', 'open');
2500
+ } else {
2501
+ $module.removeAttribute('open');
2502
+ }
2503
+
2504
+ return true
2505
+ };
2506
+
2507
+ /**
2508
+ * Handle cross-modal click events
2509
+ * @param {object} node element
2510
+ * @param {function} callback function
2511
+ */
2512
+ Details.prototype.polyfillHandleInputs = function (node, callback) {
2513
+ node.addEventListener('keypress', function (event) {
2514
+ var target = event.target;
2515
+ // When the key gets pressed - check if it is enter or space
2516
+ if (event.keyCode === KEY_ENTER || event.keyCode === KEY_SPACE$1) {
2517
+ if (target.nodeName.toLowerCase() === 'summary') {
2518
+ // Prevent space from scrolling the page
2519
+ // and enter from submitting a form
2520
+ event.preventDefault();
2521
+ // Click to let the click event do all the necessary action
2522
+ if (target.click) {
2523
+ target.click();
2524
+ } else {
2525
+ // except Safari 5.1 and under don't support .click() here
2526
+ callback(event);
2527
+ }
2528
+ }
2529
+ }
2530
+ });
2531
+
2532
+ // Prevent keyup to prevent clicking twice in Firefox when using space key
2533
+ node.addEventListener('keyup', function (event) {
2534
+ var target = event.target;
2535
+ if (event.keyCode === KEY_SPACE$1) {
2536
+ if (target.nodeName.toLowerCase() === 'summary') {
2537
+ event.preventDefault();
2538
+ }
2539
+ }
2540
+ });
2541
+
2542
+ node.addEventListener('click', callback);
2543
+ };
2544
+
2545
+ function CharacterCount ($module) {
2546
+ this.$module = $module;
2547
+ this.$textarea = $module.querySelector('.govuk-js-character-count');
2548
+ if (this.$textarea) {
2549
+ this.$countMessage = $module.querySelector('[id="' + this.$textarea.id + '-info"]');
2550
+ }
2551
+ }
2552
+
2553
+ CharacterCount.prototype.defaults = {
2554
+ characterCountAttribute: 'data-maxlength',
2555
+ wordCountAttribute: 'data-maxwords'
2556
+ };
2557
+
2558
+ // Initialize component
2559
+ CharacterCount.prototype.init = function () {
2560
+ // Check for module
2561
+ var $module = this.$module;
2562
+ var $textarea = this.$textarea;
2563
+ var $countMessage = this.$countMessage;
2564
+
2565
+ if (!$textarea || !$countMessage) {
2566
+ return
2567
+ }
2568
+
2569
+ // We move count message right after the field
2570
+ // Kept for backwards compatibility
2571
+ $textarea.insertAdjacentElement('afterend', $countMessage);
2572
+
2573
+ // Read options set using dataset ('data-' values)
2574
+ this.options = this.getDataset($module);
2575
+
2576
+ // Determine the limit attribute (characters or words)
2577
+ var countAttribute = this.defaults.characterCountAttribute;
2578
+ if (this.options.maxwords) {
2579
+ countAttribute = this.defaults.wordCountAttribute;
2580
+ }
2581
+
2582
+ // Save the element limit
2583
+ this.maxLength = $module.getAttribute(countAttribute);
2584
+
2585
+ // Check for limit
2586
+ if (!this.maxLength) {
2587
+ return
2588
+ }
2589
+
2590
+ // Remove hard limit if set
2591
+ $module.removeAttribute('maxlength');
2592
+
2593
+ // When the page is restored after navigating 'back' in some browsers the
2594
+ // state of the character count is not restored until *after* the DOMContentLoaded
2595
+ // event is fired, so we need to sync after the pageshow event in browsers
2596
+ // that support it.
2597
+ if ('onpageshow' in window) {
2598
+ window.addEventListener('pageshow', this.sync.bind(this));
2599
+ } else {
2600
+ window.addEventListener('DOMContentLoaded', this.sync.bind(this));
2601
+ }
2602
+
2603
+ this.sync();
2604
+ };
2605
+
2606
+ CharacterCount.prototype.sync = function () {
2607
+ this.bindChangeEvents();
2608
+ this.updateCountMessage();
2609
+ };
2610
+
2611
+ // Read data attributes
2612
+ CharacterCount.prototype.getDataset = function (element) {
2613
+ var dataset = {};
2614
+ var attributes = element.attributes;
2615
+ if (attributes) {
2616
+ for (var i = 0; i < attributes.length; i++) {
2617
+ var attribute = attributes[i];
2618
+ var match = attribute.name.match(/^data-(.+)/);
2619
+ if (match) {
2620
+ dataset[match[1]] = attribute.value;
2621
+ }
2622
+ }
2623
+ }
2624
+ return dataset
2625
+ };
2626
+
2627
+ // Counts characters or words in text
2628
+ CharacterCount.prototype.count = function (text) {
2629
+ var length;
2630
+ if (this.options.maxwords) {
2631
+ var tokens = text.match(/\S+/g) || []; // Matches consecutive non-whitespace chars
2632
+ length = tokens.length;
2633
+ } else {
2634
+ length = text.length;
2635
+ }
2636
+ return length
2637
+ };
2638
+
2639
+ // Bind input propertychange to the elements and update based on the change
2640
+ CharacterCount.prototype.bindChangeEvents = function () {
2641
+ var $textarea = this.$textarea;
2642
+ $textarea.addEventListener('keyup', this.checkIfValueChanged.bind(this));
2643
+
2644
+ // Bind focus/blur events to start/stop polling
2645
+ $textarea.addEventListener('focus', this.handleFocus.bind(this));
2646
+ $textarea.addEventListener('blur', this.handleBlur.bind(this));
2647
+ };
2648
+
2649
+ // Speech recognition software such as Dragon NaturallySpeaking will modify the
2650
+ // fields by directly changing its `value`. These changes don't trigger events
2651
+ // in JavaScript, so we need to poll to handle when and if they occur.
2652
+ CharacterCount.prototype.checkIfValueChanged = function () {
2653
+ if (!this.$textarea.oldValue) this.$textarea.oldValue = '';
2654
+ if (this.$textarea.value !== this.$textarea.oldValue) {
2655
+ this.$textarea.oldValue = this.$textarea.value;
2656
+ this.updateCountMessage();
2657
+ }
2658
+ };
2659
+
2660
+ // Update message box
2661
+ CharacterCount.prototype.updateCountMessage = function () {
2662
+ var countElement = this.$textarea;
2663
+ var options = this.options;
2664
+ var countMessage = this.$countMessage;
2665
+
2666
+ // Determine the remaining number of characters/words
2667
+ var currentLength = this.count(countElement.value);
2668
+ var maxLength = this.maxLength;
2669
+ var remainingNumber = maxLength - currentLength;
2670
+
2671
+ // Set threshold if presented in options
2672
+ var thresholdPercent = options.threshold ? options.threshold : 0;
2673
+ var thresholdValue = maxLength * thresholdPercent / 100;
2674
+ if (thresholdValue > currentLength) {
2675
+ countMessage.classList.add('govuk-character-count__message--disabled');
2676
+ // Ensure threshold is hidden for users of assistive technologies
2677
+ countMessage.setAttribute('aria-hidden', true);
2678
+ } else {
2679
+ countMessage.classList.remove('govuk-character-count__message--disabled');
2680
+ // Ensure threshold is visible for users of assistive technologies
2681
+ countMessage.removeAttribute('aria-hidden');
2682
+ }
2683
+
2684
+ // Update styles
2685
+ if (remainingNumber < 0) {
2686
+ countElement.classList.add('govuk-textarea--error');
2687
+ countMessage.classList.remove('govuk-hint');
2688
+ countMessage.classList.add('govuk-error-message');
2689
+ } else {
2690
+ countElement.classList.remove('govuk-textarea--error');
2691
+ countMessage.classList.remove('govuk-error-message');
2692
+ countMessage.classList.add('govuk-hint');
2693
+ }
2694
+
2695
+ // Update message
2696
+ var charVerb = 'remaining';
2697
+ var charNoun = 'character';
2698
+ var displayNumber = remainingNumber;
2699
+ if (options.maxwords) {
2700
+ charNoun = 'word';
2701
+ }
2702
+ charNoun = charNoun + ((remainingNumber === -1 || remainingNumber === 1) ? '' : 's');
2703
+
2704
+ charVerb = (remainingNumber < 0) ? 'too many' : 'remaining';
2705
+ displayNumber = Math.abs(remainingNumber);
2706
+
2707
+ countMessage.innerHTML = 'You have ' + displayNumber + ' ' + charNoun + ' ' + charVerb;
2708
+ };
2709
+
2710
+ CharacterCount.prototype.handleFocus = function () {
2711
+ // Check if value changed on focus
2712
+ this.valueChecker = setInterval(this.checkIfValueChanged.bind(this), 1000);
2713
+ };
2714
+
2715
+ CharacterCount.prototype.handleBlur = function () {
2716
+ // Cancel value checking on blur
2717
+ clearInterval(this.valueChecker);
2718
+ };
2719
+
2720
+ function Checkboxes ($module) {
2721
+ this.$module = $module;
2722
+ this.$inputs = $module.querySelectorAll('input[type="checkbox"]');
2723
+ }
2724
+
2725
+ /**
2726
+ * Initialise Checkboxes
2727
+ *
2728
+ * Checkboxes can be associated with a 'conditionally revealed' content block –
2729
+ * for example, a checkbox for 'Phone' could reveal an additional form field for
2730
+ * the user to enter their phone number.
2731
+ *
2732
+ * These associations are made using a `data-aria-controls` attribute, which is
2733
+ * promoted to an aria-controls attribute during initialisation.
2734
+ *
2735
+ * We also need to restore the state of any conditional reveals on the page (for
2736
+ * example if the user has navigated back), and set up event handlers to keep
2737
+ * the reveal in sync with the checkbox state.
2738
+ */
2739
+ Checkboxes.prototype.init = function () {
2740
+ var $module = this.$module;
2741
+ var $inputs = this.$inputs;
2742
+
2743
+ nodeListForEach($inputs, function ($input) {
2744
+ var target = $input.getAttribute('data-aria-controls');
2745
+
2746
+ // Skip checkboxes without data-aria-controls attributes, or where the
2747
+ // target element does not exist.
2748
+ if (!target || !$module.querySelector('#' + target)) {
2749
+ return
2750
+ }
2751
+
2752
+ // Promote the data-aria-controls attribute to a aria-controls attribute
2753
+ // so that the relationship is exposed in the AOM
2754
+ $input.setAttribute('aria-controls', target);
2755
+ $input.removeAttribute('data-aria-controls');
2756
+ });
2757
+
2758
+ // When the page is restored after navigating 'back' in some browsers the
2759
+ // state of form controls is not restored until *after* the DOMContentLoaded
2760
+ // event is fired, so we need to sync after the pageshow event in browsers
2761
+ // that support it.
2762
+ if ('onpageshow' in window) {
2763
+ window.addEventListener('pageshow', this.syncAllConditionalReveals.bind(this));
2764
+ } else {
2765
+ window.addEventListener('DOMContentLoaded', this.syncAllConditionalReveals.bind(this));
2766
+ }
2767
+
2768
+ // Although we've set up handlers to sync state on the pageshow or
2769
+ // DOMContentLoaded event, init could be called after those events have fired,
2770
+ // for example if they are added to the page dynamically, so sync now too.
2771
+ this.syncAllConditionalReveals();
2772
+
2773
+ $module.addEventListener('click', this.handleClick.bind(this));
2774
+ };
2775
+
2776
+ /**
2777
+ * Sync the conditional reveal states for all inputs in this $module.
2778
+ */
2779
+ Checkboxes.prototype.syncAllConditionalReveals = function () {
2780
+ nodeListForEach(this.$inputs, this.syncConditionalRevealWithInputState.bind(this));
2781
+ };
2782
+
2783
+ /**
2784
+ * Sync conditional reveal with the input state
2785
+ *
2786
+ * Synchronise the visibility of the conditional reveal, and its accessible
2787
+ * state, with the input's checked state.
2788
+ *
2789
+ * @param {HTMLInputElement} $input Checkbox input
2790
+ */
2791
+ Checkboxes.prototype.syncConditionalRevealWithInputState = function ($input) {
2792
+ var $target = this.$module.querySelector('#' + $input.getAttribute('aria-controls'));
2793
+
2794
+ if ($target && $target.classList.contains('govuk-checkboxes__conditional')) {
2795
+ var inputIsChecked = $input.checked;
2796
+
2797
+ $input.setAttribute('aria-expanded', inputIsChecked);
2798
+ $target.classList.toggle('govuk-checkboxes__conditional--hidden', !inputIsChecked);
2799
+ }
2800
+ };
2801
+
2802
+ /**
2803
+ * Uncheck other checkboxes
2804
+ *
2805
+ * Find any other checkbox inputs with the same name value, and uncheck them.
2806
+ * This is useful for when a “None of these" checkbox is checked.
2807
+ */
2808
+ Checkboxes.prototype.unCheckAllInputsExcept = function ($input) {
2809
+ var allInputsWithSameName = document.querySelectorAll('input[type="checkbox"][name="' + $input.name + '"]');
2810
+
2811
+ nodeListForEach(allInputsWithSameName, function ($inputWithSameName) {
2812
+ var hasSameFormOwner = ($input.form === $inputWithSameName.form);
2813
+ if (hasSameFormOwner && $inputWithSameName !== $input) {
2814
+ $inputWithSameName.checked = false;
2815
+ }
2816
+ });
2817
+
2818
+ this.syncAllConditionalReveals();
2819
+ };
2820
+
2821
+ /**
2822
+ * Uncheck exclusive inputs
2823
+ *
2824
+ * Find any checkbox inputs with the same name value and the 'exclusive' behaviour,
2825
+ * and uncheck them. This helps prevent someone checking both a regular checkbox and a
2826
+ * "None of these" checkbox in the same fieldset.
2827
+ */
2828
+ Checkboxes.prototype.unCheckExclusiveInputs = function ($input) {
2829
+ var allInputsWithSameNameAndExclusiveBehaviour = document.querySelectorAll(
2830
+ 'input[data-behaviour="exclusive"][type="checkbox"][name="' + $input.name + '"]'
2831
+ );
2832
+
2833
+ nodeListForEach(allInputsWithSameNameAndExclusiveBehaviour, function ($exclusiveInput) {
2834
+ var hasSameFormOwner = ($input.form === $exclusiveInput.form);
2835
+ if (hasSameFormOwner) {
2836
+ $exclusiveInput.checked = false;
2837
+ }
2838
+ });
2839
+
2840
+ this.syncAllConditionalReveals();
2841
+ };
2842
+
2843
+ /**
2844
+ * Click event handler
2845
+ *
2846
+ * Handle a click within the $module – if the click occurred on a checkbox, sync
2847
+ * the state of any associated conditional reveal with the checkbox state.
2848
+ *
2849
+ * @param {MouseEvent} event Click event
2850
+ */
2851
+ Checkboxes.prototype.handleClick = function (event) {
2852
+ var $target = event.target;
2853
+
2854
+ // Ignore clicks on things that aren't checkbox inputs
2855
+ if ($target.type !== 'checkbox') {
2856
+ return
2857
+ }
2858
+
2859
+ // If the checkbox conditionally-reveals some content, sync the state
2860
+ var hasAriaControls = $target.getAttribute('aria-controls');
2861
+ if (hasAriaControls) {
2862
+ this.syncConditionalRevealWithInputState($target);
2863
+ }
2864
+
2865
+ // No further behaviour needed for unchecking
2866
+ if (!$target.checked) {
2867
+ return
2868
+ }
2869
+
2870
+ // Handle 'exclusive' checkbox behaviour (ie "None of these")
2871
+ var hasBehaviourExclusive = ($target.getAttribute('data-behaviour') === 'exclusive');
2872
+ if (hasBehaviourExclusive) {
2873
+ this.unCheckAllInputsExcept($target);
2874
+ } else {
2875
+ this.unCheckExclusiveInputs($target);
2876
+ }
2877
+ };
2878
+
2879
+ (function(undefined) {
2880
+
2881
+ // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-service/1f3c09b402f65bf6e393f933a15ba63f1b86ef1f/packages/polyfill-library/polyfills/Element/prototype/matches/detect.js
2882
+ var detect = (
2883
+ 'document' in this && "matches" in document.documentElement
2884
+ );
2885
+
2886
+ if (detect) return
2887
+
2888
+ // Polyfill from https://raw.githubusercontent.com/Financial-Times/polyfill-service/1f3c09b402f65bf6e393f933a15ba63f1b86ef1f/packages/polyfill-library/polyfills/Element/prototype/matches/polyfill.js
2889
+ Element.prototype.matches = Element.prototype.webkitMatchesSelector || Element.prototype.oMatchesSelector || Element.prototype.msMatchesSelector || Element.prototype.mozMatchesSelector || function matches(selector) {
2890
+ var element = this;
2891
+ var elements = (element.document || element.ownerDocument).querySelectorAll(selector);
2892
+ var index = 0;
2893
+
2894
+ while (elements[index] && elements[index] !== element) {
2895
+ ++index;
2896
+ }
2897
+
2898
+ return !!elements[index];
2899
+ };
2900
+
2901
+ }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
2902
+
2903
+ (function(undefined) {
2904
+
2905
+ // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-service/1f3c09b402f65bf6e393f933a15ba63f1b86ef1f/packages/polyfill-library/polyfills/Element/prototype/closest/detect.js
2906
+ var detect = (
2907
+ 'document' in this && "closest" in document.documentElement
2908
+ );
2909
+
2910
+ if (detect) return
2911
+
2912
+ // Polyfill from https://raw.githubusercontent.com/Financial-Times/polyfill-service/1f3c09b402f65bf6e393f933a15ba63f1b86ef1f/packages/polyfill-library/polyfills/Element/prototype/closest/polyfill.js
2913
+ Element.prototype.closest = function closest(selector) {
2914
+ var node = this;
2915
+
2916
+ while (node) {
2917
+ if (node.matches(selector)) return node;
2918
+ else node = 'SVGElement' in window && node instanceof SVGElement ? node.parentNode : node.parentElement;
2919
+ }
2920
+
2921
+ return null;
2922
+ };
2923
+
2924
+ }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
2925
+
2926
+ function ErrorSummary ($module) {
2927
+ this.$module = $module;
2928
+ }
2929
+
2930
+ ErrorSummary.prototype.init = function () {
2931
+ var $module = this.$module;
2932
+ if (!$module) {
2933
+ return
2934
+ }
2935
+ $module.focus();
2936
+
2937
+ $module.addEventListener('click', this.handleClick.bind(this));
2938
+ };
2939
+
2940
+ /**
2941
+ * Click event handler
2942
+ *
2943
+ * @param {MouseEvent} event - Click event
2944
+ */
2945
+ ErrorSummary.prototype.handleClick = function (event) {
2946
+ var target = event.target;
2947
+ if (this.focusTarget(target)) {
2948
+ event.preventDefault();
2949
+ }
2950
+ };
2951
+
2952
+ /**
2953
+ * Focus the target element
2954
+ *
2955
+ * By default, the browser will scroll the target into view. Because our labels
2956
+ * or legends appear above the input, this means the user will be presented with
2957
+ * an input without any context, as the label or legend will be off the top of
2958
+ * the screen.
2959
+ *
2960
+ * Manually handling the click event, scrolling the question into view and then
2961
+ * focussing the element solves this.
2962
+ *
2963
+ * This also results in the label and/or legend being announced correctly in
2964
+ * NVDA (as tested in 2018.3.2) - without this only the field type is announced
2965
+ * (e.g. "Edit, has autocomplete").
2966
+ *
2967
+ * @param {HTMLElement} $target - Event target
2968
+ * @returns {boolean} True if the target was able to be focussed
2969
+ */
2970
+ ErrorSummary.prototype.focusTarget = function ($target) {
2971
+ // If the element that was clicked was not a link, return early
2972
+ if ($target.tagName !== 'A' || $target.href === false) {
2973
+ return false
2974
+ }
2975
+
2976
+ var inputId = this.getFragmentFromUrl($target.href);
2977
+ var $input = document.getElementById(inputId);
2978
+ if (!$input) {
2979
+ return false
2980
+ }
2981
+
2982
+ var $legendOrLabel = this.getAssociatedLegendOrLabel($input);
2983
+ if (!$legendOrLabel) {
2984
+ return false
2985
+ }
2986
+
2987
+ // Scroll the legend or label into view *before* calling focus on the input to
2988
+ // avoid extra scrolling in browsers that don't support `preventScroll` (which
2989
+ // at time of writing is most of them...)
2990
+ $legendOrLabel.scrollIntoView();
2991
+ $input.focus({ preventScroll: true });
2992
+
2993
+ return true
2994
+ };
2995
+
2996
+ /**
2997
+ * Get fragment from URL
2998
+ *
2999
+ * Extract the fragment (everything after the hash) from a URL, but not including
3000
+ * the hash.
3001
+ *
3002
+ * @param {string} url - URL
3003
+ * @returns {string} Fragment from URL, without the hash
3004
+ */
3005
+ ErrorSummary.prototype.getFragmentFromUrl = function (url) {
3006
+ if (url.indexOf('#') === -1) {
3007
+ return false
3008
+ }
3009
+
3010
+ return url.split('#').pop()
3011
+ };
3012
+
3013
+ /**
3014
+ * Get associated legend or label
3015
+ *
3016
+ * Returns the first element that exists from this list:
3017
+ *
3018
+ * - The `<legend>` associated with the closest `<fieldset>` ancestor, as long
3019
+ * as the top of it is no more than half a viewport height away from the
3020
+ * bottom of the input
3021
+ * - The first `<label>` that is associated with the input using for="inputId"
3022
+ * - The closest parent `<label>`
3023
+ *
3024
+ * @param {HTMLElement} $input - The input
3025
+ * @returns {HTMLElement} Associated legend or label, or null if no associated
3026
+ * legend or label can be found
3027
+ */
3028
+ ErrorSummary.prototype.getAssociatedLegendOrLabel = function ($input) {
3029
+ var $fieldset = $input.closest('fieldset');
3030
+
3031
+ if ($fieldset) {
3032
+ var legends = $fieldset.getElementsByTagName('legend');
3033
+
3034
+ if (legends.length) {
3035
+ var $candidateLegend = legends[0];
3036
+
3037
+ // If the input type is radio or checkbox, always use the legend if there
3038
+ // is one.
3039
+ if ($input.type === 'checkbox' || $input.type === 'radio') {
3040
+ return $candidateLegend
3041
+ }
3042
+
3043
+ // For other input types, only scroll to the fieldset’s legend (instead of
3044
+ // the label associated with the input) if the input would end up in the
3045
+ // top half of the screen.
3046
+ //
3047
+ // This should avoid situations where the input either ends up off the
3048
+ // screen, or obscured by a software keyboard.
3049
+ var legendTop = $candidateLegend.getBoundingClientRect().top;
3050
+ var inputRect = $input.getBoundingClientRect();
3051
+
3052
+ // If the browser doesn't support Element.getBoundingClientRect().height
3053
+ // or window.innerHeight (like IE8), bail and just link to the label.
3054
+ if (inputRect.height && window.innerHeight) {
3055
+ var inputBottom = inputRect.top + inputRect.height;
3056
+
3057
+ if (inputBottom - legendTop < window.innerHeight / 2) {
3058
+ return $candidateLegend
3059
+ }
3060
+ }
3061
+ }
3062
+ }
3063
+
3064
+ return document.querySelector("label[for='" + $input.getAttribute('id') + "']") ||
3065
+ $input.closest('label')
3066
+ };
3067
+
3068
+ function NotificationBanner ($module) {
3069
+ this.$module = $module;
3070
+ }
3071
+
3072
+ /**
3073
+ * Initialise the component
3074
+ */
3075
+ NotificationBanner.prototype.init = function () {
3076
+ var $module = this.$module;
3077
+ // Check for module
3078
+ if (!$module) {
3079
+ return
3080
+ }
3081
+
3082
+ this.setFocus();
3083
+ };
3084
+
3085
+ /**
3086
+ * Focus the element
3087
+ *
3088
+ * If `role="alert"` is set, focus the element to help some assistive technologies
3089
+ * prioritise announcing it.
3090
+ *
3091
+ * You can turn off the auto-focus functionality by setting `data-disable-auto-focus="true"` in the
3092
+ * component HTML. You might wish to do this based on user research findings, or to avoid a clash
3093
+ * with another element which should be focused when the page loads.
3094
+ */
3095
+ NotificationBanner.prototype.setFocus = function () {
3096
+ var $module = this.$module;
3097
+
3098
+ if ($module.getAttribute('data-disable-auto-focus') === 'true') {
3099
+ return
3100
+ }
3101
+
3102
+ if ($module.getAttribute('role') !== 'alert') {
3103
+ return
3104
+ }
3105
+
3106
+ // Set tabindex to -1 to make the element focusable with JavaScript.
3107
+ // Remove the tabindex on blur as the component doesn't need to be focusable after the page has
3108
+ // loaded.
3109
+ if (!$module.getAttribute('tabindex')) {
3110
+ $module.setAttribute('tabindex', '-1');
3111
+
3112
+ $module.addEventListener('blur', function () {
3113
+ $module.removeAttribute('tabindex');
3114
+ });
3115
+ }
3116
+
3117
+ $module.focus();
3118
+ };
3119
+
3120
+ function Header ($module) {
3121
+ this.$module = $module;
3122
+ this.$menuButton = $module && $module.querySelector('.govuk-js-header-toggle');
3123
+ this.$menu = this.$menuButton && $module.querySelector(
3124
+ '#' + this.$menuButton.getAttribute('aria-controls')
3125
+ );
3126
+ }
3127
+
3128
+ /**
3129
+ * Initialise header
3130
+ *
3131
+ * Check for the presence of the header, menu and menu button – if any are
3132
+ * missing then there's nothing to do so return early.
3133
+ */
3134
+ Header.prototype.init = function () {
3135
+ if (!this.$module || !this.$menuButton || !this.$menu) {
3136
+ return
3137
+ }
3138
+
3139
+ this.syncState(this.$menu.classList.contains('govuk-header__navigation--open'));
3140
+ this.$menuButton.addEventListener('click', this.handleMenuButtonClick.bind(this));
3141
+ };
3142
+
3143
+ /**
3144
+ * Sync menu state
3145
+ *
3146
+ * Sync the menu button class and the accessible state of the menu and the menu
3147
+ * button with the visible state of the menu
3148
+ *
3149
+ * @param {boolean} isVisible Whether the menu is currently visible
3150
+ */
3151
+ Header.prototype.syncState = function (isVisible) {
3152
+ this.$menuButton.classList.toggle('govuk-header__menu-button--open', isVisible);
3153
+ this.$menuButton.setAttribute('aria-expanded', isVisible);
3154
+ };
3155
+
3156
+ /**
3157
+ * Handle menu button click
3158
+ *
3159
+ * When the menu button is clicked, change the visibility of the menu and then
3160
+ * sync the accessibility state and menu button state
3161
+ */
3162
+ Header.prototype.handleMenuButtonClick = function () {
3163
+ var isVisible = this.$menu.classList.toggle('govuk-header__navigation--open');
3164
+ this.syncState(isVisible);
3165
+ };
3166
+
3167
+ function Radios ($module) {
3168
+ this.$module = $module;
3169
+ this.$inputs = $module.querySelectorAll('input[type="radio"]');
3170
+ }
3171
+
3172
+ /**
3173
+ * Initialise Radios
3174
+ *
3175
+ * Radios can be associated with a 'conditionally revealed' content block – for
3176
+ * example, a radio for 'Phone' could reveal an additional form field for the
3177
+ * user to enter their phone number.
3178
+ *
3179
+ * These associations are made using a `data-aria-controls` attribute, which is
3180
+ * promoted to an aria-controls attribute during initialisation.
3181
+ *
3182
+ * We also need to restore the state of any conditional reveals on the page (for
3183
+ * example if the user has navigated back), and set up event handlers to keep
3184
+ * the reveal in sync with the radio state.
3185
+ */
3186
+ Radios.prototype.init = function () {
3187
+ var $module = this.$module;
3188
+ var $inputs = this.$inputs;
3189
+
3190
+ nodeListForEach($inputs, function ($input) {
3191
+ var target = $input.getAttribute('data-aria-controls');
3192
+
3193
+ // Skip radios without data-aria-controls attributes, or where the
3194
+ // target element does not exist.
3195
+ if (!target || !$module.querySelector('#' + target)) {
3196
+ return
3197
+ }
3198
+
3199
+ // Promote the data-aria-controls attribute to a aria-controls attribute
3200
+ // so that the relationship is exposed in the AOM
3201
+ $input.setAttribute('aria-controls', target);
3202
+ $input.removeAttribute('data-aria-controls');
3203
+ });
3204
+
3205
+ // When the page is restored after navigating 'back' in some browsers the
3206
+ // state of form controls is not restored until *after* the DOMContentLoaded
3207
+ // event is fired, so we need to sync after the pageshow event in browsers
3208
+ // that support it.
3209
+ if ('onpageshow' in window) {
3210
+ window.addEventListener('pageshow', this.syncAllConditionalReveals.bind(this));
3211
+ } else {
3212
+ window.addEventListener('DOMContentLoaded', this.syncAllConditionalReveals.bind(this));
3213
+ }
3214
+
3215
+ // Although we've set up handlers to sync state on the pageshow or
3216
+ // DOMContentLoaded event, init could be called after those events have fired,
3217
+ // for example if they are added to the page dynamically, so sync now too.
3218
+ this.syncAllConditionalReveals();
3219
+
3220
+ // Handle events
3221
+ $module.addEventListener('click', this.handleClick.bind(this));
3222
+ };
3223
+
3224
+ /**
3225
+ * Sync the conditional reveal states for all inputs in this $module.
3226
+ */
3227
+ Radios.prototype.syncAllConditionalReveals = function () {
3228
+ nodeListForEach(this.$inputs, this.syncConditionalRevealWithInputState.bind(this));
3229
+ };
3230
+
3231
+ /**
3232
+ * Sync conditional reveal with the input state
3233
+ *
3234
+ * Synchronise the visibility of the conditional reveal, and its accessible
3235
+ * state, with the input's checked state.
3236
+ *
3237
+ * @param {HTMLInputElement} $input Radio input
3238
+ */
3239
+ Radios.prototype.syncConditionalRevealWithInputState = function ($input) {
3240
+ var $target = document.querySelector('#' + $input.getAttribute('aria-controls'));
3241
+
3242
+ if ($target && $target.classList.contains('govuk-radios__conditional')) {
3243
+ var inputIsChecked = $input.checked;
3244
+
3245
+ $input.setAttribute('aria-expanded', inputIsChecked);
3246
+ $target.classList.toggle('govuk-radios__conditional--hidden', !inputIsChecked);
3247
+ }
3248
+ };
3249
+
3250
+ /**
3251
+ * Click event handler
3252
+ *
3253
+ * Handle a click within the $module – if the click occurred on a radio, sync
3254
+ * the state of the conditional reveal for all radio buttons in the same form
3255
+ * with the same name (because checking one radio could have un-checked a radio
3256
+ * in another $module)
3257
+ *
3258
+ * @param {MouseEvent} event Click event
3259
+ */
3260
+ Radios.prototype.handleClick = function (event) {
3261
+ var $clickedInput = event.target;
3262
+
3263
+ // Ignore clicks on things that aren't radio buttons
3264
+ if ($clickedInput.type !== 'radio') {
3265
+ return
3266
+ }
3267
+
3268
+ // We only need to consider radios with conditional reveals, which will have
3269
+ // aria-controls attributes.
3270
+ var $allInputs = document.querySelectorAll('input[type="radio"][aria-controls]');
3271
+
3272
+ nodeListForEach($allInputs, function ($input) {
3273
+ var hasSameFormOwner = ($input.form === $clickedInput.form);
3274
+ var hasSameName = ($input.name === $clickedInput.name);
3275
+
3276
+ if (hasSameName && hasSameFormOwner) {
3277
+ this.syncConditionalRevealWithInputState($input);
3278
+ }
3279
+ }.bind(this));
3280
+ };
3281
+
3282
+ (function(undefined) {
3283
+
3284
+ // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-library/master/polyfills/Element/prototype/nextElementSibling/detect.js
3285
+ var detect = (
3286
+ 'document' in this && "nextElementSibling" in document.documentElement
3287
+ );
3288
+
3289
+ if (detect) return
3290
+
3291
+ // Polyfill from https://raw.githubusercontent.com/Financial-Times/polyfill-library/master/polyfills/Element/prototype/nextElementSibling/polyfill.js
3292
+ Object.defineProperty(Element.prototype, "nextElementSibling", {
3293
+ get: function(){
3294
+ var el = this.nextSibling;
3295
+ while (el && el.nodeType !== 1) { el = el.nextSibling; }
3296
+ return el;
3297
+ }
3298
+ });
3299
+
3300
+ }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
3301
+
3302
+ (function(undefined) {
3303
+
3304
+ // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-library/master/polyfills/Element/prototype/previousElementSibling/detect.js
3305
+ var detect = (
3306
+ 'document' in this && "previousElementSibling" in document.documentElement
3307
+ );
3308
+
3309
+ if (detect) return
3310
+
3311
+ // Polyfill from https://raw.githubusercontent.com/Financial-Times/polyfill-library/master/polyfills/Element/prototype/previousElementSibling/polyfill.js
3312
+ Object.defineProperty(Element.prototype, 'previousElementSibling', {
3313
+ get: function(){
3314
+ var el = this.previousSibling;
3315
+ while (el && el.nodeType !== 1) { el = el.previousSibling; }
3316
+ return el;
3317
+ }
3318
+ });
3319
+
3320
+ }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
3321
+
3322
+ function Tabs ($module) {
3323
+ this.$module = $module;
3324
+ this.$tabs = $module.querySelectorAll('.govuk-tabs__tab');
3325
+
3326
+ this.keys = { left: 37, right: 39, up: 38, down: 40 };
3327
+ this.jsHiddenClass = 'govuk-tabs__panel--hidden';
3328
+ }
3329
+
3330
+ Tabs.prototype.init = function () {
3331
+ if (typeof window.matchMedia === 'function') {
3332
+ this.setupResponsiveChecks();
3333
+ } else {
3334
+ this.setup();
3335
+ }
3336
+ };
3337
+
3338
+ Tabs.prototype.setupResponsiveChecks = function () {
3339
+ this.mql = window.matchMedia('(min-width: 40.0625em)');
3340
+ this.mql.addListener(this.checkMode.bind(this));
3341
+ this.checkMode();
3342
+ };
3343
+
3344
+ Tabs.prototype.checkMode = function () {
3345
+ if (this.mql.matches) {
3346
+ this.setup();
3347
+ } else {
3348
+ this.teardown();
3349
+ }
3350
+ };
3351
+
3352
+ Tabs.prototype.setup = function () {
3353
+ var $module = this.$module;
3354
+ var $tabs = this.$tabs;
3355
+ var $tabList = $module.querySelector('.govuk-tabs__list');
3356
+ var $tabListItems = $module.querySelectorAll('.govuk-tabs__list-item');
3357
+
3358
+ if (!$tabs || !$tabList || !$tabListItems) {
3359
+ return
3360
+ }
3361
+
3362
+ $tabList.setAttribute('role', 'tablist');
3363
+
3364
+ nodeListForEach($tabListItems, function ($item) {
3365
+ $item.setAttribute('role', 'presentation');
3366
+ });
3367
+
3368
+ nodeListForEach($tabs, function ($tab) {
3369
+ // Set HTML attributes
3370
+ this.setAttributes($tab);
3371
+
3372
+ // Save bounded functions to use when removing event listeners during teardown
3373
+ $tab.boundTabClick = this.onTabClick.bind(this);
3374
+ $tab.boundTabKeydown = this.onTabKeydown.bind(this);
3375
+
3376
+ // Handle events
3377
+ $tab.addEventListener('click', $tab.boundTabClick, true);
3378
+ $tab.addEventListener('keydown', $tab.boundTabKeydown, true);
3379
+
3380
+ // Remove old active panels
3381
+ this.hideTab($tab);
3382
+ }.bind(this));
3383
+
3384
+ // Show either the active tab according to the URL's hash or the first tab
3385
+ var $activeTab = this.getTab(window.location.hash) || this.$tabs[0];
3386
+ this.showTab($activeTab);
3387
+
3388
+ // Handle hashchange events
3389
+ $module.boundOnHashChange = this.onHashChange.bind(this);
3390
+ window.addEventListener('hashchange', $module.boundOnHashChange, true);
3391
+ };
3392
+
3393
+ Tabs.prototype.teardown = function () {
3394
+ var $module = this.$module;
3395
+ var $tabs = this.$tabs;
3396
+ var $tabList = $module.querySelector('.govuk-tabs__list');
3397
+ var $tabListItems = $module.querySelectorAll('.govuk-tabs__list-item');
3398
+
3399
+ if (!$tabs || !$tabList || !$tabListItems) {
3400
+ return
3401
+ }
3402
+
3403
+ $tabList.removeAttribute('role');
3404
+
3405
+ nodeListForEach($tabListItems, function ($item) {
3406
+ $item.removeAttribute('role', 'presentation');
3407
+ });
3408
+
3409
+ nodeListForEach($tabs, function ($tab) {
3410
+ // Remove events
3411
+ $tab.removeEventListener('click', $tab.boundTabClick, true);
3412
+ $tab.removeEventListener('keydown', $tab.boundTabKeydown, true);
3413
+
3414
+ // Unset HTML attributes
3415
+ this.unsetAttributes($tab);
3416
+ }.bind(this));
3417
+
3418
+ // Remove hashchange event handler
3419
+ window.removeEventListener('hashchange', $module.boundOnHashChange, true);
3420
+ };
3421
+
3422
+ Tabs.prototype.onHashChange = function (e) {
3423
+ var hash = window.location.hash;
3424
+ var $tabWithHash = this.getTab(hash);
3425
+ if (!$tabWithHash) {
3426
+ return
3427
+ }
3428
+
3429
+ // Prevent changing the hash
3430
+ if (this.changingHash) {
3431
+ this.changingHash = false;
3432
+ return
3433
+ }
3434
+
3435
+ // Show either the active tab according to the URL's hash or the first tab
3436
+ var $previousTab = this.getCurrentTab();
3437
+
3438
+ this.hideTab($previousTab);
3439
+ this.showTab($tabWithHash);
3440
+ $tabWithHash.focus();
3441
+ };
3442
+
3443
+ Tabs.prototype.hideTab = function ($tab) {
3444
+ this.unhighlightTab($tab);
3445
+ this.hidePanel($tab);
3446
+ };
3447
+
3448
+ Tabs.prototype.showTab = function ($tab) {
3449
+ this.highlightTab($tab);
3450
+ this.showPanel($tab);
3451
+ };
3452
+
3453
+ Tabs.prototype.getTab = function (hash) {
3454
+ return this.$module.querySelector('.govuk-tabs__tab[href="' + hash + '"]')
3455
+ };
3456
+
3457
+ Tabs.prototype.setAttributes = function ($tab) {
3458
+ // set tab attributes
3459
+ var panelId = this.getHref($tab).slice(1);
3460
+ $tab.setAttribute('id', 'tab_' + panelId);
3461
+ $tab.setAttribute('role', 'tab');
3462
+ $tab.setAttribute('aria-controls', panelId);
3463
+ $tab.setAttribute('aria-selected', 'false');
3464
+ $tab.setAttribute('tabindex', '-1');
3465
+
3466
+ // set panel attributes
3467
+ var $panel = this.getPanel($tab);
3468
+ $panel.setAttribute('role', 'tabpanel');
3469
+ $panel.setAttribute('aria-labelledby', $tab.id);
3470
+ $panel.classList.add(this.jsHiddenClass);
3471
+ };
3472
+
3473
+ Tabs.prototype.unsetAttributes = function ($tab) {
3474
+ // unset tab attributes
3475
+ $tab.removeAttribute('id');
3476
+ $tab.removeAttribute('role');
3477
+ $tab.removeAttribute('aria-controls');
3478
+ $tab.removeAttribute('aria-selected');
3479
+ $tab.removeAttribute('tabindex');
3480
+
3481
+ // unset panel attributes
3482
+ var $panel = this.getPanel($tab);
3483
+ $panel.removeAttribute('role');
3484
+ $panel.removeAttribute('aria-labelledby');
3485
+ $panel.classList.remove(this.jsHiddenClass);
3486
+ };
3487
+
3488
+ Tabs.prototype.onTabClick = function (e) {
3489
+ if (!e.target.classList.contains('govuk-tabs__tab')) {
3490
+ // Allow events on child DOM elements to bubble up to tab parent
3491
+ return false
3492
+ }
3493
+ e.preventDefault();
3494
+ var $newTab = e.target;
3495
+ var $currentTab = this.getCurrentTab();
3496
+ this.hideTab($currentTab);
3497
+ this.showTab($newTab);
3498
+ this.createHistoryEntry($newTab);
3499
+ };
3500
+
3501
+ Tabs.prototype.createHistoryEntry = function ($tab) {
3502
+ var $panel = this.getPanel($tab);
3503
+
3504
+ // Save and restore the id
3505
+ // so the page doesn't jump when a user clicks a tab (which changes the hash)
3506
+ var id = $panel.id;
3507
+ $panel.id = '';
3508
+ this.changingHash = true;
3509
+ window.location.hash = this.getHref($tab).slice(1);
3510
+ $panel.id = id;
3511
+ };
3512
+
3513
+ Tabs.prototype.onTabKeydown = function (e) {
3514
+ switch (e.keyCode) {
3515
+ case this.keys.left:
3516
+ case this.keys.up:
3517
+ this.activatePreviousTab();
3518
+ e.preventDefault();
3519
+ break
3520
+ case this.keys.right:
3521
+ case this.keys.down:
3522
+ this.activateNextTab();
3523
+ e.preventDefault();
3524
+ break
3525
+ }
3526
+ };
3527
+
3528
+ Tabs.prototype.activateNextTab = function () {
3529
+ var currentTab = this.getCurrentTab();
3530
+ var nextTabListItem = currentTab.parentNode.nextElementSibling;
3531
+ if (nextTabListItem) {
3532
+ var nextTab = nextTabListItem.querySelector('.govuk-tabs__tab');
3533
+ }
3534
+ if (nextTab) {
3535
+ this.hideTab(currentTab);
3536
+ this.showTab(nextTab);
3537
+ nextTab.focus();
3538
+ this.createHistoryEntry(nextTab);
3539
+ }
3540
+ };
3541
+
3542
+ Tabs.prototype.activatePreviousTab = function () {
3543
+ var currentTab = this.getCurrentTab();
3544
+ var previousTabListItem = currentTab.parentNode.previousElementSibling;
3545
+ if (previousTabListItem) {
3546
+ var previousTab = previousTabListItem.querySelector('.govuk-tabs__tab');
3547
+ }
3548
+ if (previousTab) {
3549
+ this.hideTab(currentTab);
3550
+ this.showTab(previousTab);
3551
+ previousTab.focus();
3552
+ this.createHistoryEntry(previousTab);
3553
+ }
3554
+ };
3555
+
3556
+ Tabs.prototype.getPanel = function ($tab) {
3557
+ var $panel = this.$module.querySelector(this.getHref($tab));
3558
+ return $panel
3559
+ };
3560
+
3561
+ Tabs.prototype.showPanel = function ($tab) {
3562
+ var $panel = this.getPanel($tab);
3563
+ $panel.classList.remove(this.jsHiddenClass);
3564
+ };
3565
+
3566
+ Tabs.prototype.hidePanel = function (tab) {
3567
+ var $panel = this.getPanel(tab);
3568
+ $panel.classList.add(this.jsHiddenClass);
3569
+ };
3570
+
3571
+ Tabs.prototype.unhighlightTab = function ($tab) {
3572
+ $tab.setAttribute('aria-selected', 'false');
3573
+ $tab.parentNode.classList.remove('govuk-tabs__list-item--selected');
3574
+ $tab.setAttribute('tabindex', '-1');
3575
+ };
3576
+
3577
+ Tabs.prototype.highlightTab = function ($tab) {
3578
+ $tab.setAttribute('aria-selected', 'true');
3579
+ $tab.parentNode.classList.add('govuk-tabs__list-item--selected');
3580
+ $tab.setAttribute('tabindex', '0');
3581
+ };
3582
+
3583
+ Tabs.prototype.getCurrentTab = function () {
3584
+ return this.$module.querySelector('.govuk-tabs__list-item--selected .govuk-tabs__tab')
3585
+ };
3586
+
3587
+ // this is because IE doesn't always return the actual value but a relative full path
3588
+ // should be a utility function most prob
3589
+ // http://labs.thesedays.com/blog/2010/01/08/getting-the-href-value-with-jquery-in-ie/
3590
+ Tabs.prototype.getHref = function ($tab) {
3591
+ var href = $tab.getAttribute('href');
3592
+ var hash = href.slice(href.indexOf('#'), href.length);
3593
+ return hash
3594
+ };
3595
+
3596
+ function initAll (options) {
3597
+ // Set the options to an empty object by default if no options are passed.
3598
+ options = typeof options !== 'undefined' ? options : {};
3599
+
3600
+ // Allow the user to initialise GOV.UK Frontend in only certain sections of the page
3601
+ // Defaults to the entire document if nothing is set.
3602
+ var scope = typeof options.scope !== 'undefined' ? options.scope : document;
3603
+
3604
+ var $buttons = scope.querySelectorAll('[data-module="govuk-button"]');
3605
+ nodeListForEach($buttons, function ($button) {
3606
+ new Button($button).init();
3607
+ });
3608
+
3609
+ var $accordions = scope.querySelectorAll('[data-module="govuk-accordion"]');
3610
+ nodeListForEach($accordions, function ($accordion) {
3611
+ new Accordion($accordion).init();
3612
+ });
3613
+
3614
+ var $details = scope.querySelectorAll('[data-module="govuk-details"]');
3615
+ nodeListForEach($details, function ($detail) {
3616
+ new Details($detail).init();
3617
+ });
3618
+
3619
+ var $characterCounts = scope.querySelectorAll('[data-module="govuk-character-count"]');
3620
+ nodeListForEach($characterCounts, function ($characterCount) {
3621
+ new CharacterCount($characterCount).init();
3622
+ });
3623
+
3624
+ var $checkboxes = scope.querySelectorAll('[data-module="govuk-checkboxes"]');
3625
+ nodeListForEach($checkboxes, function ($checkbox) {
3626
+ new Checkboxes($checkbox).init();
3627
+ });
3628
+
3629
+ // Find first error summary module to enhance.
3630
+ var $errorSummary = scope.querySelector('[data-module="govuk-error-summary"]');
3631
+ new ErrorSummary($errorSummary).init();
3632
+
3633
+ // Find first header module to enhance.
3634
+ var $toggleButton = scope.querySelector('[data-module="govuk-header"]');
3635
+ new Header($toggleButton).init();
3636
+
3637
+ var $notificationBanners = scope.querySelectorAll('[data-module="govuk-notification-banner"]');
3638
+ nodeListForEach($notificationBanners, function ($notificationBanner) {
3639
+ new NotificationBanner($notificationBanner).init();
3640
+ });
3641
+
3642
+ var $radios = scope.querySelectorAll('[data-module="govuk-radios"]');
3643
+ nodeListForEach($radios, function ($radio) {
3644
+ new Radios($radio).init();
3645
+ });
3646
+
3647
+ var $tabs = scope.querySelectorAll('[data-module="govuk-tabs"]');
3648
+ nodeListForEach($tabs, function ($tabs) {
3649
+ new Tabs($tabs).init();
3650
+ });
3651
+ }
3652
+
3653
+ exports.initAll = initAll;
3654
+ exports.Accordion = Accordion;
3655
+ exports.Button = Button;
3656
+ exports.Details = Details;
3657
+ exports.CharacterCount = CharacterCount;
3658
+ exports.Checkboxes = Checkboxes;
3659
+ exports.ErrorSummary = ErrorSummary;
3660
+ exports.Header = Header;
3661
+ exports.Radios = Radios;
3662
+ exports.Tabs = Tabs;
3663
+
3664
+ })));
3665
+
3666
+ }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
3667
+ },{}],13:[function(require,module,exports){
885
3668
  (function (global){(function (){
886
3669
  /**
887
3670
  * @license
@@ -18094,7 +20877,7 @@ module.exports = {
18094
20877
  }.call(this));
18095
20878
 
18096
20879
  }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
18097
- },{}],11:[function(require,module,exports){
20880
+ },{}],14:[function(require,module,exports){
18098
20881
  // shim for using process in browser
18099
20882
  var process = module.exports = {};
18100
20883
 
@@ -18280,7 +21063,7 @@ process.chdir = function (dir) {
18280
21063
  };
18281
21064
  process.umask = function() { return 0; };
18282
21065
 
18283
- },{}],12:[function(require,module,exports){
21066
+ },{}],15:[function(require,module,exports){
18284
21067
  (function (setImmediate,clearImmediate){(function (){
18285
21068
  var nextTick = require('process/browser.js').nextTick;
18286
21069
  var apply = Function.prototype.apply;
@@ -18359,7 +21142,7 @@ exports.clearImmediate = typeof clearImmediate === "function" ? clearImmediate :
18359
21142
  delete immediateIds[id];
18360
21143
  };
18361
21144
  }).call(this)}).call(this,require("timers").setImmediate,require("timers").clearImmediate)
18362
- },{"process/browser.js":11,"timers":12}],13:[function(require,module,exports){
21145
+ },{"process/browser.js":14,"timers":15}],16:[function(require,module,exports){
18363
21146
  /* eslint-disable */
18364
21147
  'use strict'
18365
21148
 
@@ -18430,7 +21213,8 @@ $('.typeahead').each(function applyTypeahead() {
18430
21213
  limit: 100
18431
21214
  });
18432
21215
  });
18433
- },{"../../../frontend/themes/gov-uk/client-js":2,"jquery":14,"typeahead-aria":17}],14:[function(require,module,exports){
21216
+
21217
+ },{"../../../frontend/themes/gov-uk/client-js":3,"jquery":17,"typeahead-aria":20}],17:[function(require,module,exports){
18434
21218
  /*!
18435
21219
  * jQuery JavaScript Library v3.6.0
18436
21220
  * https://jquery.com/
@@ -29313,7 +32097,7 @@ if ( typeof noGlobal === "undefined" ) {
29313
32097
  return jQuery;
29314
32098
  } );
29315
32099
 
29316
- },{}],15:[function(require,module,exports){
32100
+ },{}],18:[function(require,module,exports){
29317
32101
  /*!
29318
32102
  * typeahead.js 1.0.4
29319
32103
  * https://github.com/twitter/typeahead.js
@@ -30266,7 +33050,7 @@ return jQuery;
30266
33050
  }();
30267
33051
  return Bloodhound;
30268
33052
  });
30269
- },{"jquery":14}],16:[function(require,module,exports){
33053
+ },{"jquery":17}],19:[function(require,module,exports){
30270
33054
  (function (setImmediate){(function (){
30271
33055
  /*!
30272
33056
  * typeahead.js 1.0.4
@@ -32863,7 +35647,7 @@ return jQuery;
32863
35647
  })();
32864
35648
  });
32865
35649
  }).call(this)}).call(this,require("timers").setImmediate)
32866
- },{"jquery":14,"timers":12}],17:[function(require,module,exports){
35650
+ },{"jquery":17,"timers":15}],20:[function(require,module,exports){
32867
35651
  'use strict';
32868
35652
 
32869
35653
  module.exports = {
@@ -32871,4 +35655,4 @@ module.exports = {
32871
35655
  "loadjQueryPlugin": function() {require("./dist/typeahead.bundle.js");}
32872
35656
  };
32873
35657
 
32874
- },{"./dist/bloodhound.js":15,"./dist/typeahead.bundle.js":16}]},{},[13]);
35658
+ },{"./dist/bloodhound.js":18,"./dist/typeahead.bundle.js":19}]},{},[16]);