hmrc-frontend 5.20.0 → 5.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/hmrc/all.js CHANGED
@@ -973,1288 +973,6 @@
973
973
  }
974
974
  };
975
975
 
976
- var Event_1 = createCommonjsModule(function (module, exports) {
977
- (function (global, factory) {
978
- factory();
979
- })(commonjsGlobal, function () {
980
-
981
- (function (undefined) {
982
- // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Window/detect.js
983
- var detect = ('Window' in this);
984
- if (detect) return; // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Window&flags=always
985
-
986
- if (typeof WorkerGlobalScope === "undefined" && typeof importScripts !== "function") {
987
- (function (global) {
988
- if (global.constructor) {
989
- global.Window = global.constructor;
990
- } else {
991
- (global.Window = global.constructor = new Function('return function Window() {}')()).prototype = this;
992
- }
993
- })(this);
994
- }
995
- }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof commonjsGlobal && commonjsGlobal || {});
996
- (function (undefined) {
997
- // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Document/detect.js
998
- var detect = ("Document" in this);
999
- if (detect) return; // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Document&flags=always
1000
-
1001
- if (typeof WorkerGlobalScope === "undefined" && typeof importScripts !== "function") {
1002
- if (this.HTMLDocument) {
1003
- // IE8
1004
- // HTMLDocument is an extension of Document. If the browser has HTMLDocument but not Document, the former will suffice as an alias for the latter.
1005
- this.Document = this.HTMLDocument;
1006
- } else {
1007
- // 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.
1008
- this.Document = this.HTMLDocument = document.constructor = new Function('return function Document() {}')();
1009
- this.Document.prototype = document;
1010
- }
1011
- }
1012
- }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof commonjsGlobal && commonjsGlobal || {});
1013
- (function (undefined) {
1014
- // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Element/detect.js
1015
- var detect = 'Element' in this && 'HTMLElement' in this;
1016
- if (detect) return; // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Element&flags=always
1017
-
1018
- (function () {
1019
- // IE8
1020
- if (window.Element && !window.HTMLElement) {
1021
- window.HTMLElement = window.Element;
1022
- return;
1023
- } // create Element constructor
1024
-
1025
-
1026
- window.Element = window.HTMLElement = new Function('return function Element() {}')(); // generate sandboxed iframe
1027
-
1028
- var vbody = document.appendChild(document.createElement('body'));
1029
- var frame = vbody.appendChild(document.createElement('iframe')); // use sandboxed iframe to replicate Element functionality
1030
-
1031
- var frameDocument = frame.contentWindow.document;
1032
- var prototype = Element.prototype = frameDocument.appendChild(frameDocument.createElement('*'));
1033
- var cache = {}; // polyfill Element.prototype on an element
1034
-
1035
- var shiv = function (element, deep) {
1036
- var childNodes = element.childNodes || [],
1037
- index = -1,
1038
- key,
1039
- value,
1040
- childNode;
1041
-
1042
- if (element.nodeType === 1 && element.constructor !== Element) {
1043
- element.constructor = Element;
1044
-
1045
- for (key in cache) {
1046
- value = cache[key];
1047
- element[key] = value;
1048
- }
1049
- }
1050
-
1051
- while (childNode = deep && childNodes[++index]) {
1052
- shiv(childNode, deep);
1053
- }
1054
-
1055
- return element;
1056
- };
1057
-
1058
- var elements = document.getElementsByTagName('*');
1059
- var nativeCreateElement = document.createElement;
1060
- var interval;
1061
- var loopLimit = 100;
1062
- prototype.attachEvent('onpropertychange', function (event) {
1063
- var propertyName = event.propertyName,
1064
- nonValue = !cache.hasOwnProperty(propertyName),
1065
- newValue = prototype[propertyName],
1066
- oldValue = cache[propertyName],
1067
- index = -1,
1068
- element;
1069
-
1070
- while (element = elements[++index]) {
1071
- if (element.nodeType === 1) {
1072
- if (nonValue || element[propertyName] === oldValue) {
1073
- element[propertyName] = newValue;
1074
- }
1075
- }
1076
- }
1077
-
1078
- cache[propertyName] = newValue;
1079
- });
1080
- prototype.constructor = Element;
1081
-
1082
- if (!prototype.hasAttribute) {
1083
- // <Element>.hasAttribute
1084
- prototype.hasAttribute = function hasAttribute(name) {
1085
- return this.getAttribute(name) !== null;
1086
- };
1087
- } // Apply Element prototype to the pre-existing DOM as soon as the body element appears.
1088
-
1089
-
1090
- function bodyCheck() {
1091
- if (!loopLimit--) clearTimeout(interval);
1092
-
1093
- if (document.body && !document.body.prototype && /(complete|interactive)/.test(document.readyState)) {
1094
- shiv(document, true);
1095
- if (interval && document.body.prototype) clearTimeout(interval);
1096
- return !!document.body.prototype;
1097
- }
1098
-
1099
- return false;
1100
- }
1101
-
1102
- if (!bodyCheck()) {
1103
- document.onreadystatechange = bodyCheck;
1104
- interval = setInterval(bodyCheck, 25);
1105
- } // Apply to any new elements created after load
1106
-
1107
-
1108
- document.createElement = function createElement(nodeName) {
1109
- var element = nativeCreateElement(String(nodeName).toLowerCase());
1110
- return shiv(element);
1111
- }; // remove sandboxed iframe
1112
-
1113
-
1114
- document.removeChild(vbody);
1115
- })();
1116
- }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof commonjsGlobal && commonjsGlobal || {});
1117
- (function (undefined) {
1118
- // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Object/defineProperty/detect.js
1119
- var detect = // In IE8, defineProperty could only act on DOM elements, so full support
1120
- // for the feature requires the ability to set a property on an arbitrary object
1121
- 'defineProperty' in Object && function () {
1122
- try {
1123
- var a = {};
1124
- Object.defineProperty(a, 'test', {
1125
- value: 42
1126
- });
1127
- return true;
1128
- } catch (e) {
1129
- return false;
1130
- }
1131
- }();
1132
-
1133
- if (detect) return; // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Object.defineProperty&flags=always
1134
-
1135
- (function (nativeDefineProperty) {
1136
- var supportsAccessors = Object.prototype.hasOwnProperty('__defineGetter__');
1137
- var ERR_ACCESSORS_NOT_SUPPORTED = 'Getters & setters cannot be defined on this javascript engine';
1138
- var ERR_VALUE_ACCESSORS = 'A property cannot both have accessors and be writable or have a value';
1139
-
1140
- Object.defineProperty = function defineProperty(object, property, descriptor) {
1141
- // Where native support exists, assume it
1142
- if (nativeDefineProperty && (object === window || object === document || object === Element.prototype || object instanceof Element)) {
1143
- return nativeDefineProperty(object, property, descriptor);
1144
- }
1145
-
1146
- if (object === null || !(object instanceof Object || typeof object === 'object')) {
1147
- throw new TypeError('Object.defineProperty called on non-object');
1148
- }
1149
-
1150
- if (!(descriptor instanceof Object)) {
1151
- throw new TypeError('Property description must be an object');
1152
- }
1153
-
1154
- var propertyString = String(property);
1155
- var hasValueOrWritable = 'value' in descriptor || 'writable' in descriptor;
1156
- var getterType = 'get' in descriptor && typeof descriptor.get;
1157
- var setterType = 'set' in descriptor && typeof descriptor.set; // handle descriptor.get
1158
-
1159
- if (getterType) {
1160
- if (getterType !== 'function') {
1161
- throw new TypeError('Getter must be a function');
1162
- }
1163
-
1164
- if (!supportsAccessors) {
1165
- throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
1166
- }
1167
-
1168
- if (hasValueOrWritable) {
1169
- throw new TypeError(ERR_VALUE_ACCESSORS);
1170
- }
1171
-
1172
- Object.__defineGetter__.call(object, propertyString, descriptor.get);
1173
- } else {
1174
- object[propertyString] = descriptor.value;
1175
- } // handle descriptor.set
1176
-
1177
-
1178
- if (setterType) {
1179
- if (setterType !== 'function') {
1180
- throw new TypeError('Setter must be a function');
1181
- }
1182
-
1183
- if (!supportsAccessors) {
1184
- throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
1185
- }
1186
-
1187
- if (hasValueOrWritable) {
1188
- throw new TypeError(ERR_VALUE_ACCESSORS);
1189
- }
1190
-
1191
- Object.__defineSetter__.call(object, propertyString, descriptor.set);
1192
- } // OK to define value unconditionally - if a getter has been specified as well, an error would be thrown above
1193
-
1194
-
1195
- if ('value' in descriptor) {
1196
- object[propertyString] = descriptor.value;
1197
- }
1198
-
1199
- return object;
1200
- };
1201
- })(Object.defineProperty);
1202
- }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof commonjsGlobal && commonjsGlobal || {});
1203
- (function (undefined) {
1204
- // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Event/detect.js
1205
- var detect = function (global) {
1206
- if (!('Event' in global)) return false;
1207
- if (typeof global.Event === 'function') return true;
1208
-
1209
- try {
1210
- // In IE 9-11, the Event object exists but cannot be instantiated
1211
- new Event('click');
1212
- return true;
1213
- } catch (e) {
1214
- return false;
1215
- }
1216
- }(this);
1217
-
1218
- if (detect) return; // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Event&flags=always
1219
-
1220
- (function () {
1221
- var unlistenableWindowEvents = {
1222
- click: 1,
1223
- dblclick: 1,
1224
- keyup: 1,
1225
- keypress: 1,
1226
- keydown: 1,
1227
- mousedown: 1,
1228
- mouseup: 1,
1229
- mousemove: 1,
1230
- mouseover: 1,
1231
- mouseenter: 1,
1232
- mouseleave: 1,
1233
- mouseout: 1,
1234
- storage: 1,
1235
- storagecommit: 1,
1236
- textinput: 1
1237
- }; // This polyfill depends on availability of `document` so will not run in a worker
1238
- // However, we asssume there are no browsers with worker support that lack proper
1239
- // support for `Event` within the worker
1240
-
1241
- if (typeof document === 'undefined' || typeof window === 'undefined') return;
1242
-
1243
- function indexOf(array, element) {
1244
- var index = -1,
1245
- length = array.length;
1246
-
1247
- while (++index < length) {
1248
- if (index in array && array[index] === element) {
1249
- return index;
1250
- }
1251
- }
1252
-
1253
- return -1;
1254
- }
1255
-
1256
- var existingProto = window.Event && window.Event.prototype || null;
1257
-
1258
- window.Event = Window.prototype.Event = function Event(type, eventInitDict) {
1259
- if (!type) {
1260
- throw new Error('Not enough arguments');
1261
- }
1262
-
1263
- var event; // Shortcut if browser supports createEvent
1264
-
1265
- if ('createEvent' in document) {
1266
- event = document.createEvent('Event');
1267
- var bubbles = eventInitDict && eventInitDict.bubbles !== undefined ? eventInitDict.bubbles : false;
1268
- var cancelable = eventInitDict && eventInitDict.cancelable !== undefined ? eventInitDict.cancelable : false;
1269
- event.initEvent(type, bubbles, cancelable);
1270
- return event;
1271
- }
1272
-
1273
- event = document.createEventObject();
1274
- event.type = type;
1275
- event.bubbles = eventInitDict && eventInitDict.bubbles !== undefined ? eventInitDict.bubbles : false;
1276
- event.cancelable = eventInitDict && eventInitDict.cancelable !== undefined ? eventInitDict.cancelable : false;
1277
- return event;
1278
- };
1279
-
1280
- if (existingProto) {
1281
- Object.defineProperty(window.Event, 'prototype', {
1282
- configurable: false,
1283
- enumerable: false,
1284
- writable: true,
1285
- value: existingProto
1286
- });
1287
- }
1288
-
1289
- if (!('createEvent' in document)) {
1290
- window.addEventListener = Window.prototype.addEventListener = Document.prototype.addEventListener = Element.prototype.addEventListener = function addEventListener() {
1291
- var element = this,
1292
- type = arguments[0],
1293
- listener = arguments[1];
1294
-
1295
- if (element === window && type in unlistenableWindowEvents) {
1296
- 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.');
1297
- }
1298
-
1299
- if (!element._events) {
1300
- element._events = {};
1301
- }
1302
-
1303
- if (!element._events[type]) {
1304
- element._events[type] = function (event) {
1305
- var list = element._events[event.type].list,
1306
- events = list.slice(),
1307
- index = -1,
1308
- length = events.length,
1309
- eventElement;
1310
-
1311
- event.preventDefault = function preventDefault() {
1312
- if (event.cancelable !== false) {
1313
- event.returnValue = false;
1314
- }
1315
- };
1316
-
1317
- event.stopPropagation = function stopPropagation() {
1318
- event.cancelBubble = true;
1319
- };
1320
-
1321
- event.stopImmediatePropagation = function stopImmediatePropagation() {
1322
- event.cancelBubble = true;
1323
- event.cancelImmediate = true;
1324
- };
1325
-
1326
- event.currentTarget = element;
1327
- event.relatedTarget = event.fromElement || null;
1328
- event.target = event.target || event.srcElement || element;
1329
- event.timeStamp = new Date().getTime();
1330
-
1331
- if (event.clientX) {
1332
- event.pageX = event.clientX + document.documentElement.scrollLeft;
1333
- event.pageY = event.clientY + document.documentElement.scrollTop;
1334
- }
1335
-
1336
- while (++index < length && !event.cancelImmediate) {
1337
- if (index in events) {
1338
- eventElement = events[index];
1339
-
1340
- if (indexOf(list, eventElement) !== -1 && typeof eventElement === 'function') {
1341
- eventElement.call(element, event);
1342
- }
1343
- }
1344
- }
1345
- };
1346
-
1347
- element._events[type].list = [];
1348
-
1349
- if (element.attachEvent) {
1350
- element.attachEvent('on' + type, element._events[type]);
1351
- }
1352
- }
1353
-
1354
- element._events[type].list.push(listener);
1355
- };
1356
-
1357
- window.removeEventListener = Window.prototype.removeEventListener = Document.prototype.removeEventListener = Element.prototype.removeEventListener = function removeEventListener() {
1358
- var element = this,
1359
- type = arguments[0],
1360
- listener = arguments[1],
1361
- index;
1362
-
1363
- if (element._events && element._events[type] && element._events[type].list) {
1364
- index = indexOf(element._events[type].list, listener);
1365
-
1366
- if (index !== -1) {
1367
- element._events[type].list.splice(index, 1);
1368
-
1369
- if (!element._events[type].list.length) {
1370
- if (element.detachEvent) {
1371
- element.detachEvent('on' + type, element._events[type]);
1372
- }
1373
-
1374
- delete element._events[type];
1375
- }
1376
- }
1377
- }
1378
- };
1379
-
1380
- window.dispatchEvent = Window.prototype.dispatchEvent = Document.prototype.dispatchEvent = Element.prototype.dispatchEvent = function dispatchEvent(event) {
1381
- if (!arguments.length) {
1382
- throw new Error('Not enough arguments');
1383
- }
1384
-
1385
- if (!event || typeof event.type !== 'string') {
1386
- throw new Error('DOM Events Exception 0');
1387
- }
1388
-
1389
- var element = this,
1390
- type = event.type;
1391
-
1392
- try {
1393
- if (!event.bubbles) {
1394
- event.cancelBubble = true;
1395
-
1396
- var cancelBubbleEvent = function (event) {
1397
- event.cancelBubble = true;
1398
- (element || window).detachEvent('on' + type, cancelBubbleEvent);
1399
- };
1400
-
1401
- this.attachEvent('on' + type, cancelBubbleEvent);
1402
- }
1403
-
1404
- this.fireEvent('on' + type, event);
1405
- } catch (error) {
1406
- event.target = element;
1407
-
1408
- do {
1409
- event.currentTarget = element;
1410
-
1411
- if ('_events' in element && typeof element._events[type] === 'function') {
1412
- element._events[type].call(element, event);
1413
- }
1414
-
1415
- if (typeof element['on' + type] === 'function') {
1416
- element['on' + type].call(element, event);
1417
- }
1418
-
1419
- element = element.nodeType === 9 ? element.parentWindow : element.parentNode;
1420
- } while (element && !event.cancelBubble);
1421
- }
1422
-
1423
- return true;
1424
- }; // Add the DOMContentLoaded Event
1425
-
1426
-
1427
- document.attachEvent('onreadystatechange', function () {
1428
- if (document.readyState === 'complete') {
1429
- document.dispatchEvent(new Event('DOMContentLoaded', {
1430
- bubbles: true
1431
- }));
1432
- }
1433
- });
1434
- }
1435
- })();
1436
- }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof commonjsGlobal && commonjsGlobal || {});
1437
- });
1438
- });
1439
-
1440
- var classList = createCommonjsModule(function (module, exports) {
1441
- (function (global, factory) {
1442
- factory();
1443
- })(commonjsGlobal, function () {
1444
-
1445
- (function (undefined) {
1446
- // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Object/defineProperty/detect.js
1447
- var detect = // In IE8, defineProperty could only act on DOM elements, so full support
1448
- // for the feature requires the ability to set a property on an arbitrary object
1449
- 'defineProperty' in Object && function () {
1450
- try {
1451
- var a = {};
1452
- Object.defineProperty(a, 'test', {
1453
- value: 42
1454
- });
1455
- return true;
1456
- } catch (e) {
1457
- return false;
1458
- }
1459
- }();
1460
-
1461
- if (detect) return; // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Object.defineProperty&flags=always
1462
-
1463
- (function (nativeDefineProperty) {
1464
- var supportsAccessors = Object.prototype.hasOwnProperty('__defineGetter__');
1465
- var ERR_ACCESSORS_NOT_SUPPORTED = 'Getters & setters cannot be defined on this javascript engine';
1466
- var ERR_VALUE_ACCESSORS = 'A property cannot both have accessors and be writable or have a value';
1467
-
1468
- Object.defineProperty = function defineProperty(object, property, descriptor) {
1469
- // Where native support exists, assume it
1470
- if (nativeDefineProperty && (object === window || object === document || object === Element.prototype || object instanceof Element)) {
1471
- return nativeDefineProperty(object, property, descriptor);
1472
- }
1473
-
1474
- if (object === null || !(object instanceof Object || typeof object === 'object')) {
1475
- throw new TypeError('Object.defineProperty called on non-object');
1476
- }
1477
-
1478
- if (!(descriptor instanceof Object)) {
1479
- throw new TypeError('Property description must be an object');
1480
- }
1481
-
1482
- var propertyString = String(property);
1483
- var hasValueOrWritable = 'value' in descriptor || 'writable' in descriptor;
1484
- var getterType = 'get' in descriptor && typeof descriptor.get;
1485
- var setterType = 'set' in descriptor && typeof descriptor.set; // handle descriptor.get
1486
-
1487
- if (getterType) {
1488
- if (getterType !== 'function') {
1489
- throw new TypeError('Getter must be a function');
1490
- }
1491
-
1492
- if (!supportsAccessors) {
1493
- throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
1494
- }
1495
-
1496
- if (hasValueOrWritable) {
1497
- throw new TypeError(ERR_VALUE_ACCESSORS);
1498
- }
1499
-
1500
- Object.__defineGetter__.call(object, propertyString, descriptor.get);
1501
- } else {
1502
- object[propertyString] = descriptor.value;
1503
- } // handle descriptor.set
1504
-
1505
-
1506
- if (setterType) {
1507
- if (setterType !== 'function') {
1508
- throw new TypeError('Setter must be a function');
1509
- }
1510
-
1511
- if (!supportsAccessors) {
1512
- throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
1513
- }
1514
-
1515
- if (hasValueOrWritable) {
1516
- throw new TypeError(ERR_VALUE_ACCESSORS);
1517
- }
1518
-
1519
- Object.__defineSetter__.call(object, propertyString, descriptor.set);
1520
- } // OK to define value unconditionally - if a getter has been specified as well, an error would be thrown above
1521
-
1522
-
1523
- if ('value' in descriptor) {
1524
- object[propertyString] = descriptor.value;
1525
- }
1526
-
1527
- return object;
1528
- };
1529
- })(Object.defineProperty);
1530
- }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof commonjsGlobal && commonjsGlobal || {});
1531
- (function (undefined) {
1532
- // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-service/master/packages/polyfill-library/polyfills/DOMTokenList/detect.js
1533
- var detect = 'DOMTokenList' in this && function (x) {
1534
- return 'classList' in x ? !x.classList.toggle('x', false) && !x.className : true;
1535
- }(document.createElement('x'));
1536
-
1537
- if (detect) return; // Polyfill from https://raw.githubusercontent.com/Financial-Times/polyfill-service/master/packages/polyfill-library/polyfills/DOMTokenList/polyfill.js
1538
-
1539
- (function (global) {
1540
- var nativeImpl = "DOMTokenList" in global && global.DOMTokenList;
1541
-
1542
- if (!nativeImpl || !!document.createElementNS && !!document.createElementNS('http://www.w3.org/2000/svg', 'svg') && !(document.createElementNS("http://www.w3.org/2000/svg", "svg").classList instanceof DOMTokenList)) {
1543
- global.DOMTokenList = function () {
1544
- // eslint-disable-line no-unused-vars
1545
- var dpSupport = true;
1546
-
1547
- var defineGetter = function (object, name, fn, configurable) {
1548
- if (Object.defineProperty) Object.defineProperty(object, name, {
1549
- configurable: false === dpSupport ? true : !!configurable,
1550
- get: fn
1551
- });else object.__defineGetter__(name, fn);
1552
- };
1553
- /** Ensure the browser allows Object.defineProperty to be used on native JavaScript objects. */
1554
-
1555
-
1556
- try {
1557
- defineGetter({}, "support");
1558
- } catch (e) {
1559
- dpSupport = false;
1560
- }
1561
-
1562
- var _DOMTokenList = function (el, prop) {
1563
- var that = this;
1564
- var tokens = [];
1565
- var tokenMap = {};
1566
- var length = 0;
1567
- var maxLength = 0;
1568
-
1569
- var addIndexGetter = function (i) {
1570
- defineGetter(that, i, function () {
1571
- preop();
1572
- return tokens[i];
1573
- }, false);
1574
- };
1575
-
1576
- var reindex = function () {
1577
- /** Define getter functions for array-like access to the tokenList's contents. */
1578
- if (length >= maxLength) for (; maxLength < length; ++maxLength) {
1579
- addIndexGetter(maxLength);
1580
- }
1581
- };
1582
- /** Helper function called at the start of each class method. Internal use only. */
1583
-
1584
-
1585
- var preop = function () {
1586
- var error;
1587
- var i;
1588
- var args = arguments;
1589
- var rSpace = /\s+/;
1590
- /** Validate the token/s passed to an instance method, if any. */
1591
-
1592
- if (args.length) for (i = 0; i < args.length; ++i) if (rSpace.test(args[i])) {
1593
- error = new SyntaxError('String "' + args[i] + '" ' + "contains" + ' an invalid character');
1594
- error.code = 5;
1595
- error.name = "InvalidCharacterError";
1596
- throw error;
1597
- }
1598
- /** Split the new value apart by whitespace*/
1599
-
1600
- if (typeof el[prop] === "object") {
1601
- tokens = ("" + el[prop].baseVal).replace(/^\s+|\s+$/g, "").split(rSpace);
1602
- } else {
1603
- tokens = ("" + el[prop]).replace(/^\s+|\s+$/g, "").split(rSpace);
1604
- }
1605
- /** Avoid treating blank strings as single-item token lists */
1606
-
1607
-
1608
- if ("" === tokens[0]) tokens = [];
1609
- /** Repopulate the internal token lists */
1610
-
1611
- tokenMap = {};
1612
-
1613
- for (i = 0; i < tokens.length; ++i) tokenMap[tokens[i]] = true;
1614
-
1615
- length = tokens.length;
1616
- reindex();
1617
- };
1618
- /** Populate our internal token list if the targeted attribute of the subject element isn't empty. */
1619
-
1620
-
1621
- preop();
1622
- /** Return the number of tokens in the underlying string. Read-only. */
1623
-
1624
- defineGetter(that, "length", function () {
1625
- preop();
1626
- return length;
1627
- });
1628
- /** Override the default toString/toLocaleString methods to return a space-delimited list of tokens when typecast. */
1629
-
1630
- that.toLocaleString = that.toString = function () {
1631
- preop();
1632
- return tokens.join(" ");
1633
- };
1634
-
1635
- that.item = function (idx) {
1636
- preop();
1637
- return tokens[idx];
1638
- };
1639
-
1640
- that.contains = function (token) {
1641
- preop();
1642
- return !!tokenMap[token];
1643
- };
1644
-
1645
- that.add = function () {
1646
- preop.apply(that, args = arguments);
1647
-
1648
- for (var args, token, i = 0, l = args.length; i < l; ++i) {
1649
- token = args[i];
1650
-
1651
- if (!tokenMap[token]) {
1652
- tokens.push(token);
1653
- tokenMap[token] = true;
1654
- }
1655
- }
1656
- /** Update the targeted attribute of the attached element if the token list's changed. */
1657
-
1658
-
1659
- if (length !== tokens.length) {
1660
- length = tokens.length >>> 0;
1661
-
1662
- if (typeof el[prop] === "object") {
1663
- el[prop].baseVal = tokens.join(" ");
1664
- } else {
1665
- el[prop] = tokens.join(" ");
1666
- }
1667
-
1668
- reindex();
1669
- }
1670
- };
1671
-
1672
- that.remove = function () {
1673
- preop.apply(that, args = arguments);
1674
- /** Build a hash of token names to compare against when recollecting our token list. */
1675
-
1676
- for (var args, ignore = {}, i = 0, t = []; i < args.length; ++i) {
1677
- ignore[args[i]] = true;
1678
- delete tokenMap[args[i]];
1679
- }
1680
- /** Run through our tokens list and reassign only those that aren't defined in the hash declared above. */
1681
-
1682
-
1683
- for (i = 0; i < tokens.length; ++i) if (!ignore[tokens[i]]) t.push(tokens[i]);
1684
-
1685
- tokens = t;
1686
- length = t.length >>> 0;
1687
- /** Update the targeted attribute of the attached element. */
1688
-
1689
- if (typeof el[prop] === "object") {
1690
- el[prop].baseVal = tokens.join(" ");
1691
- } else {
1692
- el[prop] = tokens.join(" ");
1693
- }
1694
-
1695
- reindex();
1696
- };
1697
-
1698
- that.toggle = function (token, force) {
1699
- preop.apply(that, [token]);
1700
- /** Token state's being forced. */
1701
-
1702
- if (undefined !== force) {
1703
- if (force) {
1704
- that.add(token);
1705
- return true;
1706
- } else {
1707
- that.remove(token);
1708
- return false;
1709
- }
1710
- }
1711
- /** Token already exists in tokenList. Remove it, and return FALSE. */
1712
-
1713
-
1714
- if (tokenMap[token]) {
1715
- that.remove(token);
1716
- return false;
1717
- }
1718
- /** Otherwise, add the token and return TRUE. */
1719
-
1720
-
1721
- that.add(token);
1722
- return true;
1723
- };
1724
-
1725
- return that;
1726
- };
1727
-
1728
- return _DOMTokenList;
1729
- }();
1730
- } // Add second argument to native DOMTokenList.toggle() if necessary
1731
-
1732
-
1733
- (function () {
1734
- var e = document.createElement('span');
1735
- if (!('classList' in e)) return;
1736
- e.classList.toggle('x', false);
1737
- if (!e.classList.contains('x')) return;
1738
-
1739
- e.classList.constructor.prototype.toggle = function toggle(token
1740
- /*, force*/
1741
- ) {
1742
- var force = arguments[1];
1743
-
1744
- if (force === undefined) {
1745
- var add = !this.contains(token);
1746
- this[add ? 'add' : 'remove'](token);
1747
- return add;
1748
- }
1749
-
1750
- force = !!force;
1751
- this[force ? 'add' : 'remove'](token);
1752
- return force;
1753
- };
1754
- })(); // Add multiple arguments to native DOMTokenList.add() if necessary
1755
-
1756
-
1757
- (function () {
1758
- var e = document.createElement('span');
1759
- if (!('classList' in e)) return;
1760
- e.classList.add('a', 'b');
1761
- if (e.classList.contains('b')) return;
1762
- var native = e.classList.constructor.prototype.add;
1763
-
1764
- e.classList.constructor.prototype.add = function () {
1765
- var args = arguments;
1766
- var l = arguments.length;
1767
-
1768
- for (var i = 0; i < l; i++) {
1769
- native.call(this, args[i]);
1770
- }
1771
- };
1772
- })(); // Add multiple arguments to native DOMTokenList.remove() if necessary
1773
-
1774
-
1775
- (function () {
1776
- var e = document.createElement('span');
1777
- if (!('classList' in e)) return;
1778
- e.classList.add('a');
1779
- e.classList.add('b');
1780
- e.classList.remove('a', 'b');
1781
- if (!e.classList.contains('b')) return;
1782
- var native = e.classList.constructor.prototype.remove;
1783
-
1784
- e.classList.constructor.prototype.remove = function () {
1785
- var args = arguments;
1786
- var l = arguments.length;
1787
-
1788
- for (var i = 0; i < l; i++) {
1789
- native.call(this, args[i]);
1790
- }
1791
- };
1792
- })();
1793
- })(this);
1794
- }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof commonjsGlobal && commonjsGlobal || {});
1795
- (function (undefined) {
1796
- // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Document/detect.js
1797
- var detect = ("Document" in this);
1798
- if (detect) return; // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Document&flags=always
1799
-
1800
- if (typeof WorkerGlobalScope === "undefined" && typeof importScripts !== "function") {
1801
- if (this.HTMLDocument) {
1802
- // IE8
1803
- // HTMLDocument is an extension of Document. If the browser has HTMLDocument but not Document, the former will suffice as an alias for the latter.
1804
- this.Document = this.HTMLDocument;
1805
- } else {
1806
- // 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.
1807
- this.Document = this.HTMLDocument = document.constructor = new Function('return function Document() {}')();
1808
- this.Document.prototype = document;
1809
- }
1810
- }
1811
- }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof commonjsGlobal && commonjsGlobal || {});
1812
- (function (undefined) {
1813
- // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Element/detect.js
1814
- var detect = 'Element' in this && 'HTMLElement' in this;
1815
- if (detect) return; // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Element&flags=always
1816
-
1817
- (function () {
1818
- // IE8
1819
- if (window.Element && !window.HTMLElement) {
1820
- window.HTMLElement = window.Element;
1821
- return;
1822
- } // create Element constructor
1823
-
1824
-
1825
- window.Element = window.HTMLElement = new Function('return function Element() {}')(); // generate sandboxed iframe
1826
-
1827
- var vbody = document.appendChild(document.createElement('body'));
1828
- var frame = vbody.appendChild(document.createElement('iframe')); // use sandboxed iframe to replicate Element functionality
1829
-
1830
- var frameDocument = frame.contentWindow.document;
1831
- var prototype = Element.prototype = frameDocument.appendChild(frameDocument.createElement('*'));
1832
- var cache = {}; // polyfill Element.prototype on an element
1833
-
1834
- var shiv = function (element, deep) {
1835
- var childNodes = element.childNodes || [],
1836
- index = -1,
1837
- key,
1838
- value,
1839
- childNode;
1840
-
1841
- if (element.nodeType === 1 && element.constructor !== Element) {
1842
- element.constructor = Element;
1843
-
1844
- for (key in cache) {
1845
- value = cache[key];
1846
- element[key] = value;
1847
- }
1848
- }
1849
-
1850
- while (childNode = deep && childNodes[++index]) {
1851
- shiv(childNode, deep);
1852
- }
1853
-
1854
- return element;
1855
- };
1856
-
1857
- var elements = document.getElementsByTagName('*');
1858
- var nativeCreateElement = document.createElement;
1859
- var interval;
1860
- var loopLimit = 100;
1861
- prototype.attachEvent('onpropertychange', function (event) {
1862
- var propertyName = event.propertyName,
1863
- nonValue = !cache.hasOwnProperty(propertyName),
1864
- newValue = prototype[propertyName],
1865
- oldValue = cache[propertyName],
1866
- index = -1,
1867
- element;
1868
-
1869
- while (element = elements[++index]) {
1870
- if (element.nodeType === 1) {
1871
- if (nonValue || element[propertyName] === oldValue) {
1872
- element[propertyName] = newValue;
1873
- }
1874
- }
1875
- }
1876
-
1877
- cache[propertyName] = newValue;
1878
- });
1879
- prototype.constructor = Element;
1880
-
1881
- if (!prototype.hasAttribute) {
1882
- // <Element>.hasAttribute
1883
- prototype.hasAttribute = function hasAttribute(name) {
1884
- return this.getAttribute(name) !== null;
1885
- };
1886
- } // Apply Element prototype to the pre-existing DOM as soon as the body element appears.
1887
-
1888
-
1889
- function bodyCheck() {
1890
- if (!loopLimit--) clearTimeout(interval);
1891
-
1892
- if (document.body && !document.body.prototype && /(complete|interactive)/.test(document.readyState)) {
1893
- shiv(document, true);
1894
- if (interval && document.body.prototype) clearTimeout(interval);
1895
- return !!document.body.prototype;
1896
- }
1897
-
1898
- return false;
1899
- }
1900
-
1901
- if (!bodyCheck()) {
1902
- document.onreadystatechange = bodyCheck;
1903
- interval = setInterval(bodyCheck, 25);
1904
- } // Apply to any new elements created after load
1905
-
1906
-
1907
- document.createElement = function createElement(nodeName) {
1908
- var element = nativeCreateElement(String(nodeName).toLowerCase());
1909
- return shiv(element);
1910
- }; // remove sandboxed iframe
1911
-
1912
-
1913
- document.removeChild(vbody);
1914
- })();
1915
- }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof commonjsGlobal && commonjsGlobal || {});
1916
- (function (undefined) {
1917
- // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-service/8717a9e04ac7aff99b4980fbedead98036b0929a/packages/polyfill-library/polyfills/Element/prototype/classList/detect.js
1918
- var detect = 'document' in this && "classList" in document.documentElement && 'Element' in this && 'classList' in Element.prototype && function () {
1919
- var e = document.createElement('span');
1920
- e.classList.add('a', 'b');
1921
- return e.classList.contains('b');
1922
- }();
1923
-
1924
- if (detect) return; // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Element.prototype.classList&flags=always
1925
-
1926
- (function (global) {
1927
- var dpSupport = true;
1928
-
1929
- var defineGetter = function (object, name, fn, configurable) {
1930
- if (Object.defineProperty) Object.defineProperty(object, name, {
1931
- configurable: false === dpSupport ? true : !!configurable,
1932
- get: fn
1933
- });else object.__defineGetter__(name, fn);
1934
- };
1935
- /** Ensure the browser allows Object.defineProperty to be used on native JavaScript objects. */
1936
-
1937
-
1938
- try {
1939
- defineGetter({}, "support");
1940
- } catch (e) {
1941
- dpSupport = false;
1942
- }
1943
- /** Polyfills a property with a DOMTokenList */
1944
-
1945
-
1946
- var addProp = function (o, name, attr) {
1947
- defineGetter(o.prototype, name, function () {
1948
- var tokenList;
1949
- var THIS = this,
1950
-
1951
- /** Prevent this from firing twice for some reason. What the hell, IE. */
1952
- gibberishProperty = "__defineGetter__" + "DEFINE_PROPERTY" + name;
1953
- if (THIS[gibberishProperty]) return tokenList;
1954
- THIS[gibberishProperty] = true;
1955
- /**
1956
- * IE8 can't define properties on native JavaScript objects, so we'll use a dumb hack instead.
1957
- *
1958
- * What this is doing is creating a dummy element ("reflection") inside a detached phantom node ("mirror")
1959
- * that serves as the target of Object.defineProperty instead. While we could simply use the subject HTML
1960
- * element instead, this would conflict with element types which use indexed properties (such as forms and
1961
- * select lists).
1962
- */
1963
-
1964
- if (false === dpSupport) {
1965
- var visage;
1966
- var mirror = addProp.mirror || document.createElement("div");
1967
- var reflections = mirror.childNodes;
1968
- var l = reflections.length;
1969
-
1970
- for (var i = 0; i < l; ++i) if (reflections[i]._R === THIS) {
1971
- visage = reflections[i];
1972
- break;
1973
- }
1974
- /** Couldn't find an element's reflection inside the mirror. Materialise one. */
1975
-
1976
-
1977
- visage || (visage = mirror.appendChild(document.createElement("div")));
1978
- tokenList = DOMTokenList.call(visage, THIS, attr);
1979
- } else tokenList = new DOMTokenList(THIS, attr);
1980
-
1981
- defineGetter(THIS, name, function () {
1982
- return tokenList;
1983
- });
1984
- delete THIS[gibberishProperty];
1985
- return tokenList;
1986
- }, true);
1987
- };
1988
-
1989
- addProp(global.Element, "classList", "className");
1990
- addProp(global.HTMLElement, "classList", "className");
1991
- addProp(global.HTMLLinkElement, "relList", "rel");
1992
- addProp(global.HTMLAnchorElement, "relList", "rel");
1993
- addProp(global.HTMLAreaElement, "relList", "rel");
1994
- })(this);
1995
- }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof commonjsGlobal && commonjsGlobal || {});
1996
- });
1997
- });
1998
-
1999
- // https://github.com/alphagov/govuk-frontend/blob/main/src/govuk/components/character-count/character-count.js
2000
- // with the change to support Welsh language messages. At the moment, there is no ability to pass
2001
- // in custom messages to the component for the dynamic count. If GDS release a version supporting
2002
- // custom dynamic count messages, this version should be removed.
2003
- // Linting is disabled to keep aligned with govuk-frontend
2004
-
2005
- /* eslint-disable */
2006
-
2007
- function CharacterCount($module) {
2008
- this.$module = $module;
2009
- this.$textarea = $module.querySelector('.hmrc-js-character-count');
2010
- this.$visibleCountMessage = null;
2011
- this.$screenReaderCountMessage = null;
2012
- this.lastInputTimestamp = null;
2013
- }
2014
-
2015
- CharacterCount.prototype.defaults = {
2016
- characterCountAttribute: 'data-maxlength',
2017
- wordCountAttribute: 'data-maxwords'
2018
- }; // Initialize component
2019
-
2020
- CharacterCount.prototype.init = function () {
2021
- // Check that required elements are present
2022
- if (!this.$textarea) {
2023
- return;
2024
- } // Check for module
2025
-
2026
-
2027
- var $module = this.$module;
2028
- var $textarea = this.$textarea;
2029
- var $fallbackLimitMessage = document.getElementById($textarea.id + '-info'); // Move the fallback count message to be immediately after the textarea
2030
- // Kept for backwards compatibility
2031
-
2032
- $textarea.insertAdjacentElement('afterend', $fallbackLimitMessage); // Create the *screen reader* specific live-updating counter
2033
- // This doesn't need any styling classes, as it is never visible
2034
-
2035
- var $screenReaderCountMessage = document.createElement('div');
2036
- $screenReaderCountMessage.className = 'hmrc-character-count__sr-status govuk-visually-hidden';
2037
- $screenReaderCountMessage.setAttribute('aria-live', 'polite');
2038
- this.$screenReaderCountMessage = $screenReaderCountMessage;
2039
- $fallbackLimitMessage.insertAdjacentElement('afterend', $screenReaderCountMessage); // Create our live-updating counter element, copying the classes from the
2040
- // fallback element for backwards compatibility as these may have been configured
2041
-
2042
- var $visibleCountMessage = document.createElement('div');
2043
- $visibleCountMessage.className = $fallbackLimitMessage.className;
2044
- $visibleCountMessage.classList.add('hmrc-character-count__status');
2045
- $visibleCountMessage.setAttribute('aria-hidden', 'true');
2046
- this.$visibleCountMessage = $visibleCountMessage;
2047
- $fallbackLimitMessage.insertAdjacentElement('afterend', $visibleCountMessage); // Hide the fallback limit message
2048
-
2049
- $fallbackLimitMessage.classList.add('govuk-visually-hidden'); // Read options set using dataset ('data-' values)
2050
-
2051
- this.options = this.getDataset($module); // Determine the limit attribute (characters or words)
2052
-
2053
- var countAttribute = this.defaults.characterCountAttribute;
2054
-
2055
- if (this.options.maxwords) {
2056
- countAttribute = this.defaults.wordCountAttribute;
2057
- } // Save the element limit
2058
-
2059
-
2060
- this.maxLength = $module.getAttribute(countAttribute); // Check for limit
2061
-
2062
- if (!this.maxLength) {
2063
- return;
2064
- } // Remove hard limit if set
2065
-
2066
-
2067
- $textarea.removeAttribute('maxlength');
2068
- this.bindChangeEvents(); // When the page is restored after navigating 'back' in some browsers the
2069
- // state of the character count is not restored until *after* the DOMContentLoaded
2070
- // event is fired, so we need to manually update it after the pageshow event
2071
- // in browsers that support it.
2072
-
2073
- if ('onpageshow' in window) {
2074
- window.addEventListener('pageshow', this.updateCountMessage.bind(this));
2075
- } else {
2076
- window.addEventListener('DOMContentLoaded', this.updateCountMessage.bind(this));
2077
- }
2078
-
2079
- this.updateCountMessage();
2080
- }; // Read data attributes
2081
-
2082
-
2083
- CharacterCount.prototype.getDataset = function (element) {
2084
- var dataset = {};
2085
- var attributes = element.attributes;
2086
-
2087
- if (attributes) {
2088
- for (var i = 0; i < attributes.length; i++) {
2089
- var attribute = attributes[i];
2090
- var match = attribute.name.match(/^data-(.+)/);
2091
-
2092
- if (match) {
2093
- dataset[match[1]] = attribute.value;
2094
- }
2095
- }
2096
- }
2097
-
2098
- return dataset;
2099
- }; // Counts characters or words in text
2100
-
2101
-
2102
- CharacterCount.prototype.count = function (text) {
2103
- var length;
2104
-
2105
- if (this.options.maxwords) {
2106
- var tokens = text.match(/\S+/g) || []; // Matches consecutive non-whitespace chars
2107
-
2108
- length = tokens.length;
2109
- } else {
2110
- length = text.length;
2111
- }
2112
-
2113
- return length;
2114
- }; // Bind input propertychange to the elements and update based on the change
2115
-
2116
-
2117
- CharacterCount.prototype.bindChangeEvents = function () {
2118
- var $textarea = this.$textarea;
2119
- $textarea.addEventListener('keyup', this.handleKeyUp.bind(this)); // Bind focus/blur events to start/stop polling
2120
-
2121
- $textarea.addEventListener('focus', this.handleFocus.bind(this));
2122
- $textarea.addEventListener('blur', this.handleBlur.bind(this));
2123
- }; // Speech recognition software such as Dragon NaturallySpeaking will modify the
2124
- // fields by directly changing its `value`. These changes don't trigger events
2125
- // in JavaScript, so we need to poll to handle when and if they occur.
2126
-
2127
-
2128
- CharacterCount.prototype.checkIfValueChanged = function () {
2129
- if (!this.$textarea.oldValue) this.$textarea.oldValue = '';
2130
-
2131
- if (this.$textarea.value !== this.$textarea.oldValue) {
2132
- this.$textarea.oldValue = this.$textarea.value;
2133
- this.updateCountMessage();
2134
- }
2135
- }; // Helper function to update both the visible and screen reader-specific
2136
- // counters simultaneously (e.g. on init)
2137
-
2138
-
2139
- CharacterCount.prototype.updateCountMessage = function () {
2140
- this.updateVisibleCountMessage();
2141
- this.updateScreenReaderCountMessage();
2142
- }; // Update visible counter
2143
-
2144
-
2145
- CharacterCount.prototype.updateVisibleCountMessage = function () {
2146
- var $textarea = this.$textarea;
2147
- var $visibleCountMessage = this.$visibleCountMessage;
2148
- var remainingNumber = this.maxLength - this.count($textarea.value); // If input is over the threshold, remove the disabled class which renders the
2149
- // counter invisible.
2150
-
2151
- if (this.isOverThreshold()) {
2152
- $visibleCountMessage.classList.remove('hmrc-character-count__message--disabled');
2153
- } else {
2154
- $visibleCountMessage.classList.add('hmrc-character-count__message--disabled');
2155
- } // Update styles
2156
-
2157
-
2158
- if (remainingNumber < 0) {
2159
- $textarea.classList.add('govuk-textarea--error');
2160
- $visibleCountMessage.classList.remove('govuk-hint');
2161
- $visibleCountMessage.classList.add('govuk-error-message');
2162
- } else {
2163
- $textarea.classList.remove('govuk-textarea--error');
2164
- $visibleCountMessage.classList.remove('govuk-error-message');
2165
- $visibleCountMessage.classList.add('govuk-hint');
2166
- } // Update message
2167
-
2168
-
2169
- $visibleCountMessage.innerHTML = this.formattedUpdateMessage();
2170
- }; // Update screen reader-specific counter
2171
-
2172
-
2173
- CharacterCount.prototype.updateScreenReaderCountMessage = function () {
2174
- var $screenReaderCountMessage = this.$screenReaderCountMessage; // If over the threshold, remove the aria-hidden attribute, allowing screen
2175
- // readers to announce the content of the element.
2176
-
2177
- if (this.isOverThreshold()) {
2178
- $screenReaderCountMessage.removeAttribute('aria-hidden');
2179
- } else {
2180
- $screenReaderCountMessage.setAttribute('aria-hidden', true);
2181
- } // Update message
2182
-
2183
-
2184
- $screenReaderCountMessage.innerHTML = this.formattedUpdateMessage();
2185
- }; // Format update message
2186
-
2187
-
2188
- CharacterCount.prototype.formattedUpdateMessage = function () {
2189
- var $textarea = this.$textarea;
2190
- var options = this.options;
2191
- var remainingNumber = this.maxLength - this.count($textarea.value);
2192
- var isWelsh = this.options.language === 'cy';
2193
- var charVerb;
2194
- var charNoun;
2195
- var charStartMessage = isWelsh ? 'Mae gennych ' : 'You have ';
2196
-
2197
- if (options.maxwords) {
2198
- if (remainingNumber === -1 || remainingNumber === 1) {
2199
- charNoun = isWelsh ? 'gair' : 'word';
2200
- } else {
2201
- charNoun = isWelsh ? 'o eiriau' : 'words';
2202
- }
2203
- } else if (remainingNumber === -1 || remainingNumber === 1) {
2204
- charNoun = isWelsh ? 'cymeriad' : 'character';
2205
- } else {
2206
- charNoun = isWelsh ? 'o gymeriadau' : 'characters';
2207
- }
2208
-
2209
- if (remainingNumber < 0) {
2210
- charVerb = isWelsh ? 'yn ormod' : 'too many';
2211
- } else {
2212
- charVerb = isWelsh ? 'yn weddill' : 'remaining';
2213
- }
2214
-
2215
- var displayNumber = Math.abs(remainingNumber);
2216
- return charStartMessage + displayNumber + ' ' + charNoun + ' ' + charVerb;
2217
- }; // Checks whether the value is over the configured threshold for the input.
2218
- // If there is no configured threshold, it is set to 0 and this function will
2219
- // always return true.
2220
-
2221
-
2222
- CharacterCount.prototype.isOverThreshold = function () {
2223
- var $textarea = this.$textarea;
2224
- var options = this.options; // Determine the remaining number of characters/words
2225
-
2226
- var currentLength = this.count($textarea.value);
2227
- var maxLength = this.maxLength; // Set threshold if presented in options
2228
-
2229
- var thresholdPercent = options.threshold ? options.threshold : 0;
2230
- var thresholdValue = maxLength * thresholdPercent / 100;
2231
- return thresholdValue <= currentLength;
2232
- }; // Update the visible character counter and keep track of when the last update
2233
- // happened for each keypress
2234
-
2235
-
2236
- CharacterCount.prototype.handleKeyUp = function () {
2237
- this.updateVisibleCountMessage();
2238
- this.lastInputTimestamp = Date.now();
2239
- };
2240
-
2241
- CharacterCount.prototype.handleFocus = function () {
2242
- // If the field is focused, and a keyup event hasn't been detected for at
2243
- // least 1000 ms (1 second), then run the manual change check.
2244
- // This is so that the update triggered by the manual comparison doesn't
2245
- // conflict with debounced KeyboardEvent updates.
2246
- this.valueChecker = setInterval(function () {
2247
- if (!this.lastInputTimestamp || Date.now() - 500 >= this.lastInputTimestamp) {
2248
- this.checkIfValueChanged();
2249
- }
2250
- }.bind(this), 1000);
2251
- };
2252
-
2253
- CharacterCount.prototype.handleBlur = function () {
2254
- // Cancel value checking on blur
2255
- clearInterval(this.valueChecker);
2256
- };
2257
-
2258
976
  (function (undefined) {
2259
977
  // Detection from https://github.com/Financial-Times/polyfill-library/blob/987630a085e29226da16b5dc542042c687560191/polyfills/Array/prototype/forEach/detect.js
2260
978
  var detect = ('forEach' in Array.prototype);
@@ -3138,10 +1856,6 @@
3138
1856
  nodeListForEach($BackLinks, function ($BackLink) {
3139
1857
  new BackLinkHelper($BackLink, window, document).init();
3140
1858
  });
3141
- var $CharacterCounts = document.querySelectorAll('[data-module="hmrc-character-count"]');
3142
- nodeListForEach($CharacterCounts, function ($CharacterCount) {
3143
- new CharacterCount($CharacterCount).init();
3144
- });
3145
1859
  }
3146
1860
 
3147
1861
  var all = {
@@ -3149,7 +1863,6 @@
3149
1863
  AccountMenu: AccountMenu,
3150
1864
  TimeoutDialog: TimeoutDialog,
3151
1865
  UserResearchBanner: UserResearchBanner,
3152
- CharacterCount: CharacterCount,
3153
1866
  BackLinkHelper: BackLinkHelper
3154
1867
  };
3155
1868