katalyst-govuk-formbuilder 1.0.0 → 1.1.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.
- checksums.yaml +4 -4
- data/README.md +16 -3
- data/{lib/assets/stylesheets → app/assets/builds}/katalyst/govuk/formbuilder.css +0 -2
- data/app/assets/builds/katalyst/govuk/formbuilder.min.css +1 -0
- data/app/assets/javascripts/katalyst/govuk/formbuilder.js +1123 -0
- data/app/assets/javascripts/katalyst/govuk/formbuilder.min.js +1 -0
- data/config/importmap.rb +3 -0
- data/lib/katalyst/govuk/formbuilder/engine.rb +17 -3
- data/lib/katalyst/govuk/formbuilder/frontend.rb +19 -0
- data/lib/katalyst/govuk/formbuilder/version.rb +1 -1
- data/lib/katalyst/govuk/formbuilder.rb +1 -0
- metadata +9 -8
- data/lib/assets/stylesheets/katalyst/govuk/formbuilder.css.map +0 -1
@@ -0,0 +1,1123 @@
|
|
1
|
+
function nodeListForEach(nodes, callback) {
|
2
|
+
if (window.NodeList.prototype.forEach) {
|
3
|
+
return nodes.forEach(callback);
|
4
|
+
}
|
5
|
+
for (var i = 0; i < nodes.length; i++) {
|
6
|
+
callback.call(window, nodes[i], i, nodes);
|
7
|
+
}
|
8
|
+
}
|
9
|
+
|
10
|
+
(function(undefined$1) {
|
11
|
+
var detect = "Window" in this;
|
12
|
+
if (detect) return;
|
13
|
+
if (typeof WorkerGlobalScope === "undefined" && typeof importScripts !== "function") {
|
14
|
+
(function(global) {
|
15
|
+
if (global.constructor) {
|
16
|
+
global.Window = global.constructor;
|
17
|
+
} else {
|
18
|
+
(global.Window = global.constructor = new Function("return function Window() {}")()).prototype = this;
|
19
|
+
}
|
20
|
+
})(this);
|
21
|
+
}
|
22
|
+
}).call("object" === typeof window && window || "object" === typeof self && self || "object" === typeof global && global || {});
|
23
|
+
|
24
|
+
(function(undefined$1) {
|
25
|
+
var detect = "Document" in this;
|
26
|
+
if (detect) return;
|
27
|
+
if (typeof WorkerGlobalScope === "undefined" && typeof importScripts !== "function") {
|
28
|
+
if (this.HTMLDocument) {
|
29
|
+
this.Document = this.HTMLDocument;
|
30
|
+
} else {
|
31
|
+
this.Document = this.HTMLDocument = document.constructor = new Function("return function Document() {}")();
|
32
|
+
this.Document.prototype = document;
|
33
|
+
}
|
34
|
+
}
|
35
|
+
}).call("object" === typeof window && window || "object" === typeof self && self || "object" === typeof global && global || {});
|
36
|
+
|
37
|
+
(function(undefined$1) {
|
38
|
+
var detect = "Element" in this && "HTMLElement" in this;
|
39
|
+
if (detect) return;
|
40
|
+
(function() {
|
41
|
+
if (window.Element && !window.HTMLElement) {
|
42
|
+
window.HTMLElement = window.Element;
|
43
|
+
return;
|
44
|
+
}
|
45
|
+
window.Element = window.HTMLElement = new Function("return function Element() {}")();
|
46
|
+
var vbody = document.appendChild(document.createElement("body"));
|
47
|
+
var frame = vbody.appendChild(document.createElement("iframe"));
|
48
|
+
var frameDocument = frame.contentWindow.document;
|
49
|
+
var prototype = Element.prototype = frameDocument.appendChild(frameDocument.createElement("*"));
|
50
|
+
var cache = {};
|
51
|
+
var shiv = function(element, deep) {
|
52
|
+
var childNodes = element.childNodes || [], index = -1, key, value, childNode;
|
53
|
+
if (element.nodeType === 1 && element.constructor !== Element) {
|
54
|
+
element.constructor = Element;
|
55
|
+
for (key in cache) {
|
56
|
+
value = cache[key];
|
57
|
+
element[key] = value;
|
58
|
+
}
|
59
|
+
}
|
60
|
+
while (childNode = deep && childNodes[++index]) {
|
61
|
+
shiv(childNode, deep);
|
62
|
+
}
|
63
|
+
return element;
|
64
|
+
};
|
65
|
+
var elements = document.getElementsByTagName("*");
|
66
|
+
var nativeCreateElement = document.createElement;
|
67
|
+
var interval;
|
68
|
+
var loopLimit = 100;
|
69
|
+
prototype.attachEvent("onpropertychange", (function(event) {
|
70
|
+
var propertyName = event.propertyName, nonValue = !cache.hasOwnProperty(propertyName), newValue = prototype[propertyName], oldValue = cache[propertyName], index = -1, element;
|
71
|
+
while (element = elements[++index]) {
|
72
|
+
if (element.nodeType === 1) {
|
73
|
+
if (nonValue || element[propertyName] === oldValue) {
|
74
|
+
element[propertyName] = newValue;
|
75
|
+
}
|
76
|
+
}
|
77
|
+
}
|
78
|
+
cache[propertyName] = newValue;
|
79
|
+
}));
|
80
|
+
prototype.constructor = Element;
|
81
|
+
if (!prototype.hasAttribute) {
|
82
|
+
prototype.hasAttribute = function hasAttribute(name) {
|
83
|
+
return this.getAttribute(name) !== null;
|
84
|
+
};
|
85
|
+
}
|
86
|
+
function bodyCheck() {
|
87
|
+
if (!loopLimit--) clearTimeout(interval);
|
88
|
+
if (document.body && !document.body.prototype && /(complete|interactive)/.test(document.readyState)) {
|
89
|
+
shiv(document, true);
|
90
|
+
if (interval && document.body.prototype) clearTimeout(interval);
|
91
|
+
return !!document.body.prototype;
|
92
|
+
}
|
93
|
+
return false;
|
94
|
+
}
|
95
|
+
if (!bodyCheck()) {
|
96
|
+
document.onreadystatechange = bodyCheck;
|
97
|
+
interval = setInterval(bodyCheck, 25);
|
98
|
+
}
|
99
|
+
document.createElement = function createElement(nodeName) {
|
100
|
+
var element = nativeCreateElement(String(nodeName).toLowerCase());
|
101
|
+
return shiv(element);
|
102
|
+
};
|
103
|
+
document.removeChild(vbody);
|
104
|
+
})();
|
105
|
+
}).call("object" === typeof window && window || "object" === typeof self && self || "object" === typeof global && global || {});
|
106
|
+
|
107
|
+
(function(undefined$1) {
|
108
|
+
var detect = "defineProperty" in Object && function() {
|
109
|
+
try {
|
110
|
+
var a = {};
|
111
|
+
Object.defineProperty(a, "test", {
|
112
|
+
value: 42
|
113
|
+
});
|
114
|
+
return true;
|
115
|
+
} catch (e) {
|
116
|
+
return false;
|
117
|
+
}
|
118
|
+
}();
|
119
|
+
if (detect) return;
|
120
|
+
(function(nativeDefineProperty) {
|
121
|
+
var supportsAccessors = Object.prototype.hasOwnProperty("__defineGetter__");
|
122
|
+
var ERR_ACCESSORS_NOT_SUPPORTED = "Getters & setters cannot be defined on this javascript engine";
|
123
|
+
var ERR_VALUE_ACCESSORS = "A property cannot both have accessors and be writable or have a value";
|
124
|
+
Object.defineProperty = function defineProperty(object, property, descriptor) {
|
125
|
+
if (nativeDefineProperty && (object === window || object === document || object === Element.prototype || object instanceof Element)) {
|
126
|
+
return nativeDefineProperty(object, property, descriptor);
|
127
|
+
}
|
128
|
+
if (object === null || !(object instanceof Object || typeof object === "object")) {
|
129
|
+
throw new TypeError("Object.defineProperty called on non-object");
|
130
|
+
}
|
131
|
+
if (!(descriptor instanceof Object)) {
|
132
|
+
throw new TypeError("Property description must be an object");
|
133
|
+
}
|
134
|
+
var propertyString = String(property);
|
135
|
+
var hasValueOrWritable = "value" in descriptor || "writable" in descriptor;
|
136
|
+
var getterType = "get" in descriptor && typeof descriptor.get;
|
137
|
+
var setterType = "set" in descriptor && typeof descriptor.set;
|
138
|
+
if (getterType) {
|
139
|
+
if (getterType !== "function") {
|
140
|
+
throw new TypeError("Getter must be a function");
|
141
|
+
}
|
142
|
+
if (!supportsAccessors) {
|
143
|
+
throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
|
144
|
+
}
|
145
|
+
if (hasValueOrWritable) {
|
146
|
+
throw new TypeError(ERR_VALUE_ACCESSORS);
|
147
|
+
}
|
148
|
+
Object.__defineGetter__.call(object, propertyString, descriptor.get);
|
149
|
+
} else {
|
150
|
+
object[propertyString] = descriptor.value;
|
151
|
+
}
|
152
|
+
if (setterType) {
|
153
|
+
if (setterType !== "function") {
|
154
|
+
throw new TypeError("Setter must be a function");
|
155
|
+
}
|
156
|
+
if (!supportsAccessors) {
|
157
|
+
throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
|
158
|
+
}
|
159
|
+
if (hasValueOrWritable) {
|
160
|
+
throw new TypeError(ERR_VALUE_ACCESSORS);
|
161
|
+
}
|
162
|
+
Object.__defineSetter__.call(object, propertyString, descriptor.set);
|
163
|
+
}
|
164
|
+
if ("value" in descriptor) {
|
165
|
+
object[propertyString] = descriptor.value;
|
166
|
+
}
|
167
|
+
return object;
|
168
|
+
};
|
169
|
+
})(Object.defineProperty);
|
170
|
+
}).call("object" === typeof window && window || "object" === typeof self && self || "object" === typeof global && global || {});
|
171
|
+
|
172
|
+
(function(undefined$1) {
|
173
|
+
var detect = function(global) {
|
174
|
+
if (!("Event" in global)) return false;
|
175
|
+
if (typeof global.Event === "function") return true;
|
176
|
+
try {
|
177
|
+
new Event("click");
|
178
|
+
return true;
|
179
|
+
} catch (e) {
|
180
|
+
return false;
|
181
|
+
}
|
182
|
+
}(this);
|
183
|
+
if (detect) return;
|
184
|
+
(function() {
|
185
|
+
var unlistenableWindowEvents = {
|
186
|
+
click: 1,
|
187
|
+
dblclick: 1,
|
188
|
+
keyup: 1,
|
189
|
+
keypress: 1,
|
190
|
+
keydown: 1,
|
191
|
+
mousedown: 1,
|
192
|
+
mouseup: 1,
|
193
|
+
mousemove: 1,
|
194
|
+
mouseover: 1,
|
195
|
+
mouseenter: 1,
|
196
|
+
mouseleave: 1,
|
197
|
+
mouseout: 1,
|
198
|
+
storage: 1,
|
199
|
+
storagecommit: 1,
|
200
|
+
textinput: 1
|
201
|
+
};
|
202
|
+
if (typeof document === "undefined" || typeof window === "undefined") return;
|
203
|
+
function indexOf(array, element) {
|
204
|
+
var index = -1, length = array.length;
|
205
|
+
while (++index < length) {
|
206
|
+
if (index in array && array[index] === element) {
|
207
|
+
return index;
|
208
|
+
}
|
209
|
+
}
|
210
|
+
return -1;
|
211
|
+
}
|
212
|
+
var existingProto = window.Event && window.Event.prototype || null;
|
213
|
+
window.Event = Window.prototype.Event = function Event(type, eventInitDict) {
|
214
|
+
if (!type) {
|
215
|
+
throw new Error("Not enough arguments");
|
216
|
+
}
|
217
|
+
var event;
|
218
|
+
if ("createEvent" in document) {
|
219
|
+
event = document.createEvent("Event");
|
220
|
+
var bubbles = eventInitDict && eventInitDict.bubbles !== undefined$1 ? eventInitDict.bubbles : false;
|
221
|
+
var cancelable = eventInitDict && eventInitDict.cancelable !== undefined$1 ? eventInitDict.cancelable : false;
|
222
|
+
event.initEvent(type, bubbles, cancelable);
|
223
|
+
return event;
|
224
|
+
}
|
225
|
+
event = document.createEventObject();
|
226
|
+
event.type = type;
|
227
|
+
event.bubbles = eventInitDict && eventInitDict.bubbles !== undefined$1 ? eventInitDict.bubbles : false;
|
228
|
+
event.cancelable = eventInitDict && eventInitDict.cancelable !== undefined$1 ? eventInitDict.cancelable : false;
|
229
|
+
return event;
|
230
|
+
};
|
231
|
+
if (existingProto) {
|
232
|
+
Object.defineProperty(window.Event, "prototype", {
|
233
|
+
configurable: false,
|
234
|
+
enumerable: false,
|
235
|
+
writable: true,
|
236
|
+
value: existingProto
|
237
|
+
});
|
238
|
+
}
|
239
|
+
if (!("createEvent" in document)) {
|
240
|
+
window.addEventListener = Window.prototype.addEventListener = Document.prototype.addEventListener = Element.prototype.addEventListener = function addEventListener() {
|
241
|
+
var element = this, type = arguments[0], listener = arguments[1];
|
242
|
+
if (element === window && type in unlistenableWindowEvents) {
|
243
|
+
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.");
|
244
|
+
}
|
245
|
+
if (!element._events) {
|
246
|
+
element._events = {};
|
247
|
+
}
|
248
|
+
if (!element._events[type]) {
|
249
|
+
element._events[type] = function(event) {
|
250
|
+
var list = element._events[event.type].list, events = list.slice(), index = -1, length = events.length, eventElement;
|
251
|
+
event.preventDefault = function preventDefault() {
|
252
|
+
if (event.cancelable !== false) {
|
253
|
+
event.returnValue = false;
|
254
|
+
}
|
255
|
+
};
|
256
|
+
event.stopPropagation = function stopPropagation() {
|
257
|
+
event.cancelBubble = true;
|
258
|
+
};
|
259
|
+
event.stopImmediatePropagation = function stopImmediatePropagation() {
|
260
|
+
event.cancelBubble = true;
|
261
|
+
event.cancelImmediate = true;
|
262
|
+
};
|
263
|
+
event.currentTarget = element;
|
264
|
+
event.relatedTarget = event.fromElement || null;
|
265
|
+
event.target = event.target || event.srcElement || element;
|
266
|
+
event.timeStamp = (new Date).getTime();
|
267
|
+
if (event.clientX) {
|
268
|
+
event.pageX = event.clientX + document.documentElement.scrollLeft;
|
269
|
+
event.pageY = event.clientY + document.documentElement.scrollTop;
|
270
|
+
}
|
271
|
+
while (++index < length && !event.cancelImmediate) {
|
272
|
+
if (index in events) {
|
273
|
+
eventElement = events[index];
|
274
|
+
if (indexOf(list, eventElement) !== -1 && typeof eventElement === "function") {
|
275
|
+
eventElement.call(element, event);
|
276
|
+
}
|
277
|
+
}
|
278
|
+
}
|
279
|
+
};
|
280
|
+
element._events[type].list = [];
|
281
|
+
if (element.attachEvent) {
|
282
|
+
element.attachEvent("on" + type, element._events[type]);
|
283
|
+
}
|
284
|
+
}
|
285
|
+
element._events[type].list.push(listener);
|
286
|
+
};
|
287
|
+
window.removeEventListener = Window.prototype.removeEventListener = Document.prototype.removeEventListener = Element.prototype.removeEventListener = function removeEventListener() {
|
288
|
+
var element = this, type = arguments[0], listener = arguments[1], index;
|
289
|
+
if (element._events && element._events[type] && element._events[type].list) {
|
290
|
+
index = indexOf(element._events[type].list, listener);
|
291
|
+
if (index !== -1) {
|
292
|
+
element._events[type].list.splice(index, 1);
|
293
|
+
if (!element._events[type].list.length) {
|
294
|
+
if (element.detachEvent) {
|
295
|
+
element.detachEvent("on" + type, element._events[type]);
|
296
|
+
}
|
297
|
+
delete element._events[type];
|
298
|
+
}
|
299
|
+
}
|
300
|
+
}
|
301
|
+
};
|
302
|
+
window.dispatchEvent = Window.prototype.dispatchEvent = Document.prototype.dispatchEvent = Element.prototype.dispatchEvent = function dispatchEvent(event) {
|
303
|
+
if (!arguments.length) {
|
304
|
+
throw new Error("Not enough arguments");
|
305
|
+
}
|
306
|
+
if (!event || typeof event.type !== "string") {
|
307
|
+
throw new Error("DOM Events Exception 0");
|
308
|
+
}
|
309
|
+
var element = this, type = event.type;
|
310
|
+
try {
|
311
|
+
if (!event.bubbles) {
|
312
|
+
event.cancelBubble = true;
|
313
|
+
var cancelBubbleEvent = function(event) {
|
314
|
+
event.cancelBubble = true;
|
315
|
+
(element || window).detachEvent("on" + type, cancelBubbleEvent);
|
316
|
+
};
|
317
|
+
this.attachEvent("on" + type, cancelBubbleEvent);
|
318
|
+
}
|
319
|
+
this.fireEvent("on" + type, event);
|
320
|
+
} catch (error) {
|
321
|
+
event.target = element;
|
322
|
+
do {
|
323
|
+
event.currentTarget = element;
|
324
|
+
if ("_events" in element && typeof element._events[type] === "function") {
|
325
|
+
element._events[type].call(element, event);
|
326
|
+
}
|
327
|
+
if (typeof element["on" + type] === "function") {
|
328
|
+
element["on" + type].call(element, event);
|
329
|
+
}
|
330
|
+
element = element.nodeType === 9 ? element.parentWindow : element.parentNode;
|
331
|
+
} while (element && !event.cancelBubble);
|
332
|
+
}
|
333
|
+
return true;
|
334
|
+
};
|
335
|
+
document.attachEvent("onreadystatechange", (function() {
|
336
|
+
if (document.readyState === "complete") {
|
337
|
+
document.dispatchEvent(new Event("DOMContentLoaded", {
|
338
|
+
bubbles: true
|
339
|
+
}));
|
340
|
+
}
|
341
|
+
}));
|
342
|
+
}
|
343
|
+
})();
|
344
|
+
}).call("object" === typeof window && window || "object" === typeof self && self || "object" === typeof global && global || {});
|
345
|
+
|
346
|
+
(function(undefined$1) {
|
347
|
+
var detect = "bind" in Function.prototype;
|
348
|
+
if (detect) return;
|
349
|
+
Object.defineProperty(Function.prototype, "bind", {
|
350
|
+
value: function bind(that) {
|
351
|
+
var $Array = Array;
|
352
|
+
var $Object = Object;
|
353
|
+
var ObjectPrototype = $Object.prototype;
|
354
|
+
var ArrayPrototype = $Array.prototype;
|
355
|
+
var Empty = function Empty() {};
|
356
|
+
var to_string = ObjectPrototype.toString;
|
357
|
+
var hasToStringTag = typeof Symbol === "function" && typeof Symbol.toStringTag === "symbol";
|
358
|
+
var isCallable;
|
359
|
+
var fnToStr = Function.prototype.toString, tryFunctionObject = function tryFunctionObject(value) {
|
360
|
+
try {
|
361
|
+
fnToStr.call(value);
|
362
|
+
return true;
|
363
|
+
} catch (e) {
|
364
|
+
return false;
|
365
|
+
}
|
366
|
+
}, fnClass = "[object Function]", genClass = "[object GeneratorFunction]";
|
367
|
+
isCallable = function isCallable(value) {
|
368
|
+
if (typeof value !== "function") {
|
369
|
+
return false;
|
370
|
+
}
|
371
|
+
if (hasToStringTag) {
|
372
|
+
return tryFunctionObject(value);
|
373
|
+
}
|
374
|
+
var strClass = to_string.call(value);
|
375
|
+
return strClass === fnClass || strClass === genClass;
|
376
|
+
};
|
377
|
+
var array_slice = ArrayPrototype.slice;
|
378
|
+
var array_concat = ArrayPrototype.concat;
|
379
|
+
var array_push = ArrayPrototype.push;
|
380
|
+
var max = Math.max;
|
381
|
+
var target = this;
|
382
|
+
if (!isCallable(target)) {
|
383
|
+
throw new TypeError("Function.prototype.bind called on incompatible " + target);
|
384
|
+
}
|
385
|
+
var args = array_slice.call(arguments, 1);
|
386
|
+
var bound;
|
387
|
+
var binder = function() {
|
388
|
+
if (this instanceof bound) {
|
389
|
+
var result = target.apply(this, array_concat.call(args, array_slice.call(arguments)));
|
390
|
+
if ($Object(result) === result) {
|
391
|
+
return result;
|
392
|
+
}
|
393
|
+
return this;
|
394
|
+
} else {
|
395
|
+
return target.apply(that, array_concat.call(args, array_slice.call(arguments)));
|
396
|
+
}
|
397
|
+
};
|
398
|
+
var boundLength = max(0, target.length - args.length);
|
399
|
+
var boundArgs = [];
|
400
|
+
for (var i = 0; i < boundLength; i++) {
|
401
|
+
array_push.call(boundArgs, "$" + i);
|
402
|
+
}
|
403
|
+
bound = Function("binder", "return function (" + boundArgs.join(",") + "){ return binder.apply(this, arguments); }")(binder);
|
404
|
+
if (target.prototype) {
|
405
|
+
Empty.prototype = target.prototype;
|
406
|
+
bound.prototype = new Empty;
|
407
|
+
Empty.prototype = null;
|
408
|
+
}
|
409
|
+
return bound;
|
410
|
+
}
|
411
|
+
});
|
412
|
+
}).call("object" === typeof window && window || "object" === typeof self && self || "object" === typeof global && global || {});
|
413
|
+
|
414
|
+
var KEY_SPACE = 32;
|
415
|
+
|
416
|
+
var DEBOUNCE_TIMEOUT_IN_SECONDS = 1;
|
417
|
+
|
418
|
+
function Button($module) {
|
419
|
+
this.$module = $module;
|
420
|
+
this.debounceFormSubmitTimer = null;
|
421
|
+
}
|
422
|
+
|
423
|
+
Button.prototype.handleKeyDown = function(event) {
|
424
|
+
var target = event.target;
|
425
|
+
if (target.getAttribute("role") === "button" && event.keyCode === KEY_SPACE) {
|
426
|
+
event.preventDefault();
|
427
|
+
target.click();
|
428
|
+
}
|
429
|
+
};
|
430
|
+
|
431
|
+
Button.prototype.debounce = function(event) {
|
432
|
+
var target = event.target;
|
433
|
+
if (target.getAttribute("data-prevent-double-click") !== "true") {
|
434
|
+
return;
|
435
|
+
}
|
436
|
+
if (this.debounceFormSubmitTimer) {
|
437
|
+
event.preventDefault();
|
438
|
+
return false;
|
439
|
+
}
|
440
|
+
this.debounceFormSubmitTimer = setTimeout(function() {
|
441
|
+
this.debounceFormSubmitTimer = null;
|
442
|
+
}.bind(this), DEBOUNCE_TIMEOUT_IN_SECONDS * 1e3);
|
443
|
+
};
|
444
|
+
|
445
|
+
Button.prototype.init = function() {
|
446
|
+
this.$module.addEventListener("keydown", this.handleKeyDown);
|
447
|
+
this.$module.addEventListener("click", this.debounce);
|
448
|
+
};
|
449
|
+
|
450
|
+
(function(undefined$1) {
|
451
|
+
var detect = "DOMTokenList" in this && function(x) {
|
452
|
+
return "classList" in x ? !x.classList.toggle("x", false) && !x.className : true;
|
453
|
+
}(document.createElement("x"));
|
454
|
+
if (detect) return;
|
455
|
+
(function(global) {
|
456
|
+
var nativeImpl = "DOMTokenList" in global && global.DOMTokenList;
|
457
|
+
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)) {
|
458
|
+
global.DOMTokenList = function() {
|
459
|
+
var dpSupport = true;
|
460
|
+
var defineGetter = function(object, name, fn, configurable) {
|
461
|
+
if (Object.defineProperty) Object.defineProperty(object, name, {
|
462
|
+
configurable: false === dpSupport ? true : !!configurable,
|
463
|
+
get: fn
|
464
|
+
}); else object.__defineGetter__(name, fn);
|
465
|
+
};
|
466
|
+
try {
|
467
|
+
defineGetter({}, "support");
|
468
|
+
} catch (e) {
|
469
|
+
dpSupport = false;
|
470
|
+
}
|
471
|
+
var _DOMTokenList = function(el, prop) {
|
472
|
+
var that = this;
|
473
|
+
var tokens = [];
|
474
|
+
var tokenMap = {};
|
475
|
+
var length = 0;
|
476
|
+
var maxLength = 0;
|
477
|
+
var addIndexGetter = function(i) {
|
478
|
+
defineGetter(that, i, (function() {
|
479
|
+
preop();
|
480
|
+
return tokens[i];
|
481
|
+
}), false);
|
482
|
+
};
|
483
|
+
var reindex = function() {
|
484
|
+
if (length >= maxLength) for (;maxLength < length; ++maxLength) {
|
485
|
+
addIndexGetter(maxLength);
|
486
|
+
}
|
487
|
+
};
|
488
|
+
var preop = function() {
|
489
|
+
var error;
|
490
|
+
var i;
|
491
|
+
var args = arguments;
|
492
|
+
var rSpace = /\s+/;
|
493
|
+
if (args.length) for (i = 0; i < args.length; ++i) if (rSpace.test(args[i])) {
|
494
|
+
error = new SyntaxError('String "' + args[i] + '" ' + "contains" + " an invalid character");
|
495
|
+
error.code = 5;
|
496
|
+
error.name = "InvalidCharacterError";
|
497
|
+
throw error;
|
498
|
+
}
|
499
|
+
if (typeof el[prop] === "object") {
|
500
|
+
tokens = ("" + el[prop].baseVal).replace(/^\s+|\s+$/g, "").split(rSpace);
|
501
|
+
} else {
|
502
|
+
tokens = ("" + el[prop]).replace(/^\s+|\s+$/g, "").split(rSpace);
|
503
|
+
}
|
504
|
+
if ("" === tokens[0]) tokens = [];
|
505
|
+
tokenMap = {};
|
506
|
+
for (i = 0; i < tokens.length; ++i) tokenMap[tokens[i]] = true;
|
507
|
+
length = tokens.length;
|
508
|
+
reindex();
|
509
|
+
};
|
510
|
+
preop();
|
511
|
+
defineGetter(that, "length", (function() {
|
512
|
+
preop();
|
513
|
+
return length;
|
514
|
+
}));
|
515
|
+
that.toLocaleString = that.toString = function() {
|
516
|
+
preop();
|
517
|
+
return tokens.join(" ");
|
518
|
+
};
|
519
|
+
that.item = function(idx) {
|
520
|
+
preop();
|
521
|
+
return tokens[idx];
|
522
|
+
};
|
523
|
+
that.contains = function(token) {
|
524
|
+
preop();
|
525
|
+
return !!tokenMap[token];
|
526
|
+
};
|
527
|
+
that.add = function() {
|
528
|
+
preop.apply(that, args = arguments);
|
529
|
+
for (var args, token, i = 0, l = args.length; i < l; ++i) {
|
530
|
+
token = args[i];
|
531
|
+
if (!tokenMap[token]) {
|
532
|
+
tokens.push(token);
|
533
|
+
tokenMap[token] = true;
|
534
|
+
}
|
535
|
+
}
|
536
|
+
if (length !== tokens.length) {
|
537
|
+
length = tokens.length >>> 0;
|
538
|
+
if (typeof el[prop] === "object") {
|
539
|
+
el[prop].baseVal = tokens.join(" ");
|
540
|
+
} else {
|
541
|
+
el[prop] = tokens.join(" ");
|
542
|
+
}
|
543
|
+
reindex();
|
544
|
+
}
|
545
|
+
};
|
546
|
+
that.remove = function() {
|
547
|
+
preop.apply(that, args = arguments);
|
548
|
+
for (var args, ignore = {}, i = 0, t = []; i < args.length; ++i) {
|
549
|
+
ignore[args[i]] = true;
|
550
|
+
delete tokenMap[args[i]];
|
551
|
+
}
|
552
|
+
for (i = 0; i < tokens.length; ++i) if (!ignore[tokens[i]]) t.push(tokens[i]);
|
553
|
+
tokens = t;
|
554
|
+
length = t.length >>> 0;
|
555
|
+
if (typeof el[prop] === "object") {
|
556
|
+
el[prop].baseVal = tokens.join(" ");
|
557
|
+
} else {
|
558
|
+
el[prop] = tokens.join(" ");
|
559
|
+
}
|
560
|
+
reindex();
|
561
|
+
};
|
562
|
+
that.toggle = function(token, force) {
|
563
|
+
preop.apply(that, [ token ]);
|
564
|
+
if (undefined$1 !== force) {
|
565
|
+
if (force) {
|
566
|
+
that.add(token);
|
567
|
+
return true;
|
568
|
+
} else {
|
569
|
+
that.remove(token);
|
570
|
+
return false;
|
571
|
+
}
|
572
|
+
}
|
573
|
+
if (tokenMap[token]) {
|
574
|
+
that.remove(token);
|
575
|
+
return false;
|
576
|
+
}
|
577
|
+
that.add(token);
|
578
|
+
return true;
|
579
|
+
};
|
580
|
+
return that;
|
581
|
+
};
|
582
|
+
return _DOMTokenList;
|
583
|
+
}();
|
584
|
+
}
|
585
|
+
(function() {
|
586
|
+
var e = document.createElement("span");
|
587
|
+
if (!("classList" in e)) return;
|
588
|
+
e.classList.toggle("x", false);
|
589
|
+
if (!e.classList.contains("x")) return;
|
590
|
+
e.classList.constructor.prototype.toggle = function toggle(token) {
|
591
|
+
var force = arguments[1];
|
592
|
+
if (force === undefined$1) {
|
593
|
+
var add = !this.contains(token);
|
594
|
+
this[add ? "add" : "remove"](token);
|
595
|
+
return add;
|
596
|
+
}
|
597
|
+
force = !!force;
|
598
|
+
this[force ? "add" : "remove"](token);
|
599
|
+
return force;
|
600
|
+
};
|
601
|
+
})();
|
602
|
+
(function() {
|
603
|
+
var e = document.createElement("span");
|
604
|
+
if (!("classList" in e)) return;
|
605
|
+
e.classList.add("a", "b");
|
606
|
+
if (e.classList.contains("b")) return;
|
607
|
+
var native = e.classList.constructor.prototype.add;
|
608
|
+
e.classList.constructor.prototype.add = function() {
|
609
|
+
var args = arguments;
|
610
|
+
var l = arguments.length;
|
611
|
+
for (var i = 0; i < l; i++) {
|
612
|
+
native.call(this, args[i]);
|
613
|
+
}
|
614
|
+
};
|
615
|
+
})();
|
616
|
+
(function() {
|
617
|
+
var e = document.createElement("span");
|
618
|
+
if (!("classList" in e)) return;
|
619
|
+
e.classList.add("a");
|
620
|
+
e.classList.add("b");
|
621
|
+
e.classList.remove("a", "b");
|
622
|
+
if (!e.classList.contains("b")) return;
|
623
|
+
var native = e.classList.constructor.prototype.remove;
|
624
|
+
e.classList.constructor.prototype.remove = function() {
|
625
|
+
var args = arguments;
|
626
|
+
var l = arguments.length;
|
627
|
+
for (var i = 0; i < l; i++) {
|
628
|
+
native.call(this, args[i]);
|
629
|
+
}
|
630
|
+
};
|
631
|
+
})();
|
632
|
+
})(this);
|
633
|
+
}).call("object" === typeof window && window || "object" === typeof self && self || "object" === typeof global && global || {});
|
634
|
+
|
635
|
+
(function(undefined$1) {
|
636
|
+
var detect = "document" in this && "classList" in document.documentElement && "Element" in this && "classList" in Element.prototype && function() {
|
637
|
+
var e = document.createElement("span");
|
638
|
+
e.classList.add("a", "b");
|
639
|
+
return e.classList.contains("b");
|
640
|
+
}();
|
641
|
+
if (detect) return;
|
642
|
+
(function(global) {
|
643
|
+
var dpSupport = true;
|
644
|
+
var defineGetter = function(object, name, fn, configurable) {
|
645
|
+
if (Object.defineProperty) Object.defineProperty(object, name, {
|
646
|
+
configurable: false === dpSupport ? true : !!configurable,
|
647
|
+
get: fn
|
648
|
+
}); else object.__defineGetter__(name, fn);
|
649
|
+
};
|
650
|
+
try {
|
651
|
+
defineGetter({}, "support");
|
652
|
+
} catch (e) {
|
653
|
+
dpSupport = false;
|
654
|
+
}
|
655
|
+
var addProp = function(o, name, attr) {
|
656
|
+
defineGetter(o.prototype, name, (function() {
|
657
|
+
var tokenList;
|
658
|
+
var THIS = this, gibberishProperty = "__defineGetter__" + "DEFINE_PROPERTY" + name;
|
659
|
+
if (THIS[gibberishProperty]) return tokenList;
|
660
|
+
THIS[gibberishProperty] = true;
|
661
|
+
if (false === dpSupport) {
|
662
|
+
var visage;
|
663
|
+
var mirror = addProp.mirror || document.createElement("div");
|
664
|
+
var reflections = mirror.childNodes;
|
665
|
+
var l = reflections.length;
|
666
|
+
for (var i = 0; i < l; ++i) if (reflections[i]._R === THIS) {
|
667
|
+
visage = reflections[i];
|
668
|
+
break;
|
669
|
+
}
|
670
|
+
visage || (visage = mirror.appendChild(document.createElement("div")));
|
671
|
+
tokenList = DOMTokenList.call(visage, THIS, attr);
|
672
|
+
} else tokenList = new DOMTokenList(THIS, attr);
|
673
|
+
defineGetter(THIS, name, (function() {
|
674
|
+
return tokenList;
|
675
|
+
}));
|
676
|
+
delete THIS[gibberishProperty];
|
677
|
+
return tokenList;
|
678
|
+
}), true);
|
679
|
+
};
|
680
|
+
addProp(global.Element, "classList", "className");
|
681
|
+
addProp(global.HTMLElement, "classList", "className");
|
682
|
+
addProp(global.HTMLLinkElement, "relList", "rel");
|
683
|
+
addProp(global.HTMLAnchorElement, "relList", "rel");
|
684
|
+
addProp(global.HTMLAreaElement, "relList", "rel");
|
685
|
+
})(this);
|
686
|
+
}).call("object" === typeof window && window || "object" === typeof self && self || "object" === typeof global && global || {});
|
687
|
+
|
688
|
+
function CharacterCount($module) {
|
689
|
+
this.$module = $module;
|
690
|
+
this.$textarea = $module.querySelector(".govuk-js-character-count");
|
691
|
+
this.$visibleCountMessage = null;
|
692
|
+
this.$screenReaderCountMessage = null;
|
693
|
+
this.lastInputTimestamp = null;
|
694
|
+
}
|
695
|
+
|
696
|
+
CharacterCount.prototype.defaults = {
|
697
|
+
characterCountAttribute: "data-maxlength",
|
698
|
+
wordCountAttribute: "data-maxwords"
|
699
|
+
};
|
700
|
+
|
701
|
+
CharacterCount.prototype.init = function() {
|
702
|
+
if (!this.$textarea) {
|
703
|
+
return;
|
704
|
+
}
|
705
|
+
var $module = this.$module;
|
706
|
+
var $textarea = this.$textarea;
|
707
|
+
var $fallbackLimitMessage = document.getElementById($textarea.id + "-info");
|
708
|
+
$textarea.insertAdjacentElement("afterend", $fallbackLimitMessage);
|
709
|
+
var $screenReaderCountMessage = document.createElement("div");
|
710
|
+
$screenReaderCountMessage.className = "govuk-character-count__sr-status govuk-visually-hidden";
|
711
|
+
$screenReaderCountMessage.setAttribute("aria-live", "polite");
|
712
|
+
this.$screenReaderCountMessage = $screenReaderCountMessage;
|
713
|
+
$fallbackLimitMessage.insertAdjacentElement("afterend", $screenReaderCountMessage);
|
714
|
+
var $visibleCountMessage = document.createElement("div");
|
715
|
+
$visibleCountMessage.className = $fallbackLimitMessage.className;
|
716
|
+
$visibleCountMessage.classList.add("govuk-character-count__status");
|
717
|
+
$visibleCountMessage.setAttribute("aria-hidden", "true");
|
718
|
+
this.$visibleCountMessage = $visibleCountMessage;
|
719
|
+
$fallbackLimitMessage.insertAdjacentElement("afterend", $visibleCountMessage);
|
720
|
+
$fallbackLimitMessage.classList.add("govuk-visually-hidden");
|
721
|
+
this.options = this.getDataset($module);
|
722
|
+
var countAttribute = this.defaults.characterCountAttribute;
|
723
|
+
if (this.options.maxwords) {
|
724
|
+
countAttribute = this.defaults.wordCountAttribute;
|
725
|
+
}
|
726
|
+
this.maxLength = $module.getAttribute(countAttribute);
|
727
|
+
if (!this.maxLength) {
|
728
|
+
return;
|
729
|
+
}
|
730
|
+
$textarea.removeAttribute("maxlength");
|
731
|
+
this.bindChangeEvents();
|
732
|
+
if ("onpageshow" in window) {
|
733
|
+
window.addEventListener("pageshow", this.updateCountMessage.bind(this));
|
734
|
+
} else {
|
735
|
+
window.addEventListener("DOMContentLoaded", this.updateCountMessage.bind(this));
|
736
|
+
}
|
737
|
+
this.updateCountMessage();
|
738
|
+
};
|
739
|
+
|
740
|
+
CharacterCount.prototype.getDataset = function(element) {
|
741
|
+
var dataset = {};
|
742
|
+
var attributes = element.attributes;
|
743
|
+
if (attributes) {
|
744
|
+
for (var i = 0; i < attributes.length; i++) {
|
745
|
+
var attribute = attributes[i];
|
746
|
+
var match = attribute.name.match(/^data-(.+)/);
|
747
|
+
if (match) {
|
748
|
+
dataset[match[1]] = attribute.value;
|
749
|
+
}
|
750
|
+
}
|
751
|
+
}
|
752
|
+
return dataset;
|
753
|
+
};
|
754
|
+
|
755
|
+
CharacterCount.prototype.count = function(text) {
|
756
|
+
var length;
|
757
|
+
if (this.options.maxwords) {
|
758
|
+
var tokens = text.match(/\S+/g) || [];
|
759
|
+
length = tokens.length;
|
760
|
+
} else {
|
761
|
+
length = text.length;
|
762
|
+
}
|
763
|
+
return length;
|
764
|
+
};
|
765
|
+
|
766
|
+
CharacterCount.prototype.bindChangeEvents = function() {
|
767
|
+
var $textarea = this.$textarea;
|
768
|
+
$textarea.addEventListener("keyup", this.handleKeyUp.bind(this));
|
769
|
+
$textarea.addEventListener("focus", this.handleFocus.bind(this));
|
770
|
+
$textarea.addEventListener("blur", this.handleBlur.bind(this));
|
771
|
+
};
|
772
|
+
|
773
|
+
CharacterCount.prototype.checkIfValueChanged = function() {
|
774
|
+
if (!this.$textarea.oldValue) this.$textarea.oldValue = "";
|
775
|
+
if (this.$textarea.value !== this.$textarea.oldValue) {
|
776
|
+
this.$textarea.oldValue = this.$textarea.value;
|
777
|
+
this.updateCountMessage();
|
778
|
+
}
|
779
|
+
};
|
780
|
+
|
781
|
+
CharacterCount.prototype.updateCountMessage = function() {
|
782
|
+
this.updateVisibleCountMessage();
|
783
|
+
this.updateScreenReaderCountMessage();
|
784
|
+
};
|
785
|
+
|
786
|
+
CharacterCount.prototype.updateVisibleCountMessage = function() {
|
787
|
+
var $textarea = this.$textarea;
|
788
|
+
var $visibleCountMessage = this.$visibleCountMessage;
|
789
|
+
var remainingNumber = this.maxLength - this.count($textarea.value);
|
790
|
+
if (this.isOverThreshold()) {
|
791
|
+
$visibleCountMessage.classList.remove("govuk-character-count__message--disabled");
|
792
|
+
} else {
|
793
|
+
$visibleCountMessage.classList.add("govuk-character-count__message--disabled");
|
794
|
+
}
|
795
|
+
if (remainingNumber < 0) {
|
796
|
+
$textarea.classList.add("govuk-textarea--error");
|
797
|
+
$visibleCountMessage.classList.remove("govuk-hint");
|
798
|
+
$visibleCountMessage.classList.add("govuk-error-message");
|
799
|
+
} else {
|
800
|
+
$textarea.classList.remove("govuk-textarea--error");
|
801
|
+
$visibleCountMessage.classList.remove("govuk-error-message");
|
802
|
+
$visibleCountMessage.classList.add("govuk-hint");
|
803
|
+
}
|
804
|
+
$visibleCountMessage.innerHTML = this.formattedUpdateMessage();
|
805
|
+
};
|
806
|
+
|
807
|
+
CharacterCount.prototype.updateScreenReaderCountMessage = function() {
|
808
|
+
var $screenReaderCountMessage = this.$screenReaderCountMessage;
|
809
|
+
if (this.isOverThreshold()) {
|
810
|
+
$screenReaderCountMessage.removeAttribute("aria-hidden");
|
811
|
+
} else {
|
812
|
+
$screenReaderCountMessage.setAttribute("aria-hidden", true);
|
813
|
+
}
|
814
|
+
$screenReaderCountMessage.innerHTML = this.formattedUpdateMessage();
|
815
|
+
};
|
816
|
+
|
817
|
+
CharacterCount.prototype.formattedUpdateMessage = function() {
|
818
|
+
var $textarea = this.$textarea;
|
819
|
+
var options = this.options;
|
820
|
+
var remainingNumber = this.maxLength - this.count($textarea.value);
|
821
|
+
var charVerb = "remaining";
|
822
|
+
var charNoun = "character";
|
823
|
+
var displayNumber = remainingNumber;
|
824
|
+
if (options.maxwords) {
|
825
|
+
charNoun = "word";
|
826
|
+
}
|
827
|
+
charNoun = charNoun + (remainingNumber === -1 || remainingNumber === 1 ? "" : "s");
|
828
|
+
charVerb = remainingNumber < 0 ? "too many" : "remaining";
|
829
|
+
displayNumber = Math.abs(remainingNumber);
|
830
|
+
return "You have " + displayNumber + " " + charNoun + " " + charVerb;
|
831
|
+
};
|
832
|
+
|
833
|
+
CharacterCount.prototype.isOverThreshold = function() {
|
834
|
+
var $textarea = this.$textarea;
|
835
|
+
var options = this.options;
|
836
|
+
var currentLength = this.count($textarea.value);
|
837
|
+
var maxLength = this.maxLength;
|
838
|
+
var thresholdPercent = options.threshold ? options.threshold : 0;
|
839
|
+
var thresholdValue = maxLength * thresholdPercent / 100;
|
840
|
+
return thresholdValue <= currentLength;
|
841
|
+
};
|
842
|
+
|
843
|
+
CharacterCount.prototype.handleKeyUp = function() {
|
844
|
+
this.updateVisibleCountMessage();
|
845
|
+
this.lastInputTimestamp = Date.now();
|
846
|
+
};
|
847
|
+
|
848
|
+
CharacterCount.prototype.handleFocus = function() {
|
849
|
+
this.valueChecker = setInterval(function() {
|
850
|
+
if (!this.lastInputTimestamp || Date.now() - 500 >= this.lastInputTimestamp) {
|
851
|
+
this.checkIfValueChanged();
|
852
|
+
}
|
853
|
+
}.bind(this), 1e3);
|
854
|
+
};
|
855
|
+
|
856
|
+
CharacterCount.prototype.handleBlur = function() {
|
857
|
+
clearInterval(this.valueChecker);
|
858
|
+
};
|
859
|
+
|
860
|
+
function Checkboxes($module) {
|
861
|
+
this.$module = $module;
|
862
|
+
this.$inputs = $module.querySelectorAll('input[type="checkbox"]');
|
863
|
+
}
|
864
|
+
|
865
|
+
Checkboxes.prototype.init = function() {
|
866
|
+
var $module = this.$module;
|
867
|
+
var $inputs = this.$inputs;
|
868
|
+
nodeListForEach($inputs, (function($input) {
|
869
|
+
var target = $input.getAttribute("data-aria-controls");
|
870
|
+
if (!target || !document.getElementById(target)) {
|
871
|
+
return;
|
872
|
+
}
|
873
|
+
$input.setAttribute("aria-controls", target);
|
874
|
+
$input.removeAttribute("data-aria-controls");
|
875
|
+
}));
|
876
|
+
if ("onpageshow" in window) {
|
877
|
+
window.addEventListener("pageshow", this.syncAllConditionalReveals.bind(this));
|
878
|
+
} else {
|
879
|
+
window.addEventListener("DOMContentLoaded", this.syncAllConditionalReveals.bind(this));
|
880
|
+
}
|
881
|
+
this.syncAllConditionalReveals();
|
882
|
+
$module.addEventListener("click", this.handleClick.bind(this));
|
883
|
+
};
|
884
|
+
|
885
|
+
Checkboxes.prototype.syncAllConditionalReveals = function() {
|
886
|
+
nodeListForEach(this.$inputs, this.syncConditionalRevealWithInputState.bind(this));
|
887
|
+
};
|
888
|
+
|
889
|
+
Checkboxes.prototype.syncConditionalRevealWithInputState = function($input) {
|
890
|
+
var $target = document.getElementById($input.getAttribute("aria-controls"));
|
891
|
+
if ($target && $target.classList.contains("govuk-checkboxes__conditional")) {
|
892
|
+
var inputIsChecked = $input.checked;
|
893
|
+
$input.setAttribute("aria-expanded", inputIsChecked);
|
894
|
+
$target.classList.toggle("govuk-checkboxes__conditional--hidden", !inputIsChecked);
|
895
|
+
}
|
896
|
+
};
|
897
|
+
|
898
|
+
Checkboxes.prototype.unCheckAllInputsExcept = function($input) {
|
899
|
+
var allInputsWithSameName = document.querySelectorAll('input[type="checkbox"][name="' + $input.name + '"]');
|
900
|
+
nodeListForEach(allInputsWithSameName, function($inputWithSameName) {
|
901
|
+
var hasSameFormOwner = $input.form === $inputWithSameName.form;
|
902
|
+
if (hasSameFormOwner && $inputWithSameName !== $input) {
|
903
|
+
$inputWithSameName.checked = false;
|
904
|
+
this.syncConditionalRevealWithInputState($inputWithSameName);
|
905
|
+
}
|
906
|
+
}.bind(this));
|
907
|
+
};
|
908
|
+
|
909
|
+
Checkboxes.prototype.unCheckExclusiveInputs = function($input) {
|
910
|
+
var allInputsWithSameNameAndExclusiveBehaviour = document.querySelectorAll('input[data-behaviour="exclusive"][type="checkbox"][name="' + $input.name + '"]');
|
911
|
+
nodeListForEach(allInputsWithSameNameAndExclusiveBehaviour, function($exclusiveInput) {
|
912
|
+
var hasSameFormOwner = $input.form === $exclusiveInput.form;
|
913
|
+
if (hasSameFormOwner) {
|
914
|
+
$exclusiveInput.checked = false;
|
915
|
+
this.syncConditionalRevealWithInputState($exclusiveInput);
|
916
|
+
}
|
917
|
+
}.bind(this));
|
918
|
+
};
|
919
|
+
|
920
|
+
Checkboxes.prototype.handleClick = function(event) {
|
921
|
+
var $target = event.target;
|
922
|
+
if ($target.type !== "checkbox") {
|
923
|
+
return;
|
924
|
+
}
|
925
|
+
var hasAriaControls = $target.getAttribute("aria-controls");
|
926
|
+
if (hasAriaControls) {
|
927
|
+
this.syncConditionalRevealWithInputState($target);
|
928
|
+
}
|
929
|
+
if (!$target.checked) {
|
930
|
+
return;
|
931
|
+
}
|
932
|
+
var hasBehaviourExclusive = $target.getAttribute("data-behaviour") === "exclusive";
|
933
|
+
if (hasBehaviourExclusive) {
|
934
|
+
this.unCheckAllInputsExcept($target);
|
935
|
+
} else {
|
936
|
+
this.unCheckExclusiveInputs($target);
|
937
|
+
}
|
938
|
+
};
|
939
|
+
|
940
|
+
(function(undefined$1) {
|
941
|
+
var detect = "document" in this && "matches" in document.documentElement;
|
942
|
+
if (detect) return;
|
943
|
+
Element.prototype.matches = Element.prototype.webkitMatchesSelector || Element.prototype.oMatchesSelector || Element.prototype.msMatchesSelector || Element.prototype.mozMatchesSelector || function matches(selector) {
|
944
|
+
var element = this;
|
945
|
+
var elements = (element.document || element.ownerDocument).querySelectorAll(selector);
|
946
|
+
var index = 0;
|
947
|
+
while (elements[index] && elements[index] !== element) {
|
948
|
+
++index;
|
949
|
+
}
|
950
|
+
return !!elements[index];
|
951
|
+
};
|
952
|
+
}).call("object" === typeof window && window || "object" === typeof self && self || "object" === typeof global && global || {});
|
953
|
+
|
954
|
+
(function(undefined$1) {
|
955
|
+
var detect = "document" in this && "closest" in document.documentElement;
|
956
|
+
if (detect) return;
|
957
|
+
Element.prototype.closest = function closest(selector) {
|
958
|
+
var node = this;
|
959
|
+
while (node) {
|
960
|
+
if (node.matches(selector)) return node; else node = "SVGElement" in window && node instanceof SVGElement ? node.parentNode : node.parentElement;
|
961
|
+
}
|
962
|
+
return null;
|
963
|
+
};
|
964
|
+
}).call("object" === typeof window && window || "object" === typeof self && self || "object" === typeof global && global || {});
|
965
|
+
|
966
|
+
function ErrorSummary($module) {
|
967
|
+
this.$module = $module;
|
968
|
+
}
|
969
|
+
|
970
|
+
ErrorSummary.prototype.init = function() {
|
971
|
+
var $module = this.$module;
|
972
|
+
if (!$module) {
|
973
|
+
return;
|
974
|
+
}
|
975
|
+
this.setFocus();
|
976
|
+
$module.addEventListener("click", this.handleClick.bind(this));
|
977
|
+
};
|
978
|
+
|
979
|
+
ErrorSummary.prototype.setFocus = function() {
|
980
|
+
var $module = this.$module;
|
981
|
+
if ($module.getAttribute("data-disable-auto-focus") === "true") {
|
982
|
+
return;
|
983
|
+
}
|
984
|
+
$module.setAttribute("tabindex", "-1");
|
985
|
+
$module.addEventListener("blur", (function() {
|
986
|
+
$module.removeAttribute("tabindex");
|
987
|
+
}));
|
988
|
+
$module.focus();
|
989
|
+
};
|
990
|
+
|
991
|
+
ErrorSummary.prototype.handleClick = function(event) {
|
992
|
+
var target = event.target;
|
993
|
+
if (this.focusTarget(target)) {
|
994
|
+
event.preventDefault();
|
995
|
+
}
|
996
|
+
};
|
997
|
+
|
998
|
+
ErrorSummary.prototype.focusTarget = function($target) {
|
999
|
+
if ($target.tagName !== "A" || $target.href === false) {
|
1000
|
+
return false;
|
1001
|
+
}
|
1002
|
+
var inputId = this.getFragmentFromUrl($target.href);
|
1003
|
+
var $input = document.getElementById(inputId);
|
1004
|
+
if (!$input) {
|
1005
|
+
return false;
|
1006
|
+
}
|
1007
|
+
var $legendOrLabel = this.getAssociatedLegendOrLabel($input);
|
1008
|
+
if (!$legendOrLabel) {
|
1009
|
+
return false;
|
1010
|
+
}
|
1011
|
+
$legendOrLabel.scrollIntoView();
|
1012
|
+
$input.focus({
|
1013
|
+
preventScroll: true
|
1014
|
+
});
|
1015
|
+
return true;
|
1016
|
+
};
|
1017
|
+
|
1018
|
+
ErrorSummary.prototype.getFragmentFromUrl = function(url) {
|
1019
|
+
if (url.indexOf("#") === -1) {
|
1020
|
+
return false;
|
1021
|
+
}
|
1022
|
+
return url.split("#").pop();
|
1023
|
+
};
|
1024
|
+
|
1025
|
+
ErrorSummary.prototype.getAssociatedLegendOrLabel = function($input) {
|
1026
|
+
var $fieldset = $input.closest("fieldset");
|
1027
|
+
if ($fieldset) {
|
1028
|
+
var legends = $fieldset.getElementsByTagName("legend");
|
1029
|
+
if (legends.length) {
|
1030
|
+
var $candidateLegend = legends[0];
|
1031
|
+
if ($input.type === "checkbox" || $input.type === "radio") {
|
1032
|
+
return $candidateLegend;
|
1033
|
+
}
|
1034
|
+
var legendTop = $candidateLegend.getBoundingClientRect().top;
|
1035
|
+
var inputRect = $input.getBoundingClientRect();
|
1036
|
+
if (inputRect.height && window.innerHeight) {
|
1037
|
+
var inputBottom = inputRect.top + inputRect.height;
|
1038
|
+
if (inputBottom - legendTop < window.innerHeight / 2) {
|
1039
|
+
return $candidateLegend;
|
1040
|
+
}
|
1041
|
+
}
|
1042
|
+
}
|
1043
|
+
}
|
1044
|
+
return document.querySelector("label[for='" + $input.getAttribute("id") + "']") || $input.closest("label");
|
1045
|
+
};
|
1046
|
+
|
1047
|
+
function Radios($module) {
|
1048
|
+
this.$module = $module;
|
1049
|
+
this.$inputs = $module.querySelectorAll('input[type="radio"]');
|
1050
|
+
}
|
1051
|
+
|
1052
|
+
Radios.prototype.init = function() {
|
1053
|
+
var $module = this.$module;
|
1054
|
+
var $inputs = this.$inputs;
|
1055
|
+
nodeListForEach($inputs, (function($input) {
|
1056
|
+
var target = $input.getAttribute("data-aria-controls");
|
1057
|
+
if (!target || !document.getElementById(target)) {
|
1058
|
+
return;
|
1059
|
+
}
|
1060
|
+
$input.setAttribute("aria-controls", target);
|
1061
|
+
$input.removeAttribute("data-aria-controls");
|
1062
|
+
}));
|
1063
|
+
if ("onpageshow" in window) {
|
1064
|
+
window.addEventListener("pageshow", this.syncAllConditionalReveals.bind(this));
|
1065
|
+
} else {
|
1066
|
+
window.addEventListener("DOMContentLoaded", this.syncAllConditionalReveals.bind(this));
|
1067
|
+
}
|
1068
|
+
this.syncAllConditionalReveals();
|
1069
|
+
$module.addEventListener("click", this.handleClick.bind(this));
|
1070
|
+
};
|
1071
|
+
|
1072
|
+
Radios.prototype.syncAllConditionalReveals = function() {
|
1073
|
+
nodeListForEach(this.$inputs, this.syncConditionalRevealWithInputState.bind(this));
|
1074
|
+
};
|
1075
|
+
|
1076
|
+
Radios.prototype.syncConditionalRevealWithInputState = function($input) {
|
1077
|
+
var $target = document.getElementById($input.getAttribute("aria-controls"));
|
1078
|
+
if ($target && $target.classList.contains("govuk-radios__conditional")) {
|
1079
|
+
var inputIsChecked = $input.checked;
|
1080
|
+
$input.setAttribute("aria-expanded", inputIsChecked);
|
1081
|
+
$target.classList.toggle("govuk-radios__conditional--hidden", !inputIsChecked);
|
1082
|
+
}
|
1083
|
+
};
|
1084
|
+
|
1085
|
+
Radios.prototype.handleClick = function(event) {
|
1086
|
+
var $clickedInput = event.target;
|
1087
|
+
if ($clickedInput.type !== "radio") {
|
1088
|
+
return;
|
1089
|
+
}
|
1090
|
+
var $allInputs = document.querySelectorAll('input[type="radio"][aria-controls]');
|
1091
|
+
nodeListForEach($allInputs, function($input) {
|
1092
|
+
var hasSameFormOwner = $input.form === $clickedInput.form;
|
1093
|
+
var hasSameName = $input.name === $clickedInput.name;
|
1094
|
+
if (hasSameName && hasSameFormOwner) {
|
1095
|
+
this.syncConditionalRevealWithInputState($input);
|
1096
|
+
}
|
1097
|
+
}.bind(this));
|
1098
|
+
};
|
1099
|
+
|
1100
|
+
function initAll(options) {
|
1101
|
+
options = typeof options !== "undefined" ? options : {};
|
1102
|
+
const scope = typeof options.scope !== "undefined" ? options.scope : document;
|
1103
|
+
const $buttons = scope.querySelectorAll('[data-module="govuk-button"]');
|
1104
|
+
nodeListForEach($buttons, (function($button) {
|
1105
|
+
new Button($button).init();
|
1106
|
+
}));
|
1107
|
+
const $characterCounts = scope.querySelectorAll('[data-module="govuk-character-count"]');
|
1108
|
+
nodeListForEach($characterCounts, (function($characterCount) {
|
1109
|
+
new CharacterCount($characterCount).init();
|
1110
|
+
}));
|
1111
|
+
const $checkboxes = scope.querySelectorAll('[data-module="govuk-checkboxes"]');
|
1112
|
+
nodeListForEach($checkboxes, (function($checkbox) {
|
1113
|
+
new Checkboxes($checkbox).init();
|
1114
|
+
}));
|
1115
|
+
const $errorSummary = scope.querySelector('[data-module="govuk-error-summary"]');
|
1116
|
+
new ErrorSummary($errorSummary).init();
|
1117
|
+
const $radios = scope.querySelectorAll('[data-module="govuk-radios"]');
|
1118
|
+
nodeListForEach($radios, (function($radio) {
|
1119
|
+
new Radios($radio).init();
|
1120
|
+
}));
|
1121
|
+
}
|
1122
|
+
|
1123
|
+
export { Button, CharacterCount, Checkboxes, ErrorSummary, Radios, initAll };
|