govuk_publishing_components 12.8.0 → 12.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/app/views/govuk_publishing_components/components/_checkboxes.html.erb +1 -0
  3. data/app/views/govuk_publishing_components/components/docs/checkboxes.yml +13 -0
  4. data/lib/govuk_publishing_components/version.rb +1 -1
  5. data/node_modules/govuk-frontend/all.js +161 -1
  6. data/node_modules/govuk-frontend/components/back-link/README.md +3 -77
  7. data/node_modules/govuk-frontend/components/breadcrumbs/README.md +3 -101
  8. data/node_modules/govuk-frontend/components/button/README.md +3 -137
  9. data/node_modules/govuk-frontend/components/character-count/README.md +3 -149
  10. data/node_modules/govuk-frontend/components/character-count/character-count.js +1 -1
  11. data/node_modules/govuk-frontend/components/checkboxes/README.md +3 -257
  12. data/node_modules/govuk-frontend/components/checkboxes/checkboxes.js +1 -1
  13. data/node_modules/govuk-frontend/components/checkboxes/template.njk +5 -0
  14. data/node_modules/govuk-frontend/components/date-input/README.md +3 -173
  15. data/node_modules/govuk-frontend/components/date-input/macro-options.json +14 -0
  16. data/node_modules/govuk-frontend/components/date-input/template.njk +1 -1
  17. data/node_modules/govuk-frontend/components/details/README.md +3 -101
  18. data/node_modules/govuk-frontend/components/error-message/README.md +3 -77
  19. data/node_modules/govuk-frontend/components/error-summary/README.md +3 -125
  20. data/node_modules/govuk-frontend/components/error-summary/error-summary.js +405 -87
  21. data/node_modules/govuk-frontend/components/fieldset/README.md +3 -113
  22. data/node_modules/govuk-frontend/components/file-upload/README.md +3 -125
  23. data/node_modules/govuk-frontend/components/file-upload/macro-options.json +14 -0
  24. data/node_modules/govuk-frontend/components/file-upload/template.njk +1 -1
  25. data/node_modules/govuk-frontend/components/footer/README.md +3 -233
  26. data/node_modules/govuk-frontend/components/header/README.md +3 -197
  27. data/node_modules/govuk-frontend/components/hint/README.md +3 -77
  28. data/node_modules/govuk-frontend/components/input/README.md +3 -137
  29. data/node_modules/govuk-frontend/components/input/macro-options.json +14 -0
  30. data/node_modules/govuk-frontend/components/input/template.njk +1 -1
  31. data/node_modules/govuk-frontend/components/inset-text/README.md +7 -77
  32. data/node_modules/govuk-frontend/components/label/README.md +3 -89
  33. data/node_modules/govuk-frontend/components/panel/README.md +3 -89
  34. data/node_modules/govuk-frontend/components/phase-banner/README.md +3 -77
  35. data/node_modules/govuk-frontend/components/radios/README.md +3 -269
  36. data/node_modules/govuk-frontend/components/radios/radios.js +1 -1
  37. data/node_modules/govuk-frontend/components/select/README.md +3 -185
  38. data/node_modules/govuk-frontend/components/select/macro-options.json +14 -0
  39. data/node_modules/govuk-frontend/components/select/template.njk +1 -1
  40. data/node_modules/govuk-frontend/components/skip-link/README.md +3 -77
  41. data/node_modules/govuk-frontend/components/table/README.md +3 -233
  42. data/node_modules/govuk-frontend/components/tabs/README.md +3 -149
  43. data/node_modules/govuk-frontend/components/tabs/tabs.js +111 -111
  44. data/node_modules/govuk-frontend/components/tag/README.md +3 -65
  45. data/node_modules/govuk-frontend/components/textarea/README.md +3 -149
  46. data/node_modules/govuk-frontend/components/textarea/macro-options.json +14 -0
  47. data/node_modules/govuk-frontend/components/textarea/template.njk +1 -1
  48. data/node_modules/govuk-frontend/components/warning-text/README.md +3 -77
  49. data/node_modules/govuk-frontend/package.json +11 -11
  50. data/node_modules/govuk-frontend/vendor/polyfills/Element/prototype/classList.js +141 -1
  51. data/node_modules/govuk-frontend/vendor/polyfills/Element/prototype/closest.js +54 -0
  52. data/node_modules/govuk-frontend/vendor/polyfills/Element/prototype/matches.js +31 -0
  53. metadata +4 -2
@@ -6,6 +6,251 @@
6
6
 
7
7
  (function(undefined) {
8
8
 
9
+ // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Object/defineProperty/detect.js
10
+ var detect = (
11
+ // In IE8, defineProperty could only act on DOM elements, so full support
12
+ // for the feature requires the ability to set a property on an arbitrary object
13
+ 'defineProperty' in Object && (function() {
14
+ try {
15
+ var a = {};
16
+ Object.defineProperty(a, 'test', {value:42});
17
+ return true;
18
+ } catch(e) {
19
+ return false
20
+ }
21
+ }())
22
+ );
23
+
24
+ if (detect) return
25
+
26
+ // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Object.defineProperty&flags=always
27
+ (function (nativeDefineProperty) {
28
+
29
+ var supportsAccessors = Object.prototype.hasOwnProperty('__defineGetter__');
30
+ var ERR_ACCESSORS_NOT_SUPPORTED = 'Getters & setters cannot be defined on this javascript engine';
31
+ var ERR_VALUE_ACCESSORS = 'A property cannot both have accessors and be writable or have a value';
32
+
33
+ Object.defineProperty = function defineProperty(object, property, descriptor) {
34
+
35
+ // Where native support exists, assume it
36
+ if (nativeDefineProperty && (object === window || object === document || object === Element.prototype || object instanceof Element)) {
37
+ return nativeDefineProperty(object, property, descriptor);
38
+ }
39
+
40
+ if (object === null || !(object instanceof Object || typeof object === 'object')) {
41
+ throw new TypeError('Object.defineProperty called on non-object');
42
+ }
43
+
44
+ if (!(descriptor instanceof Object)) {
45
+ throw new TypeError('Property description must be an object');
46
+ }
47
+
48
+ var propertyString = String(property);
49
+ var hasValueOrWritable = 'value' in descriptor || 'writable' in descriptor;
50
+ var getterType = 'get' in descriptor && typeof descriptor.get;
51
+ var setterType = 'set' in descriptor && typeof descriptor.set;
52
+
53
+ // handle descriptor.get
54
+ if (getterType) {
55
+ if (getterType !== 'function') {
56
+ throw new TypeError('Getter must be a function');
57
+ }
58
+ if (!supportsAccessors) {
59
+ throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
60
+ }
61
+ if (hasValueOrWritable) {
62
+ throw new TypeError(ERR_VALUE_ACCESSORS);
63
+ }
64
+ Object.__defineGetter__.call(object, propertyString, descriptor.get);
65
+ } else {
66
+ object[propertyString] = descriptor.value;
67
+ }
68
+
69
+ // handle descriptor.set
70
+ if (setterType) {
71
+ if (setterType !== 'function') {
72
+ throw new TypeError('Setter must be a function');
73
+ }
74
+ if (!supportsAccessors) {
75
+ throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
76
+ }
77
+ if (hasValueOrWritable) {
78
+ throw new TypeError(ERR_VALUE_ACCESSORS);
79
+ }
80
+ Object.__defineSetter__.call(object, propertyString, descriptor.set);
81
+ }
82
+
83
+ // OK to define value unconditionally - if a getter has been specified as well, an error would be thrown above
84
+ if ('value' in descriptor) {
85
+ object[propertyString] = descriptor.value;
86
+ }
87
+
88
+ return object;
89
+ };
90
+ }(Object.defineProperty));
91
+ })
92
+ .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
93
+
94
+ (function(undefined) {
95
+ // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Function/prototype/bind/detect.js
96
+ var detect = 'bind' in Function.prototype;
97
+
98
+ if (detect) return
99
+
100
+ // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Function.prototype.bind&flags=always
101
+ Object.defineProperty(Function.prototype, 'bind', {
102
+ value: function bind(that) { // .length is 1
103
+ // add necessary es5-shim utilities
104
+ var $Array = Array;
105
+ var $Object = Object;
106
+ var ObjectPrototype = $Object.prototype;
107
+ var ArrayPrototype = $Array.prototype;
108
+ var Empty = function Empty() {};
109
+ var to_string = ObjectPrototype.toString;
110
+ var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';
111
+ var isCallable; /* inlined from https://npmjs.com/is-callable */ var fnToStr = Function.prototype.toString, tryFunctionObject = function tryFunctionObject(value) { try { fnToStr.call(value); return true; } catch (e) { return false; } }, fnClass = '[object Function]', genClass = '[object GeneratorFunction]'; isCallable = function isCallable(value) { if (typeof value !== 'function') { return false; } if (hasToStringTag) { return tryFunctionObject(value); } var strClass = to_string.call(value); return strClass === fnClass || strClass === genClass; };
112
+ var array_slice = ArrayPrototype.slice;
113
+ var array_concat = ArrayPrototype.concat;
114
+ var array_push = ArrayPrototype.push;
115
+ var max = Math.max;
116
+ // /add necessary es5-shim utilities
117
+
118
+ // 1. Let Target be the this value.
119
+ var target = this;
120
+ // 2. If IsCallable(Target) is false, throw a TypeError exception.
121
+ if (!isCallable(target)) {
122
+ throw new TypeError('Function.prototype.bind called on incompatible ' + target);
123
+ }
124
+ // 3. Let A be a new (possibly empty) internal list of all of the
125
+ // argument values provided after thisArg (arg1, arg2 etc), in order.
126
+ // XXX slicedArgs will stand in for "A" if used
127
+ var args = array_slice.call(arguments, 1); // for normal call
128
+ // 4. Let F be a new native ECMAScript object.
129
+ // 11. Set the [[Prototype]] internal property of F to the standard
130
+ // built-in Function prototype object as specified in 15.3.3.1.
131
+ // 12. Set the [[Call]] internal property of F as described in
132
+ // 15.3.4.5.1.
133
+ // 13. Set the [[Construct]] internal property of F as described in
134
+ // 15.3.4.5.2.
135
+ // 14. Set the [[HasInstance]] internal property of F as described in
136
+ // 15.3.4.5.3.
137
+ var bound;
138
+ var binder = function () {
139
+
140
+ if (this instanceof bound) {
141
+ // 15.3.4.5.2 [[Construct]]
142
+ // When the [[Construct]] internal method of a function object,
143
+ // F that was created using the bind function is called with a
144
+ // list of arguments ExtraArgs, the following steps are taken:
145
+ // 1. Let target be the value of F's [[TargetFunction]]
146
+ // internal property.
147
+ // 2. If target has no [[Construct]] internal method, a
148
+ // TypeError exception is thrown.
149
+ // 3. Let boundArgs be the value of F's [[BoundArgs]] internal
150
+ // property.
151
+ // 4. Let args be a new list containing the same values as the
152
+ // list boundArgs in the same order followed by the same
153
+ // values as the list ExtraArgs in the same order.
154
+ // 5. Return the result of calling the [[Construct]] internal
155
+ // method of target providing args as the arguments.
156
+
157
+ var result = target.apply(
158
+ this,
159
+ array_concat.call(args, array_slice.call(arguments))
160
+ );
161
+ if ($Object(result) === result) {
162
+ return result;
163
+ }
164
+ return this;
165
+
166
+ } else {
167
+ // 15.3.4.5.1 [[Call]]
168
+ // When the [[Call]] internal method of a function object, F,
169
+ // which was created using the bind function is called with a
170
+ // this value and a list of arguments ExtraArgs, the following
171
+ // steps are taken:
172
+ // 1. Let boundArgs be the value of F's [[BoundArgs]] internal
173
+ // property.
174
+ // 2. Let boundThis be the value of F's [[BoundThis]] internal
175
+ // property.
176
+ // 3. Let target be the value of F's [[TargetFunction]] internal
177
+ // property.
178
+ // 4. Let args be a new list containing the same values as the
179
+ // list boundArgs in the same order followed by the same
180
+ // values as the list ExtraArgs in the same order.
181
+ // 5. Return the result of calling the [[Call]] internal method
182
+ // of target providing boundThis as the this value and
183
+ // providing args as the arguments.
184
+
185
+ // equiv: target.call(this, ...boundArgs, ...args)
186
+ return target.apply(
187
+ that,
188
+ array_concat.call(args, array_slice.call(arguments))
189
+ );
190
+
191
+ }
192
+
193
+ };
194
+
195
+ // 15. If the [[Class]] internal property of Target is "Function", then
196
+ // a. Let L be the length property of Target minus the length of A.
197
+ // b. Set the length own property of F to either 0 or L, whichever is
198
+ // larger.
199
+ // 16. Else set the length own property of F to 0.
200
+
201
+ var boundLength = max(0, target.length - args.length);
202
+
203
+ // 17. Set the attributes of the length own property of F to the values
204
+ // specified in 15.3.5.1.
205
+ var boundArgs = [];
206
+ for (var i = 0; i < boundLength; i++) {
207
+ array_push.call(boundArgs, '$' + i);
208
+ }
209
+
210
+ // XXX Build a dynamic function with desired amount of arguments is the only
211
+ // way to set the length property of a function.
212
+ // In environments where Content Security Policies enabled (Chrome extensions,
213
+ // for ex.) all use of eval or Function costructor throws an exception.
214
+ // However in all of these environments Function.prototype.bind exists
215
+ // and so this code will never be executed.
216
+ bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this, arguments); }')(binder);
217
+
218
+ if (target.prototype) {
219
+ Empty.prototype = target.prototype;
220
+ bound.prototype = new Empty();
221
+ // Clean up dangling references.
222
+ Empty.prototype = null;
223
+ }
224
+
225
+ // TODO
226
+ // 18. Set the [[Extensible]] internal property of F to true.
227
+
228
+ // TODO
229
+ // 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3).
230
+ // 20. Call the [[DefineOwnProperty]] internal method of F with
231
+ // arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]:
232
+ // thrower, [[Enumerable]]: false, [[Configurable]]: false}, and
233
+ // false.
234
+ // 21. Call the [[DefineOwnProperty]] internal method of F with
235
+ // arguments "arguments", PropertyDescriptor {[[Get]]: thrower,
236
+ // [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false},
237
+ // and false.
238
+
239
+ // TODO
240
+ // NOTE Function objects created using Function.prototype.bind do not
241
+ // have a prototype property or the [[Code]], [[FormalParameters]], and
242
+ // [[Scope]] internal properties.
243
+ // XXX can't delete prototype in pure-js.
244
+
245
+ // 22. Return F.
246
+ return bound;
247
+ }
248
+ });
249
+ })
250
+ .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
251
+
252
+ (function(undefined) {
253
+
9
254
  // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Window/detect.js
10
255
  var detect = ('Window' in this);
11
256
 
@@ -167,93 +412,6 @@ if (detect) return
167
412
 
168
413
  (function(undefined) {
169
414
 
170
- // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Object/defineProperty/detect.js
171
- var detect = (
172
- // In IE8, defineProperty could only act on DOM elements, so full support
173
- // for the feature requires the ability to set a property on an arbitrary object
174
- 'defineProperty' in Object && (function() {
175
- try {
176
- var a = {};
177
- Object.defineProperty(a, 'test', {value:42});
178
- return true;
179
- } catch(e) {
180
- return false
181
- }
182
- }())
183
- );
184
-
185
- if (detect) return
186
-
187
- // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Object.defineProperty&flags=always
188
- (function (nativeDefineProperty) {
189
-
190
- var supportsAccessors = Object.prototype.hasOwnProperty('__defineGetter__');
191
- var ERR_ACCESSORS_NOT_SUPPORTED = 'Getters & setters cannot be defined on this javascript engine';
192
- var ERR_VALUE_ACCESSORS = 'A property cannot both have accessors and be writable or have a value';
193
-
194
- Object.defineProperty = function defineProperty(object, property, descriptor) {
195
-
196
- // Where native support exists, assume it
197
- if (nativeDefineProperty && (object === window || object === document || object === Element.prototype || object instanceof Element)) {
198
- return nativeDefineProperty(object, property, descriptor);
199
- }
200
-
201
- if (object === null || !(object instanceof Object || typeof object === 'object')) {
202
- throw new TypeError('Object.defineProperty called on non-object');
203
- }
204
-
205
- if (!(descriptor instanceof Object)) {
206
- throw new TypeError('Property description must be an object');
207
- }
208
-
209
- var propertyString = String(property);
210
- var hasValueOrWritable = 'value' in descriptor || 'writable' in descriptor;
211
- var getterType = 'get' in descriptor && typeof descriptor.get;
212
- var setterType = 'set' in descriptor && typeof descriptor.set;
213
-
214
- // handle descriptor.get
215
- if (getterType) {
216
- if (getterType !== 'function') {
217
- throw new TypeError('Getter must be a function');
218
- }
219
- if (!supportsAccessors) {
220
- throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
221
- }
222
- if (hasValueOrWritable) {
223
- throw new TypeError(ERR_VALUE_ACCESSORS);
224
- }
225
- Object.__defineGetter__.call(object, propertyString, descriptor.get);
226
- } else {
227
- object[propertyString] = descriptor.value;
228
- }
229
-
230
- // handle descriptor.set
231
- if (setterType) {
232
- if (setterType !== 'function') {
233
- throw new TypeError('Setter must be a function');
234
- }
235
- if (!supportsAccessors) {
236
- throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
237
- }
238
- if (hasValueOrWritable) {
239
- throw new TypeError(ERR_VALUE_ACCESSORS);
240
- }
241
- Object.__defineSetter__.call(object, propertyString, descriptor.set);
242
- }
243
-
244
- // OK to define value unconditionally - if a getter has been specified as well, an error would be thrown above
245
- if ('value' in descriptor) {
246
- object[propertyString] = descriptor.value;
247
- }
248
-
249
- return object;
250
- };
251
- }(Object.defineProperty));
252
- })
253
- .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
254
-
255
- (function(undefined) {
256
-
257
415
  // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Event/detect.js
258
416
  var detect = (
259
417
  (function(global) {
@@ -501,6 +659,53 @@ if (detect) return
501
659
  })
502
660
  .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
503
661
 
662
+ (function(undefined) {
663
+
664
+ // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-service/1f3c09b402f65bf6e393f933a15ba63f1b86ef1f/packages/polyfill-library/polyfills/Element/prototype/matches/detect.js
665
+ var detect = (
666
+ 'document' in this && "matches" in document.documentElement
667
+ );
668
+
669
+ if (detect) return
670
+
671
+ // Polyfill from https://raw.githubusercontent.com/Financial-Times/polyfill-service/1f3c09b402f65bf6e393f933a15ba63f1b86ef1f/packages/polyfill-library/polyfills/Element/prototype/matches/polyfill.js
672
+ Element.prototype.matches = Element.prototype.webkitMatchesSelector || Element.prototype.oMatchesSelector || Element.prototype.msMatchesSelector || Element.prototype.mozMatchesSelector || function matches(selector) {
673
+ var element = this;
674
+ var elements = (element.document || element.ownerDocument).querySelectorAll(selector);
675
+ var index = 0;
676
+
677
+ while (elements[index] && elements[index] !== element) {
678
+ ++index;
679
+ }
680
+
681
+ return !!elements[index];
682
+ };
683
+
684
+ }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
685
+
686
+ (function(undefined) {
687
+
688
+ // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-service/1f3c09b402f65bf6e393f933a15ba63f1b86ef1f/packages/polyfill-library/polyfills/Element/prototype/closest/detect.js
689
+ var detect = (
690
+ 'document' in this && "closest" in document.documentElement
691
+ );
692
+
693
+ if (detect) return
694
+
695
+ // Polyfill from https://raw.githubusercontent.com/Financial-Times/polyfill-service/1f3c09b402f65bf6e393f933a15ba63f1b86ef1f/packages/polyfill-library/polyfills/Element/prototype/closest/polyfill.js
696
+ Element.prototype.closest = function closest(selector) {
697
+ var node = this;
698
+
699
+ while (node) {
700
+ if (node.matches(selector)) return node;
701
+ else node = 'SVGElement' in window && node instanceof SVGElement ? node.parentNode : node.parentElement;
702
+ }
703
+
704
+ return null;
705
+ };
706
+
707
+ }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
708
+
504
709
  function ErrorSummary ($module) {
505
710
  this.$module = $module;
506
711
  }
@@ -513,6 +718,119 @@ ErrorSummary.prototype.init = function () {
513
718
  window.addEventListener('load', function () {
514
719
  $module.focus();
515
720
  });
721
+
722
+ $module.addEventListener('click', this.handleClick.bind(this));
723
+ };
724
+
725
+ /**
726
+ * Click event handler
727
+ *
728
+ * @param {MouseEvent} event - Click event
729
+ */
730
+ ErrorSummary.prototype.handleClick = function (event) {
731
+ var target = event.target;
732
+ if (this.focusTarget(target)) {
733
+ event.preventDefault();
734
+ }
735
+ };
736
+
737
+ /**
738
+ * Focus the target element
739
+ *
740
+ * By default, the browser will scroll the target into view. Because our labels
741
+ * or legends appear above the input, this means the user will be presented with
742
+ * an input without any context, as the label or legend will be off the top of
743
+ * the screen.
744
+ *
745
+ * Manually handling the click event, scrolling the question into view and then
746
+ * focussing the element solves this.
747
+ *
748
+ * This also results in the label and/or legend being announced correctly in
749
+ * NVDA (as tested in 2018.3.2) - without this only the field type is announced
750
+ * (e.g. "Edit, has autocomplete").
751
+ *
752
+ * @param {HTMLElement} $target - Event target
753
+ * @returns {boolean} True if the target was able to be focussed
754
+ */
755
+ ErrorSummary.prototype.focusTarget = function ($target) {
756
+ // If the element that was clicked was not a link, return early
757
+ if ($target.tagName !== 'A' || $target.href === false) {
758
+ return false
759
+ }
760
+
761
+ var inputId = this.getFragmentFromUrl($target.href);
762
+ var $input = document.getElementById(inputId);
763
+ if (!$input) {
764
+ return false
765
+ }
766
+
767
+ var $legendOrLabel = this.getAssociatedLegendOrLabel($input);
768
+ if (!$legendOrLabel) {
769
+ return false
770
+ }
771
+
772
+ // Prefer using the history API where possible, as updating
773
+ // window.location.hash causes the viewport to jump to the input briefly
774
+ // before then scrolling to the label/legend in IE10, IE11 and Edge (as tested
775
+ // in Edge 17).
776
+ if (window.history.pushState) {
777
+ window.history.pushState(null, null, '#' + inputId);
778
+ } else {
779
+ window.location.hash = inputId;
780
+ }
781
+
782
+ // Scroll the legend or label into view *before* calling focus on the input to
783
+ // avoid extra scrolling in browsers that don't support `preventScroll` (which
784
+ // at time of writing is most of them...)
785
+ $legendOrLabel.scrollIntoView();
786
+ $input.focus({ preventScroll: true });
787
+
788
+ return true
789
+ };
790
+
791
+ /**
792
+ * Get fragment from URL
793
+ *
794
+ * Extract the fragment (everything after the hash) from a URL, but not including
795
+ * the hash.
796
+ *
797
+ * @param {string} url - URL
798
+ * @returns {string} Fragment from URL, without the hash
799
+ */
800
+ ErrorSummary.prototype.getFragmentFromUrl = function (url) {
801
+ if (url.indexOf('#') === -1) {
802
+ return false
803
+ }
804
+
805
+ return url.split('#').pop()
806
+ };
807
+
808
+ /**
809
+ * Get associated legend or label
810
+ *
811
+ * Returns the first element that exists from this list:
812
+ *
813
+ * - The `<legend>` associated with the closest `<fieldset>` ancestor
814
+ * - The first `<label>` that is associated with the input using for="inputId"
815
+ * - The closest parent `<label>`
816
+ *
817
+ * @param {HTMLElement} $input - The input
818
+ * @returns {HTMLElement} Associated legend or label, or null if no associated
819
+ * legend or label can be found
820
+ */
821
+ ErrorSummary.prototype.getAssociatedLegendOrLabel = function ($input) {
822
+ var $fieldset = $input.closest('fieldset');
823
+
824
+ if ($fieldset) {
825
+ var legends = $fieldset.getElementsByTagName('legend');
826
+
827
+ if (legends.length) {
828
+ return legends[0]
829
+ }
830
+ }
831
+
832
+ return document.querySelector("label[for='" + $input.getAttribute('id') + "']") ||
833
+ $input.closest('label')
516
834
  };
517
835
 
518
836
  return ErrorSummary;