govuk_publishing_components 32.1.0 → 33.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/component_guide/accessibility-test.js +0 -1
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-core.js +175 -0
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-ecommerce-tracker.js +4 -4
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-event-tracker.js +5 -13
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-link-tracker.js +80 -309
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-page-views.js +2 -2
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-specialist-link-tracker.js +140 -0
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/init-ga4.js +3 -0
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4.js +1 -0
- data/app/assets/javascripts/govuk_publishing_components/components/accordion.js +12 -1
- data/app/assets/javascripts/govuk_publishing_components/components/single-page-notification-button.js +24 -8
- data/app/assets/javascripts/govuk_publishing_components/components/step-by-step-nav.js +22 -1
- data/app/assets/javascripts/govuk_publishing_components/vendor/lux/lux-reporter.js +140 -191
- data/app/assets/stylesheets/govuk_publishing_components/components/_big-number.scss +2 -5
- data/app/assets/stylesheets/govuk_publishing_components/components/_image-card.scss +1 -5
- data/app/assets/stylesheets/govuk_publishing_components/components/_input.scss +3 -5
- data/app/assets/stylesheets/govuk_publishing_components/components/_layout-super-navigation-header.scss +10 -30
- data/app/assets/stylesheets/govuk_publishing_components/components/_search.scss +0 -7
- data/app/views/govuk_publishing_components/components/_accordion.html.erb +14 -1
- data/app/views/govuk_publishing_components/components/_error_summary.html.erb +27 -26
- data/app/views/govuk_publishing_components/components/_layout_super_navigation_header.html.erb +2 -2
- data/app/views/govuk_publishing_components/components/_phase_banner.html.erb +1 -1
- data/app/views/govuk_publishing_components/components/_share_links.html.erb +11 -13
- data/app/views/govuk_publishing_components/components/_single_page_notification_button.html.erb +1 -1
- data/app/views/govuk_publishing_components/components/_step_by_step_nav.html.erb +4 -1
- data/app/views/govuk_publishing_components/components/docs/accordion.yml +15 -3
- data/app/views/govuk_publishing_components/components/docs/button.yml +10 -0
- data/app/views/govuk_publishing_components/components/docs/share_links.yml +59 -30
- data/app/views/govuk_publishing_components/components/docs/single_page_notification_button.yml +10 -1
- data/app/views/govuk_publishing_components/components/docs/step_by_step_nav.yml +34 -0
- data/app/views/govuk_publishing_components/components/feedback/_problem_form.html.erb +1 -1
- data/app/views/govuk_publishing_components/components/feedback/_survey_signup_form.html.erb +1 -1
- data/app/views/govuk_publishing_components/components/feedback/_yes_no_banner.html.erb +3 -3
- data/lib/govuk_publishing_components/presenters/button_helper.rb +9 -2
- data/lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb +25 -1
- data/lib/govuk_publishing_components/version.rb +1 -1
- data/node_modules/axe-core/axe.js +4559 -4673
- data/node_modules/axe-core/axe.min.js +2 -2
- data/node_modules/axe-core/package.json +2 -2
- data/node_modules/axe-core/sri-history.json +4 -0
- data/node_modules/govuk-frontend/README.md +1 -2
- data/node_modules/govuk-frontend/govuk/all.js +1398 -273
- data/node_modules/govuk-frontend/govuk/common/closest-attribute-value.js +70 -0
- data/node_modules/govuk-frontend/govuk/common/index.js +172 -0
- data/node_modules/govuk-frontend/govuk/common/normalise-dataset.js +373 -0
- data/node_modules/govuk-frontend/govuk/common.js +138 -3
- data/node_modules/govuk-frontend/govuk/components/accordion/accordion.js +753 -25
- data/node_modules/govuk-frontend/govuk/components/accordion/fixtures.json +54 -22
- data/node_modules/govuk-frontend/govuk/components/accordion/macro-options.json +36 -0
- data/node_modules/govuk-frontend/govuk/components/accordion/template.njk +7 -1
- data/node_modules/govuk-frontend/govuk/components/back-link/fixtures.json +12 -12
- data/node_modules/govuk-frontend/govuk/components/breadcrumbs/fixtures.json +22 -22
- data/node_modules/govuk-frontend/govuk/components/button/_index.scss +23 -5
- data/node_modules/govuk-frontend/govuk/components/button/button.js +365 -107
- data/node_modules/govuk-frontend/govuk/components/button/fixtures.json +85 -66
- data/node_modules/govuk-frontend/govuk/components/button/template.njk +1 -1
- data/node_modules/govuk-frontend/govuk/components/character-count/_index.scss +9 -0
- data/node_modules/govuk-frontend/govuk/components/character-count/character-count.js +1033 -121
- data/node_modules/govuk-frontend/govuk/components/character-count/fixtures.json +112 -36
- data/node_modules/govuk-frontend/govuk/components/character-count/macro-options.json +42 -0
- data/node_modules/govuk-frontend/govuk/components/character-count/template.njk +27 -3
- data/node_modules/govuk-frontend/govuk/components/checkboxes/checkboxes.js +30 -2
- data/node_modules/govuk-frontend/govuk/components/checkboxes/fixtures.json +96 -93
- data/node_modules/govuk-frontend/govuk/components/cookie-banner/fixtures.json +46 -46
- data/node_modules/govuk-frontend/govuk/components/date-input/fixtures.json +50 -50
- data/node_modules/govuk-frontend/govuk/components/details/details.js +43 -13
- data/node_modules/govuk-frontend/govuk/components/details/fixtures.json +20 -20
- data/node_modules/govuk-frontend/govuk/components/error-message/fixtures.json +20 -20
- data/node_modules/govuk-frontend/govuk/components/error-summary/error-summary.js +268 -6
- data/node_modules/govuk-frontend/govuk/components/error-summary/fixtures.json +44 -35
- data/node_modules/govuk-frontend/govuk/components/error-summary/template.njk +25 -21
- data/node_modules/govuk-frontend/govuk/components/fieldset/fixtures.json +51 -39
- data/node_modules/govuk-frontend/govuk/components/file-upload/fixtures.json +26 -26
- data/node_modules/govuk-frontend/govuk/components/footer/_index.scss +1 -1
- data/node_modules/govuk-frontend/govuk/components/footer/fixtures.json +46 -46
- data/node_modules/govuk-frontend/govuk/components/footer/macro-options.json +2 -2
- data/node_modules/govuk-frontend/govuk/components/header/fixtures.json +93 -38
- data/node_modules/govuk-frontend/govuk/components/header/header.js +6 -0
- data/node_modules/govuk-frontend/govuk/components/header/macro-options.json +8 -2
- data/node_modules/govuk-frontend/govuk/components/header/template.njk +4 -2
- data/node_modules/govuk-frontend/govuk/components/hint/fixtures.json +12 -12
- data/node_modules/govuk-frontend/govuk/components/input/fixtures.json +80 -80
- data/node_modules/govuk-frontend/govuk/components/inset-text/fixtures.json +12 -12
- data/node_modules/govuk-frontend/govuk/components/label/fixtures.json +34 -34
- data/node_modules/govuk-frontend/govuk/components/notification-banner/fixtures.json +56 -46
- data/node_modules/govuk-frontend/govuk/components/notification-banner/notification-banner.js +252 -2
- data/node_modules/govuk-frontend/govuk/components/notification-banner/template.njk +1 -1
- data/node_modules/govuk-frontend/govuk/components/pagination/_index.scss +10 -7
- data/node_modules/govuk-frontend/govuk/components/pagination/fixtures.json +33 -26
- data/node_modules/govuk-frontend/govuk/components/panel/fixtures.json +18 -18
- data/node_modules/govuk-frontend/govuk/components/phase-banner/fixtures.json +14 -14
- data/node_modules/govuk-frontend/govuk/components/radios/fixtures.json +94 -91
- data/node_modules/govuk-frontend/govuk/components/radios/radios.js +30 -2
- data/node_modules/govuk-frontend/govuk/components/select/fixtures.json +32 -32
- data/node_modules/govuk-frontend/govuk/components/skip-link/fixtures.json +22 -20
- data/node_modules/govuk-frontend/govuk/components/skip-link/skip-link.js +10 -4
- data/node_modules/govuk-frontend/govuk/components/summary-list/fixtures.json +50 -50
- data/node_modules/govuk-frontend/govuk/components/table/_index.scss +1 -1
- data/node_modules/govuk-frontend/govuk/components/table/fixtures.json +40 -40
- data/node_modules/govuk-frontend/govuk/components/tabs/fixtures.json +29 -29
- data/node_modules/govuk-frontend/govuk/components/tabs/tabs.js +28 -0
- data/node_modules/govuk-frontend/govuk/components/tag/fixtures.json +28 -28
- data/node_modules/govuk-frontend/govuk/components/textarea/fixtures.json +34 -34
- data/node_modules/govuk-frontend/govuk/components/warning-text/fixtures.json +14 -14
- data/node_modules/govuk-frontend/govuk/core/_section-break.scss +1 -1
- data/node_modules/govuk-frontend/govuk/helpers/_colour.scss +2 -2
- data/node_modules/govuk-frontend/govuk/helpers/_links.scss +6 -6
- data/node_modules/govuk-frontend/govuk/i18n.js +390 -0
- data/node_modules/govuk-frontend/govuk/macros/i18n.njk +15 -0
- data/node_modules/govuk-frontend/govuk/settings/_all.scss +1 -0
- data/node_modules/govuk-frontend/govuk/settings/_colours-palette.scss +12 -0
- data/node_modules/govuk-frontend/govuk/settings/_compatibility.scss +26 -0
- data/node_modules/govuk-frontend/govuk/settings/_typography-font.scss +23 -0
- data/node_modules/govuk-frontend/govuk/settings/_typography-responsive.scss +12 -0
- data/node_modules/govuk-frontend/govuk/settings/_warnings.scss +53 -0
- data/node_modules/govuk-frontend/govuk/tools/_compatibility.scss +20 -6
- data/node_modules/govuk-frontend/govuk/vendor/polyfills/Date/now.js +21 -0
- data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element/prototype/dataset.js +300 -0
- data/node_modules/govuk-frontend/govuk/vendor/polyfills/String/prototype/trim.js +21 -0
- data/node_modules/govuk-frontend/govuk-esm/all.mjs +50 -27
- data/node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs +15 -0
- data/node_modules/govuk-frontend/govuk-esm/common/index.mjs +159 -0
- data/node_modules/govuk-frontend/govuk-esm/common/normalise-dataset.mjs +58 -0
- data/node_modules/govuk-frontend/govuk-esm/common.mjs +6 -28
- data/node_modules/govuk-frontend/govuk-esm/components/accordion/accordion.mjs +113 -43
- data/node_modules/govuk-frontend/govuk-esm/components/button/button.mjs +67 -30
- data/node_modules/govuk-frontend/govuk-esm/components/character-count/character-count.mjs +325 -123
- data/node_modules/govuk-frontend/govuk-esm/components/checkboxes/checkboxes.mjs +9 -3
- data/node_modules/govuk-frontend/govuk-esm/components/details/details.mjs +22 -8
- data/node_modules/govuk-frontend/govuk-esm/components/error-summary/error-summary.mjs +48 -6
- data/node_modules/govuk-frontend/govuk-esm/components/header/header.mjs +6 -0
- data/node_modules/govuk-frontend/govuk-esm/components/notification-banner/notification-banner.mjs +32 -2
- data/node_modules/govuk-frontend/govuk-esm/components/radios/radios.mjs +9 -3
- data/node_modules/govuk-frontend/govuk-esm/components/skip-link/skip-link.mjs +10 -4
- data/node_modules/govuk-frontend/govuk-esm/components/tabs/tabs.mjs +8 -2
- data/node_modules/govuk-frontend/govuk-esm/i18n.mjs +380 -0
- data/node_modules/govuk-frontend/govuk-esm/vendor/polyfills/Date/now.mjs +13 -0
- data/node_modules/govuk-frontend/govuk-esm/vendor/polyfills/Element/prototype/dataset.mjs +68 -0
- data/node_modules/govuk-frontend/govuk-esm/vendor/polyfills/String/prototype/trim.mjs +13 -0
- data/node_modules/govuk-frontend/govuk-prototype-kit/init.js +7 -0
- data/node_modules/govuk-frontend/govuk-prototype-kit/init.scss +12 -0
- data/node_modules/govuk-frontend/govuk-prototype-kit.config.json +138 -7
- data/node_modules/govuk-frontend/package.json +1 -1
- metadata +22 -3
@@ -0,0 +1,21 @@
|
|
1
|
+
(function (global, factory) {
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
|
3
|
+
typeof define === 'function' && define.amd ? define('GOVUKFrontend', factory) :
|
4
|
+
(factory());
|
5
|
+
}(this, (function () { 'use strict';
|
6
|
+
|
7
|
+
(function(undefined) {
|
8
|
+
|
9
|
+
// Detection from https://github.com/Financial-Times/polyfill-library/blob/v3.111.0/polyfills/Date/now/detect.js
|
10
|
+
var detect = ('Date' in self && 'now' in self.Date && 'getTime' in self.Date.prototype);
|
11
|
+
|
12
|
+
if (detect) return
|
13
|
+
|
14
|
+
// Polyfill from https://polyfill.io/v3/polyfill.js?version=3.111.0&features=Date.now&flags=always
|
15
|
+
Date.now = function () {
|
16
|
+
return new Date().getTime();
|
17
|
+
};
|
18
|
+
|
19
|
+
}).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
|
20
|
+
|
21
|
+
})));
|
@@ -0,0 +1,300 @@
|
|
1
|
+
(function (global, factory) {
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
|
3
|
+
typeof define === 'function' && define.amd ? define('GOVUKFrontend', factory) :
|
4
|
+
(factory());
|
5
|
+
}(this, (function () { 'use strict';
|
6
|
+
|
7
|
+
(function(undefined) {
|
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
|
+
|
96
|
+
// Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Document/detect.js
|
97
|
+
var detect = ("Document" in this);
|
98
|
+
|
99
|
+
if (detect) return
|
100
|
+
|
101
|
+
// Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Document&flags=always
|
102
|
+
if ((typeof WorkerGlobalScope === "undefined") && (typeof importScripts !== "function")) {
|
103
|
+
|
104
|
+
if (this.HTMLDocument) { // IE8
|
105
|
+
|
106
|
+
// HTMLDocument is an extension of Document. If the browser has HTMLDocument but not Document, the former will suffice as an alias for the latter.
|
107
|
+
this.Document = this.HTMLDocument;
|
108
|
+
|
109
|
+
} else {
|
110
|
+
|
111
|
+
// 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.
|
112
|
+
this.Document = this.HTMLDocument = document.constructor = (new Function('return function Document() {}')());
|
113
|
+
this.Document.prototype = document;
|
114
|
+
}
|
115
|
+
}
|
116
|
+
|
117
|
+
|
118
|
+
})
|
119
|
+
.call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
|
120
|
+
|
121
|
+
(function(undefined) {
|
122
|
+
|
123
|
+
// Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Element/detect.js
|
124
|
+
var detect = ('Element' in this && 'HTMLElement' in this);
|
125
|
+
|
126
|
+
if (detect) return
|
127
|
+
|
128
|
+
// Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Element&flags=always
|
129
|
+
(function () {
|
130
|
+
|
131
|
+
// IE8
|
132
|
+
if (window.Element && !window.HTMLElement) {
|
133
|
+
window.HTMLElement = window.Element;
|
134
|
+
return;
|
135
|
+
}
|
136
|
+
|
137
|
+
// create Element constructor
|
138
|
+
window.Element = window.HTMLElement = new Function('return function Element() {}')();
|
139
|
+
|
140
|
+
// generate sandboxed iframe
|
141
|
+
var vbody = document.appendChild(document.createElement('body'));
|
142
|
+
var frame = vbody.appendChild(document.createElement('iframe'));
|
143
|
+
|
144
|
+
// use sandboxed iframe to replicate Element functionality
|
145
|
+
var frameDocument = frame.contentWindow.document;
|
146
|
+
var prototype = Element.prototype = frameDocument.appendChild(frameDocument.createElement('*'));
|
147
|
+
var cache = {};
|
148
|
+
|
149
|
+
// polyfill Element.prototype on an element
|
150
|
+
var shiv = function (element, deep) {
|
151
|
+
var
|
152
|
+
childNodes = element.childNodes || [],
|
153
|
+
index = -1,
|
154
|
+
key, value, childNode;
|
155
|
+
|
156
|
+
if (element.nodeType === 1 && element.constructor !== Element) {
|
157
|
+
element.constructor = Element;
|
158
|
+
|
159
|
+
for (key in cache) {
|
160
|
+
value = cache[key];
|
161
|
+
element[key] = value;
|
162
|
+
}
|
163
|
+
}
|
164
|
+
|
165
|
+
while (childNode = deep && childNodes[++index]) {
|
166
|
+
shiv(childNode, deep);
|
167
|
+
}
|
168
|
+
|
169
|
+
return element;
|
170
|
+
};
|
171
|
+
|
172
|
+
var elements = document.getElementsByTagName('*');
|
173
|
+
var nativeCreateElement = document.createElement;
|
174
|
+
var interval;
|
175
|
+
var loopLimit = 100;
|
176
|
+
|
177
|
+
prototype.attachEvent('onpropertychange', function (event) {
|
178
|
+
var
|
179
|
+
propertyName = event.propertyName,
|
180
|
+
nonValue = !cache.hasOwnProperty(propertyName),
|
181
|
+
newValue = prototype[propertyName],
|
182
|
+
oldValue = cache[propertyName],
|
183
|
+
index = -1,
|
184
|
+
element;
|
185
|
+
|
186
|
+
while (element = elements[++index]) {
|
187
|
+
if (element.nodeType === 1) {
|
188
|
+
if (nonValue || element[propertyName] === oldValue) {
|
189
|
+
element[propertyName] = newValue;
|
190
|
+
}
|
191
|
+
}
|
192
|
+
}
|
193
|
+
|
194
|
+
cache[propertyName] = newValue;
|
195
|
+
});
|
196
|
+
|
197
|
+
prototype.constructor = Element;
|
198
|
+
|
199
|
+
if (!prototype.hasAttribute) {
|
200
|
+
// <Element>.hasAttribute
|
201
|
+
prototype.hasAttribute = function hasAttribute(name) {
|
202
|
+
return this.getAttribute(name) !== null;
|
203
|
+
};
|
204
|
+
}
|
205
|
+
|
206
|
+
// Apply Element prototype to the pre-existing DOM as soon as the body element appears.
|
207
|
+
function bodyCheck() {
|
208
|
+
if (!(loopLimit--)) clearTimeout(interval);
|
209
|
+
if (document.body && !document.body.prototype && /(complete|interactive)/.test(document.readyState)) {
|
210
|
+
shiv(document, true);
|
211
|
+
if (interval && document.body.prototype) clearTimeout(interval);
|
212
|
+
return (!!document.body.prototype);
|
213
|
+
}
|
214
|
+
return false;
|
215
|
+
}
|
216
|
+
if (!bodyCheck()) {
|
217
|
+
document.onreadystatechange = bodyCheck;
|
218
|
+
interval = setInterval(bodyCheck, 25);
|
219
|
+
}
|
220
|
+
|
221
|
+
// Apply to any new elements created after load
|
222
|
+
document.createElement = function createElement(nodeName) {
|
223
|
+
var element = nativeCreateElement(String(nodeName).toLowerCase());
|
224
|
+
return shiv(element);
|
225
|
+
};
|
226
|
+
|
227
|
+
// remove sandboxed iframe
|
228
|
+
document.removeChild(vbody);
|
229
|
+
}());
|
230
|
+
|
231
|
+
})
|
232
|
+
.call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
|
233
|
+
|
234
|
+
(function(undefined) {
|
235
|
+
|
236
|
+
// Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-library/13cf7c340974d128d557580b5e2dafcd1b1192d1/polyfills/Element/prototype/dataset/detect.js
|
237
|
+
var detect = (function(){
|
238
|
+
if (!document.documentElement.dataset) {
|
239
|
+
return false;
|
240
|
+
}
|
241
|
+
var el = document.createElement('div');
|
242
|
+
el.setAttribute("data-a-b", "c");
|
243
|
+
return el.dataset && el.dataset.aB == "c";
|
244
|
+
}());
|
245
|
+
|
246
|
+
if (detect) return
|
247
|
+
|
248
|
+
// Polyfill derived from https://raw.githubusercontent.com/Financial-Times/polyfill-library/13cf7c340974d128d557580b5e2dafcd1b1192d1/polyfills/Element/prototype/dataset/polyfill.js
|
249
|
+
Object.defineProperty(Element.prototype, 'dataset', {
|
250
|
+
get: function() {
|
251
|
+
var element = this;
|
252
|
+
var attributes = this.attributes;
|
253
|
+
var map = {};
|
254
|
+
|
255
|
+
for (var i = 0; i < attributes.length; i++) {
|
256
|
+
var attribute = attributes[i];
|
257
|
+
|
258
|
+
// This regex has been edited from the original polyfill, to add
|
259
|
+
// support for period (.) separators in data-* attribute names. These
|
260
|
+
// are allowed in the HTML spec, but were not covered by the original
|
261
|
+
// polyfill's regex. We use periods in our i18n implementation.
|
262
|
+
if (attribute && attribute.name && (/^data-\w[.\w-]*$/).test(attribute.name)) {
|
263
|
+
var name = attribute.name;
|
264
|
+
var value = attribute.value;
|
265
|
+
|
266
|
+
var propName = name.substr(5).replace(/-./g, function (prop) {
|
267
|
+
return prop.charAt(1).toUpperCase();
|
268
|
+
});
|
269
|
+
|
270
|
+
// If this browser supports __defineGetter__ and __defineSetter__,
|
271
|
+
// continue using defineProperty. If not (like IE 8 and below), we use
|
272
|
+
// a hacky fallback which at least gives an object in the right format
|
273
|
+
if ('__defineGetter__' in Object.prototype && '__defineSetter__' in Object.prototype) {
|
274
|
+
Object.defineProperty(map, propName, {
|
275
|
+
enumerable: true,
|
276
|
+
get: function() {
|
277
|
+
return this.value;
|
278
|
+
}.bind({value: value || ''}),
|
279
|
+
set: function setter(name, value) {
|
280
|
+
if (typeof value !== 'undefined') {
|
281
|
+
this.setAttribute(name, value);
|
282
|
+
} else {
|
283
|
+
this.removeAttribute(name);
|
284
|
+
}
|
285
|
+
}.bind(element, name)
|
286
|
+
});
|
287
|
+
} else {
|
288
|
+
map[propName] = value;
|
289
|
+
}
|
290
|
+
|
291
|
+
}
|
292
|
+
}
|
293
|
+
|
294
|
+
return map;
|
295
|
+
}
|
296
|
+
});
|
297
|
+
|
298
|
+
}).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
|
299
|
+
|
300
|
+
})));
|
@@ -0,0 +1,21 @@
|
|
1
|
+
(function (global, factory) {
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
|
3
|
+
typeof define === 'function' && define.amd ? define('GOVUKFrontend', factory) :
|
4
|
+
(factory());
|
5
|
+
}(this, (function () { 'use strict';
|
6
|
+
|
7
|
+
(function(undefined) {
|
8
|
+
|
9
|
+
// Detection from https://github.com/mdn/content/blob/cf607d68522cd35ee7670782d3ee3a361eaef2e4/files/en-us/web/javascript/reference/global_objects/string/trim/index.md#polyfill
|
10
|
+
var detect = ('trim' in String.prototype);
|
11
|
+
|
12
|
+
if (detect) return
|
13
|
+
|
14
|
+
// Polyfill from https://github.com/mdn/content/blob/cf607d68522cd35ee7670782d3ee3a361eaef2e4/files/en-us/web/javascript/reference/global_objects/string/trim/index.md#polyfill
|
15
|
+
String.prototype.trim = function () {
|
16
|
+
return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
|
17
|
+
};
|
18
|
+
|
19
|
+
}).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
|
20
|
+
|
21
|
+
})));
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { nodeListForEach } from './common.mjs'
|
1
|
+
import { nodeListForEach } from './common/index.mjs'
|
2
2
|
import Accordion from './components/accordion/accordion.mjs'
|
3
3
|
import Button from './components/button/button.mjs'
|
4
4
|
import Details from './components/details/details.mjs'
|
@@ -11,62 +11,73 @@ import Radios from './components/radios/radios.mjs'
|
|
11
11
|
import SkipLink from './components/skip-link/skip-link.mjs'
|
12
12
|
import Tabs from './components/tabs/tabs.mjs'
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
/**
|
15
|
+
* Initialise all components
|
16
|
+
*
|
17
|
+
* Use the `data-module` attributes to find, instantiate and init all of the
|
18
|
+
* components provided as part of GOV.UK Frontend.
|
19
|
+
*
|
20
|
+
* @param {Config} [config] - Config for all components
|
21
|
+
*/
|
22
|
+
function initAll (config) {
|
23
|
+
config = typeof config !== 'undefined' ? config : {}
|
17
24
|
|
18
25
|
// Allow the user to initialise GOV.UK Frontend in only certain sections of the page
|
19
26
|
// Defaults to the entire document if nothing is set.
|
20
|
-
var scope = typeof
|
27
|
+
var $scope = typeof config.scope !== 'undefined' ? config.scope : document
|
21
28
|
|
22
|
-
var $
|
23
|
-
nodeListForEach($buttons, function ($button) {
|
24
|
-
new Button($button).init()
|
25
|
-
})
|
26
|
-
|
27
|
-
var $accordions = scope.querySelectorAll('[data-module="govuk-accordion"]')
|
29
|
+
var $accordions = $scope.querySelectorAll('[data-module="govuk-accordion"]')
|
28
30
|
nodeListForEach($accordions, function ($accordion) {
|
29
|
-
new Accordion($accordion).init()
|
31
|
+
new Accordion($accordion, config.accordion).init()
|
30
32
|
})
|
31
33
|
|
32
|
-
var $
|
33
|
-
nodeListForEach($
|
34
|
-
new
|
34
|
+
var $buttons = $scope.querySelectorAll('[data-module="govuk-button"]')
|
35
|
+
nodeListForEach($buttons, function ($button) {
|
36
|
+
new Button($button, config.button).init()
|
35
37
|
})
|
36
38
|
|
37
|
-
var $characterCounts = scope.querySelectorAll('[data-module="govuk-character-count"]')
|
39
|
+
var $characterCounts = $scope.querySelectorAll('[data-module="govuk-character-count"]')
|
38
40
|
nodeListForEach($characterCounts, function ($characterCount) {
|
39
|
-
new CharacterCount($characterCount).init()
|
41
|
+
new CharacterCount($characterCount, config.characterCount).init()
|
40
42
|
})
|
41
43
|
|
42
|
-
var $checkboxes = scope.querySelectorAll('[data-module="govuk-checkboxes"]')
|
44
|
+
var $checkboxes = $scope.querySelectorAll('[data-module="govuk-checkboxes"]')
|
43
45
|
nodeListForEach($checkboxes, function ($checkbox) {
|
44
46
|
new Checkboxes($checkbox).init()
|
45
47
|
})
|
46
48
|
|
49
|
+
var $details = $scope.querySelectorAll('[data-module="govuk-details"]')
|
50
|
+
nodeListForEach($details, function ($detail) {
|
51
|
+
new Details($detail).init()
|
52
|
+
})
|
53
|
+
|
47
54
|
// Find first error summary module to enhance.
|
48
|
-
var $errorSummary = scope.querySelector('[data-module="govuk-error-summary"]')
|
49
|
-
|
55
|
+
var $errorSummary = $scope.querySelector('[data-module="govuk-error-summary"]')
|
56
|
+
if ($errorSummary) {
|
57
|
+
new ErrorSummary($errorSummary, config.errorSummary).init()
|
58
|
+
}
|
50
59
|
|
51
60
|
// Find first header module to enhance.
|
52
|
-
var $
|
53
|
-
|
61
|
+
var $header = $scope.querySelector('[data-module="govuk-header"]')
|
62
|
+
if ($header) {
|
63
|
+
new Header($header).init()
|
64
|
+
}
|
54
65
|
|
55
|
-
var $notificationBanners = scope.querySelectorAll('[data-module="govuk-notification-banner"]')
|
66
|
+
var $notificationBanners = $scope.querySelectorAll('[data-module="govuk-notification-banner"]')
|
56
67
|
nodeListForEach($notificationBanners, function ($notificationBanner) {
|
57
|
-
new NotificationBanner($notificationBanner).init()
|
68
|
+
new NotificationBanner($notificationBanner, config.notificationBanner).init()
|
58
69
|
})
|
59
70
|
|
60
|
-
var $radios = scope.querySelectorAll('[data-module="govuk-radios"]')
|
71
|
+
var $radios = $scope.querySelectorAll('[data-module="govuk-radios"]')
|
61
72
|
nodeListForEach($radios, function ($radio) {
|
62
73
|
new Radios($radio).init()
|
63
74
|
})
|
64
75
|
|
65
76
|
// Find first skip link module to enhance.
|
66
|
-
var $skipLink = scope.querySelector('[data-module="govuk-skip-link"]')
|
77
|
+
var $skipLink = $scope.querySelector('[data-module="govuk-skip-link"]')
|
67
78
|
new SkipLink($skipLink).init()
|
68
79
|
|
69
|
-
var $tabs = scope.querySelectorAll('[data-module="govuk-tabs"]')
|
80
|
+
var $tabs = $scope.querySelectorAll('[data-module="govuk-tabs"]')
|
70
81
|
nodeListForEach($tabs, function ($tabs) {
|
71
82
|
new Tabs($tabs).init()
|
72
83
|
})
|
@@ -86,3 +97,15 @@ export {
|
|
86
97
|
SkipLink,
|
87
98
|
Tabs
|
88
99
|
}
|
100
|
+
|
101
|
+
/**
|
102
|
+
* Config for all components
|
103
|
+
*
|
104
|
+
* @typedef {object} Config
|
105
|
+
* @property {HTMLElement} [scope=document] - Scope to query for components
|
106
|
+
* @property {import('./components/accordion/accordion.mjs').AccordionConfig} [accordion] - Accordion config
|
107
|
+
* @property {import('./components/button/button.mjs').ButtonConfig} [button] - Button config
|
108
|
+
* @property {import('./components/character-count/character-count.mjs').CharacterCountConfig} [characterCount] - Character Count config
|
109
|
+
* @property {import('./components/error-summary/error-summary.mjs').ErrorSummaryConfig} [errorSummary] - Error Summary config
|
110
|
+
* @property {import('./components/notification-banner/notification-banner.mjs').NotificationBannerConfig} [notificationBanner] - Notification Banner config
|
111
|
+
*/
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import '../vendor/polyfills/Element/prototype/closest.mjs'
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Returns the value of the given attribute closest to the given element (including itself)
|
5
|
+
*
|
6
|
+
* @param {HTMLElement} $element - The element to start walking the DOM tree up
|
7
|
+
* @param {string} attributeName - The name of the attribute
|
8
|
+
* @returns {string | undefined} Attribute value
|
9
|
+
*/
|
10
|
+
export function closestAttributeValue ($element, attributeName) {
|
11
|
+
var closestElementWithAttribute = $element.closest('[' + attributeName + ']')
|
12
|
+
if (closestElementWithAttribute) {
|
13
|
+
return closestElementWithAttribute.getAttribute(attributeName)
|
14
|
+
}
|
15
|
+
}
|
@@ -0,0 +1,159 @@
|
|
1
|
+
/**
|
2
|
+
* Common helpers which do not require polyfill.
|
3
|
+
*
|
4
|
+
* IMPORTANT: If a helper require a polyfill, please isolate it in its own module
|
5
|
+
* so that the polyfill can be properly tree-shaken and does not burden
|
6
|
+
* the components that do not need that helper
|
7
|
+
*
|
8
|
+
* @module common/index
|
9
|
+
*/
|
10
|
+
|
11
|
+
/**
|
12
|
+
* TODO: Ideally this would be a NodeList.prototype.forEach polyfill
|
13
|
+
* This seems to fail in IE8, requires more investigation.
|
14
|
+
* See: https://github.com/imagitama/nodelist-foreach-polyfill
|
15
|
+
*
|
16
|
+
* @param {NodeListOf<Element>} nodes - NodeList from querySelectorAll()
|
17
|
+
* @param {nodeListIterator} callback - Callback function to run for each node
|
18
|
+
* @returns {undefined}
|
19
|
+
*/
|
20
|
+
export function nodeListForEach (nodes, callback) {
|
21
|
+
if (window.NodeList.prototype.forEach) {
|
22
|
+
return nodes.forEach(callback)
|
23
|
+
}
|
24
|
+
for (var i = 0; i < nodes.length; i++) {
|
25
|
+
callback.call(window, nodes[i], i, nodes)
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
/**
|
30
|
+
* Used to generate a unique string, allows multiple instances of the component
|
31
|
+
* without them conflicting with each other.
|
32
|
+
* https://stackoverflow.com/a/8809472
|
33
|
+
*
|
34
|
+
* @returns {string} Unique ID
|
35
|
+
*/
|
36
|
+
export function generateUniqueID () {
|
37
|
+
var d = new Date().getTime()
|
38
|
+
if (typeof window.performance !== 'undefined' && typeof window.performance.now === 'function') {
|
39
|
+
d += window.performance.now() // use high-precision timer if available
|
40
|
+
}
|
41
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
42
|
+
var r = (d + Math.random() * 16) % 16 | 0
|
43
|
+
d = Math.floor(d / 16)
|
44
|
+
return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16)
|
45
|
+
})
|
46
|
+
}
|
47
|
+
|
48
|
+
/**
|
49
|
+
* Config flattening function
|
50
|
+
*
|
51
|
+
* Takes any number of objects, flattens them into namespaced key-value pairs,
|
52
|
+
* (e.g. {'i18n.showSection': 'Show section'}) and combines them together, with
|
53
|
+
* greatest priority on the LAST item passed in.
|
54
|
+
*
|
55
|
+
* @returns {object} A flattened object of key-value pairs.
|
56
|
+
*/
|
57
|
+
export function mergeConfigs (/* configObject1, configObject2, ...configObjects */) {
|
58
|
+
/**
|
59
|
+
* Function to take nested objects and flatten them to a dot-separated keyed
|
60
|
+
* object. Doing this means we don't need to do any deep/recursive merging of
|
61
|
+
* each of our objects, nor transform our dataset from a flat list into a
|
62
|
+
* nested object.
|
63
|
+
*
|
64
|
+
* @param {object} configObject - Deeply nested object
|
65
|
+
* @returns {object} Flattened object with dot-separated keys
|
66
|
+
*/
|
67
|
+
var flattenObject = function (configObject) {
|
68
|
+
// Prepare an empty return object
|
69
|
+
var flattenedObject = {}
|
70
|
+
|
71
|
+
// Our flattening function, this is called recursively for each level of
|
72
|
+
// depth in the object. At each level we prepend the previous level names to
|
73
|
+
// the key using `prefix`.
|
74
|
+
var flattenLoop = function (obj, prefix) {
|
75
|
+
// Loop through keys...
|
76
|
+
for (var key in obj) {
|
77
|
+
// Check to see if this is a prototypical key/value,
|
78
|
+
// if it is, skip it.
|
79
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key)) {
|
80
|
+
continue
|
81
|
+
}
|
82
|
+
var value = obj[key]
|
83
|
+
var prefixedKey = prefix ? prefix + '.' + key : key
|
84
|
+
if (typeof value === 'object') {
|
85
|
+
// If the value is a nested object, recurse over that too
|
86
|
+
flattenLoop(value, prefixedKey)
|
87
|
+
} else {
|
88
|
+
// Otherwise, add this value to our return object
|
89
|
+
flattenedObject[prefixedKey] = value
|
90
|
+
}
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
// Kick off the recursive loop
|
95
|
+
flattenLoop(configObject)
|
96
|
+
return flattenedObject
|
97
|
+
}
|
98
|
+
|
99
|
+
// Start with an empty object as our base
|
100
|
+
var formattedConfigObject = {}
|
101
|
+
|
102
|
+
// Loop through each of the remaining passed objects and push their keys
|
103
|
+
// one-by-one into configObject. Any duplicate keys will override the existing
|
104
|
+
// key with the new value.
|
105
|
+
for (var i = 0; i < arguments.length; i++) {
|
106
|
+
var obj = flattenObject(arguments[i])
|
107
|
+
for (var key in obj) {
|
108
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
109
|
+
formattedConfigObject[key] = obj[key]
|
110
|
+
}
|
111
|
+
}
|
112
|
+
}
|
113
|
+
|
114
|
+
return formattedConfigObject
|
115
|
+
}
|
116
|
+
|
117
|
+
/**
|
118
|
+
* Extracts keys starting with a particular namespace from a flattened config
|
119
|
+
* object, removing the namespace in the process.
|
120
|
+
*
|
121
|
+
* @param {object} configObject - The object to extract key-value pairs from.
|
122
|
+
* @param {string} namespace - The namespace to filter keys with.
|
123
|
+
* @returns {object} Flattened object with dot-separated key namespace removed
|
124
|
+
*/
|
125
|
+
export function extractConfigByNamespace (configObject, namespace) {
|
126
|
+
// Check we have what we need
|
127
|
+
if (!configObject || typeof configObject !== 'object') {
|
128
|
+
throw new Error('Provide a `configObject` of type "object".')
|
129
|
+
}
|
130
|
+
if (!namespace || typeof namespace !== 'string') {
|
131
|
+
throw new Error('Provide a `namespace` of type "string" to filter the `configObject` by.')
|
132
|
+
}
|
133
|
+
var newObject = {}
|
134
|
+
for (var key in configObject) {
|
135
|
+
// Split the key into parts, using . as our namespace separator
|
136
|
+
var keyParts = key.split('.')
|
137
|
+
// Check if the first namespace matches the configured namespace
|
138
|
+
if (Object.prototype.hasOwnProperty.call(configObject, key) && keyParts[0] === namespace) {
|
139
|
+
// Remove the first item (the namespace) from the parts array,
|
140
|
+
// but only if there is more than one part (we don't want blank keys!)
|
141
|
+
if (keyParts.length > 1) {
|
142
|
+
keyParts.shift()
|
143
|
+
}
|
144
|
+
// Join the remaining parts back together
|
145
|
+
var newKey = keyParts.join('.')
|
146
|
+
// Add them to our new object
|
147
|
+
newObject[newKey] = configObject[key]
|
148
|
+
}
|
149
|
+
}
|
150
|
+
return newObject
|
151
|
+
}
|
152
|
+
|
153
|
+
/**
|
154
|
+
* @callback nodeListIterator
|
155
|
+
* @param {Element} value - The current node being iterated on
|
156
|
+
* @param {number} index - The current index in the iteration
|
157
|
+
* @param {NodeListOf<Element>} nodes - NodeList from querySelectorAll()
|
158
|
+
* @returns {undefined}
|
159
|
+
*/
|