@ministryofjustice/frontend 4.0.1 → 5.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.
- package/govuk-prototype-kit.config.json +19 -4
- package/moj/_base.scss +2 -0
- package/moj/_base.scss.map +1 -0
- package/moj/all.bundle.js +3010 -0
- package/moj/all.bundle.js.map +1 -0
- package/moj/all.bundle.mjs +3293 -0
- package/moj/all.bundle.mjs.map +1 -0
- package/moj/all.mjs +17 -110
- package/moj/all.mjs.map +1 -1
- package/moj/all.scss +3 -0
- package/moj/all.scss.map +1 -0
- package/moj/common/index.mjs +57 -0
- package/moj/common/index.mjs.map +1 -0
- package/moj/common/moj-frontend-version.mjs +14 -0
- package/moj/common/moj-frontend-version.mjs.map +1 -0
- package/moj/components/_all.scss +2 -0
- package/moj/components/_all.scss.map +1 -0
- package/moj/components/action-bar/_action-bar.scss +2 -0
- package/moj/components/action-bar/_action-bar.scss.map +1 -0
- package/moj/components/add-another/_add-another.scss +2 -0
- package/moj/components/add-another/_add-another.scss.map +1 -0
- package/moj/components/add-another/add-another.bundle.js +157 -0
- package/moj/components/add-another/add-another.bundle.js.map +1 -0
- package/moj/components/add-another/add-another.bundle.mjs +271 -0
- package/moj/components/add-another/add-another.bundle.mjs.map +1 -0
- package/moj/components/add-another/add-another.mjs +135 -91
- package/moj/components/add-another/add-another.mjs.map +1 -1
- package/moj/components/alert/_alert.scss +4 -0
- package/moj/components/alert/_alert.scss.map +1 -0
- package/moj/components/alert/alert.bundle.js +254 -0
- package/moj/components/alert/alert.bundle.js.map +1 -0
- package/moj/components/alert/alert.bundle.mjs +490 -0
- package/moj/components/alert/alert.bundle.mjs.map +1 -0
- package/moj/components/alert/alert.mjs +97 -218
- package/moj/components/alert/alert.mjs.map +1 -1
- package/moj/components/alert/{alert.spec.helper.js → alert.spec.helper.bundle.js} +1 -1
- package/moj/components/alert/alert.spec.helper.bundle.js.map +1 -0
- package/moj/components/alert/alert.spec.helper.bundle.mjs +67 -0
- package/moj/components/alert/alert.spec.helper.bundle.mjs.map +1 -0
- package/moj/components/alert/alert.spec.helper.mjs.map +1 -1
- package/moj/components/badge/_badge.scss +2 -0
- package/moj/components/badge/_badge.scss.map +1 -0
- package/moj/components/banner/_banner.scss +2 -0
- package/moj/components/banner/_banner.scss.map +1 -0
- package/moj/components/button-menu/README.md +12 -6
- package/moj/components/button-menu/_button-menu.scss +4 -1
- package/moj/components/button-menu/_button-menu.scss.map +1 -0
- package/moj/components/button-menu/button-menu.bundle.js +270 -0
- package/moj/components/button-menu/button-menu.bundle.js.map +1 -0
- package/moj/components/button-menu/button-menu.bundle.mjs +506 -0
- package/moj/components/button-menu/button-menu.bundle.mjs.map +1 -0
- package/moj/components/button-menu/button-menu.mjs +214 -280
- package/moj/components/button-menu/button-menu.mjs.map +1 -1
- package/moj/components/cookie-banner/_cookie-banner.scss +2 -0
- package/moj/components/cookie-banner/_cookie-banner.scss.map +1 -0
- package/moj/components/currency-input/_currency-input.scss +2 -0
- package/moj/components/currency-input/_currency-input.scss.map +1 -0
- package/moj/components/date-picker/_date-picker.scss +2 -0
- package/moj/components/date-picker/_date-picker.scss.map +1 -0
- package/moj/components/date-picker/date-picker.bundle.js +804 -0
- package/moj/components/date-picker/date-picker.bundle.js.map +1 -0
- package/moj/components/date-picker/date-picker.bundle.mjs +1040 -0
- package/moj/components/date-picker/date-picker.bundle.mjs.map +1 -0
- package/moj/components/date-picker/date-picker.mjs +663 -827
- package/moj/components/date-picker/date-picker.mjs.map +1 -1
- package/moj/components/filter/_filter.scss +2 -0
- package/moj/components/filter/_filter.scss.map +1 -0
- package/moj/components/filter/template.njk +1 -1
- package/moj/components/filter-toggle-button/filter-toggle-button.bundle.js +185 -0
- package/moj/components/filter-toggle-button/filter-toggle-button.bundle.js.map +1 -0
- package/moj/components/filter-toggle-button/filter-toggle-button.bundle.mjs +421 -0
- package/moj/components/filter-toggle-button/filter-toggle-button.bundle.mjs.map +1 -0
- package/moj/components/filter-toggle-button/filter-toggle-button.mjs +166 -81
- package/moj/components/filter-toggle-button/filter-toggle-button.mjs.map +1 -1
- package/moj/components/form-validator/form-validator.bundle.js +288 -0
- package/moj/components/form-validator/form-validator.bundle.js.map +1 -0
- package/moj/components/form-validator/form-validator.bundle.mjs +524 -0
- package/moj/components/form-validator/form-validator.bundle.mjs.map +1 -0
- package/moj/components/form-validator/form-validator.mjs +226 -149
- package/moj/components/form-validator/form-validator.mjs.map +1 -1
- package/moj/components/header/_header.scss +2 -0
- package/moj/components/header/_header.scss.map +1 -0
- package/moj/components/identity-bar/_identity-bar.scss +2 -0
- package/moj/components/identity-bar/_identity-bar.scss.map +1 -0
- package/moj/components/interruption-card/_interruption-card.scss +2 -0
- package/moj/components/interruption-card/_interruption-card.scss.map +1 -0
- package/moj/components/messages/_messages.scss +2 -0
- package/moj/components/messages/_messages.scss.map +1 -0
- package/moj/components/multi-file-upload/_multi-file-upload.scss +2 -0
- package/moj/components/multi-file-upload/_multi-file-upload.scss.map +1 -0
- package/moj/components/multi-file-upload/multi-file-upload.bundle.js +397 -0
- package/moj/components/multi-file-upload/multi-file-upload.bundle.js.map +1 -0
- package/moj/components/multi-file-upload/multi-file-upload.bundle.mjs +633 -0
- package/moj/components/multi-file-upload/multi-file-upload.bundle.mjs.map +1 -0
- package/moj/components/multi-file-upload/multi-file-upload.mjs +384 -213
- package/moj/components/multi-file-upload/multi-file-upload.mjs.map +1 -1
- package/moj/components/multi-file-upload/template.njk +1 -1
- package/moj/components/multi-select/_multi-select.scss +2 -0
- package/moj/components/multi-select/_multi-select.scss.map +1 -0
- package/moj/components/multi-select/multi-select.bundle.js +143 -0
- package/moj/components/multi-select/multi-select.bundle.js.map +1 -0
- package/moj/components/multi-select/multi-select.bundle.mjs +379 -0
- package/moj/components/multi-select/multi-select.bundle.mjs.map +1 -0
- package/moj/components/multi-select/multi-select.mjs +123 -64
- package/moj/components/multi-select/multi-select.mjs.map +1 -1
- package/moj/components/notification-badge/_notification-badge.scss +2 -0
- package/moj/components/notification-badge/_notification-badge.scss.map +1 -0
- package/moj/components/organisation-switcher/_organisation-switcher.scss +2 -0
- package/moj/components/organisation-switcher/_organisation-switcher.scss.map +1 -0
- package/moj/components/page-header-actions/_page-header-actions.scss +2 -0
- package/moj/components/page-header-actions/_page-header-actions.scss.map +1 -0
- package/moj/components/pagination/_pagination.scss +2 -2
- package/moj/components/pagination/_pagination.scss.map +1 -0
- package/moj/components/password-reveal/_password-reveal.scss +5 -1
- package/moj/components/password-reveal/_password-reveal.scss.map +1 -0
- package/moj/components/password-reveal/password-reveal.bundle.js +52 -0
- package/moj/components/password-reveal/password-reveal.bundle.js.map +1 -0
- package/moj/components/password-reveal/password-reveal.bundle.mjs +166 -0
- package/moj/components/password-reveal/password-reveal.bundle.mjs.map +1 -0
- package/moj/components/password-reveal/password-reveal.mjs +39 -29
- package/moj/components/password-reveal/password-reveal.mjs.map +1 -1
- package/moj/components/primary-navigation/_primary-navigation.scss +2 -0
- package/moj/components/primary-navigation/_primary-navigation.scss.map +1 -0
- package/moj/components/progress-bar/_progress-bar.scss +2 -0
- package/moj/components/progress-bar/_progress-bar.scss.map +1 -0
- package/moj/components/rich-text-editor/README.md +16 -9
- package/moj/components/rich-text-editor/_rich-text-editor.scss +2 -0
- package/moj/components/rich-text-editor/_rich-text-editor.scss.map +1 -0
- package/moj/components/rich-text-editor/rich-text-editor.bundle.js +210 -0
- package/moj/components/rich-text-editor/rich-text-editor.bundle.js.map +1 -0
- package/moj/components/rich-text-editor/rich-text-editor.bundle.mjs +446 -0
- package/moj/components/rich-text-editor/rich-text-editor.bundle.mjs.map +1 -0
- package/moj/components/rich-text-editor/rich-text-editor.mjs +186 -140
- package/moj/components/rich-text-editor/rich-text-editor.mjs.map +1 -1
- package/moj/components/search/_search.scss +2 -0
- package/moj/components/search/_search.scss.map +1 -0
- package/moj/components/search-toggle/{search-toggle.scss → _search-toggle.scss} +2 -0
- package/moj/components/search-toggle/_search-toggle.scss.map +1 -0
- package/moj/components/search-toggle/search-toggle.bundle.js +122 -0
- package/moj/components/search-toggle/search-toggle.bundle.js.map +1 -0
- package/moj/components/search-toggle/search-toggle.bundle.mjs +358 -0
- package/moj/components/search-toggle/search-toggle.bundle.mjs.map +1 -0
- package/moj/components/search-toggle/search-toggle.mjs +104 -43
- package/moj/components/search-toggle/search-toggle.mjs.map +1 -1
- package/moj/components/side-navigation/_side-navigation.scss +2 -0
- package/moj/components/side-navigation/_side-navigation.scss.map +1 -0
- package/moj/components/sortable-table/_sortable-table.scss +2 -2
- package/moj/components/sortable-table/_sortable-table.scss.map +1 -0
- package/moj/components/sortable-table/sortable-table.bundle.js +202 -0
- package/moj/components/sortable-table/sortable-table.bundle.js.map +1 -0
- package/moj/components/sortable-table/sortable-table.bundle.mjs +438 -0
- package/moj/components/sortable-table/sortable-table.bundle.mjs.map +1 -0
- package/moj/components/sortable-table/sortable-table.mjs +179 -122
- package/moj/components/sortable-table/sortable-table.mjs.map +1 -1
- package/moj/components/sub-navigation/_sub-navigation.scss +2 -0
- package/moj/components/sub-navigation/_sub-navigation.scss.map +1 -0
- package/moj/components/tag/_tag.scss +2 -0
- package/moj/components/tag/_tag.scss.map +1 -0
- package/moj/components/task-list/_task-list.scss +2 -0
- package/moj/components/task-list/_task-list.scss.map +1 -0
- package/moj/components/ticket-panel/_ticket-panel.scss +2 -0
- package/moj/components/ticket-panel/_ticket-panel.scss.map +1 -0
- package/moj/components/timeline/_timeline.scss +2 -0
- package/moj/components/timeline/_timeline.scss.map +1 -0
- package/moj/core/_all.scss +3 -0
- package/moj/core/_all.scss.map +1 -0
- package/moj/core/_moj-frontend-properties.scss +7 -0
- package/moj/core/_moj-frontend-properties.scss.map +1 -0
- package/moj/filters/all.js +44 -22
- package/moj/filters/prototype-kit-13-filters.js +4 -3
- package/moj/helpers/_all.scss +2 -0
- package/moj/helpers/_all.scss.map +1 -0
- package/moj/helpers/_hidden.scss +2 -0
- package/moj/helpers/_hidden.scss.map +1 -0
- package/moj/helpers/_links.scss +2 -0
- package/moj/helpers/_links.scss.map +1 -0
- package/moj/helpers.bundle.js +140 -0
- package/moj/helpers.bundle.js.map +1 -0
- package/moj/helpers.bundle.mjs +128 -0
- package/moj/helpers.bundle.mjs.map +1 -0
- package/moj/helpers.mjs +50 -77
- package/moj/helpers.mjs.map +1 -1
- package/moj/init.js +11 -2
- package/moj/moj-frontend.min.css +1 -1
- package/moj/moj-frontend.min.css.map +1 -1
- package/moj/moj-frontend.min.js +1 -1
- package/moj/moj-frontend.min.js.map +1 -1
- package/moj/objects/_all.scss +2 -0
- package/moj/objects/_all.scss.map +1 -0
- package/moj/objects/_button-group.scss +2 -0
- package/moj/objects/_button-group.scss.map +1 -0
- package/moj/objects/_filter-layout.scss +2 -0
- package/moj/objects/_filter-layout.scss.map +1 -0
- package/moj/objects/_scrollable-pane.scss +2 -0
- package/moj/objects/_scrollable-pane.scss.map +1 -0
- package/moj/objects/_width-container.scss +2 -0
- package/moj/objects/_width-container.scss.map +1 -0
- package/moj/settings/_all.scss +2 -0
- package/moj/settings/_all.scss.map +1 -0
- package/moj/settings/_assets.scss +2 -0
- package/moj/settings/_assets.scss.map +1 -0
- package/moj/settings/_colours.scss +2 -0
- package/moj/settings/_colours.scss.map +1 -0
- package/moj/settings/_measurements.scss +2 -0
- package/moj/settings/_measurements.scss.map +1 -0
- package/moj/settings/_typography.scss +2 -0
- package/moj/settings/_typography.scss.map +1 -0
- package/moj/template.njk +13 -0
- package/moj/utilities/_all.scss +2 -0
- package/moj/utilities/_all.scss.map +1 -0
- package/moj/utilities/_hidden.scss +2 -0
- package/moj/utilities/_hidden.scss.map +1 -0
- package/moj/utilities/_width-container.scss +2 -0
- package/moj/utilities/_width-container.scss.map +1 -0
- package/moj/vendor/govuk-frontend/_base.scss +2 -0
- package/moj/vendor/govuk-frontend/_base.scss.map +1 -0
- package/moj/vendor/govuk-frontend/_index.scss +2 -0
- package/moj/vendor/govuk-frontend/_index.scss.map +1 -0
- package/package.json +5 -6
- package/moj/all.jquery.min.js +0 -1
- package/moj/all.jquery.min.js.map +0 -1
- package/moj/all.js +0 -2662
- package/moj/all.js.map +0 -1
- package/moj/components/add-another/add-another.js +0 -115
- package/moj/components/add-another/add-another.js.map +0 -1
- package/moj/components/alert/alert.js +0 -356
- package/moj/components/alert/alert.js.map +0 -1
- package/moj/components/alert/alert.spec.helper.js.map +0 -1
- package/moj/components/button-menu/button-menu.js +0 -338
- package/moj/components/button-menu/button-menu.js.map +0 -1
- package/moj/components/date-picker/date-picker.js +0 -970
- package/moj/components/date-picker/date-picker.js.map +0 -1
- package/moj/components/filter-toggle-button/filter-toggle-button.js +0 -102
- package/moj/components/filter-toggle-button/filter-toggle-button.js.map +0 -1
- package/moj/components/form-validator/form-validator.js +0 -205
- package/moj/components/form-validator/form-validator.js.map +0 -1
- package/moj/components/multi-file-upload/multi-file-upload.js +0 -241
- package/moj/components/multi-file-upload/multi-file-upload.js.map +0 -1
- package/moj/components/multi-select/multi-select.js +0 -86
- package/moj/components/multi-select/multi-select.js.map +0 -1
- package/moj/components/password-reveal/password-reveal.js +0 -44
- package/moj/components/password-reveal/password-reveal.js.map +0 -1
- package/moj/components/rich-text-editor/rich-text-editor.js +0 -166
- package/moj/components/rich-text-editor/rich-text-editor.js.map +0 -1
- package/moj/components/search-toggle/search-toggle.js +0 -63
- package/moj/components/search-toggle/search-toggle.js.map +0 -1
- package/moj/components/sortable-table/sortable-table.js +0 -147
- package/moj/components/sortable-table/sortable-table.js.map +0 -1
- package/moj/helpers.js +0 -200
- package/moj/helpers.js.map +0 -1
- package/moj/vendor/html5shiv.js +0 -326
- package/moj/vendor/jquery.js +0 -9300
- package/moj/version.js +0 -12
- package/moj/version.js.map +0 -1
- package/moj/version.mjs +0 -4
- package/moj/version.mjs.map +0 -1
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.MOJFrontend = global.MOJFrontend || {}));
|
|
5
|
+
})(this, (function (exports) { 'use strict';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @param {Element} $element - Element to remove attribute value from
|
|
9
|
+
* @param {string} attr - Attribute name
|
|
10
|
+
* @param {string} value - Attribute value
|
|
11
|
+
*/
|
|
12
|
+
function removeAttributeValue($element, attr, value) {
|
|
13
|
+
let re, m;
|
|
14
|
+
if ($element.getAttribute(attr)) {
|
|
15
|
+
if ($element.getAttribute(attr) === value) {
|
|
16
|
+
$element.removeAttribute(attr);
|
|
17
|
+
} else {
|
|
18
|
+
re = new RegExp(`(^|\\s)${value}(\\s|$)`);
|
|
19
|
+
m = $element.getAttribute(attr).match(re);
|
|
20
|
+
if (m && m.length === 3) {
|
|
21
|
+
$element.setAttribute(attr, $element.getAttribute(attr).replace(re, m[1] && m[2] ? ' ' : ''));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @param {Element} $element - Element to add attribute value to
|
|
29
|
+
* @param {string} attr - Attribute name
|
|
30
|
+
* @param {string} value - Attribute value
|
|
31
|
+
*/
|
|
32
|
+
function addAttributeValue($element, attr, value) {
|
|
33
|
+
let re;
|
|
34
|
+
if (!$element.getAttribute(attr)) {
|
|
35
|
+
$element.setAttribute(attr, value);
|
|
36
|
+
} else {
|
|
37
|
+
re = new RegExp(`(^|\\s)${value}(\\s|$)`);
|
|
38
|
+
if (!re.test($element.getAttribute(attr))) {
|
|
39
|
+
$element.setAttribute(attr, `${$element.getAttribute(attr)} ${value}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Find an elements next sibling
|
|
46
|
+
*
|
|
47
|
+
* Utility function to find an elements next sibling matching the provided
|
|
48
|
+
* selector.
|
|
49
|
+
*
|
|
50
|
+
* @param {Element | null} $element - Element to find siblings for
|
|
51
|
+
* @param {string} [selector] - selector for required sibling
|
|
52
|
+
*/
|
|
53
|
+
function getNextSibling($element, selector) {
|
|
54
|
+
if (!$element || !($element instanceof HTMLElement)) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Get the next sibling element
|
|
59
|
+
let $sibling = $element.nextElementSibling;
|
|
60
|
+
|
|
61
|
+
// If there's no selector, return the first sibling
|
|
62
|
+
if (!selector) return $sibling;
|
|
63
|
+
|
|
64
|
+
// If the sibling matches our selector, use it
|
|
65
|
+
// If not, jump to the next sibling and continue the loop
|
|
66
|
+
while ($sibling) {
|
|
67
|
+
if ($sibling.matches(selector)) return $sibling;
|
|
68
|
+
$sibling = $sibling.nextElementSibling;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Find an elements preceding sibling
|
|
74
|
+
*
|
|
75
|
+
* Utility function to find an elements previous sibling matching the provided
|
|
76
|
+
* selector.
|
|
77
|
+
*
|
|
78
|
+
* @param {Element | null} $element - Element to find siblings for
|
|
79
|
+
* @param {string} [selector] - selector for required sibling
|
|
80
|
+
*/
|
|
81
|
+
function getPreviousSibling($element, selector) {
|
|
82
|
+
if (!$element || !($element instanceof HTMLElement)) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Get the previous sibling element
|
|
87
|
+
let $sibling = $element.previousElementSibling;
|
|
88
|
+
|
|
89
|
+
// If there's no selector, return the first sibling
|
|
90
|
+
if (!selector) return $sibling;
|
|
91
|
+
|
|
92
|
+
// If the sibling matches our selector, use it
|
|
93
|
+
// If not, jump to the next sibling and continue the loop
|
|
94
|
+
while ($sibling) {
|
|
95
|
+
if ($sibling.matches(selector)) return $sibling;
|
|
96
|
+
$sibling = $sibling.previousElementSibling;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* @param {Element | null} $element
|
|
102
|
+
* @param {string} [selector]
|
|
103
|
+
*/
|
|
104
|
+
function findNearestMatchingElement($element, selector) {
|
|
105
|
+
// If no element or selector is provided, return
|
|
106
|
+
if (!$element || !($element instanceof HTMLElement) || !selector) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Start with the current element
|
|
111
|
+
let $currentElement = $element;
|
|
112
|
+
while ($currentElement) {
|
|
113
|
+
// First check the current element
|
|
114
|
+
if ($currentElement.matches(selector)) {
|
|
115
|
+
return $currentElement;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Check all previous siblings
|
|
119
|
+
let $sibling = $currentElement.previousElementSibling;
|
|
120
|
+
while ($sibling) {
|
|
121
|
+
// Check if the sibling itself is a heading
|
|
122
|
+
if ($sibling.matches(selector)) {
|
|
123
|
+
return $sibling;
|
|
124
|
+
}
|
|
125
|
+
$sibling = $sibling.previousElementSibling;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// If no match found in siblings, move up to parent
|
|
129
|
+
$currentElement = $currentElement.parentElement;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
exports.addAttributeValue = addAttributeValue;
|
|
134
|
+
exports.findNearestMatchingElement = findNearestMatchingElement;
|
|
135
|
+
exports.getNextSibling = getNextSibling;
|
|
136
|
+
exports.getPreviousSibling = getPreviousSibling;
|
|
137
|
+
exports.removeAttributeValue = removeAttributeValue;
|
|
138
|
+
|
|
139
|
+
}));
|
|
140
|
+
//# sourceMappingURL=helpers.bundle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.bundle.js","sources":["../../src/moj/helpers.mjs"],"sourcesContent":["/**\n * @param {Element} $element - Element to remove attribute value from\n * @param {string} attr - Attribute name\n * @param {string} value - Attribute value\n */\nexport function removeAttributeValue($element, attr, value) {\n let re, m\n if ($element.getAttribute(attr)) {\n if ($element.getAttribute(attr) === value) {\n $element.removeAttribute(attr)\n } else {\n re = new RegExp(`(^|\\\\s)${value}(\\\\s|$)`)\n m = $element.getAttribute(attr).match(re)\n if (m && m.length === 3) {\n $element.setAttribute(\n attr,\n $element.getAttribute(attr).replace(re, m[1] && m[2] ? ' ' : '')\n )\n }\n }\n }\n}\n\n/**\n * @param {Element} $element - Element to add attribute value to\n * @param {string} attr - Attribute name\n * @param {string} value - Attribute value\n */\nexport function addAttributeValue($element, attr, value) {\n let re\n if (!$element.getAttribute(attr)) {\n $element.setAttribute(attr, value)\n } else {\n re = new RegExp(`(^|\\\\s)${value}(\\\\s|$)`)\n if (!re.test($element.getAttribute(attr))) {\n $element.setAttribute(attr, `${$element.getAttribute(attr)} ${value}`)\n }\n }\n}\n\n/**\n * Find an elements next sibling\n *\n * Utility function to find an elements next sibling matching the provided\n * selector.\n *\n * @param {Element | null} $element - Element to find siblings for\n * @param {string} [selector] - selector for required sibling\n */\nexport function getNextSibling($element, selector) {\n if (!$element || !($element instanceof HTMLElement)) {\n return\n }\n\n // Get the next sibling element\n let $sibling = $element.nextElementSibling\n\n // If there's no selector, return the first sibling\n if (!selector) return $sibling\n\n // If the sibling matches our selector, use it\n // If not, jump to the next sibling and continue the loop\n while ($sibling) {\n if ($sibling.matches(selector)) return $sibling\n $sibling = $sibling.nextElementSibling\n }\n}\n\n/**\n * Find an elements preceding sibling\n *\n * Utility function to find an elements previous sibling matching the provided\n * selector.\n *\n * @param {Element | null} $element - Element to find siblings for\n * @param {string} [selector] - selector for required sibling\n */\nexport function getPreviousSibling($element, selector) {\n if (!$element || !($element instanceof HTMLElement)) {\n return\n }\n\n // Get the previous sibling element\n let $sibling = $element.previousElementSibling\n\n // If there's no selector, return the first sibling\n if (!selector) return $sibling\n\n // If the sibling matches our selector, use it\n // If not, jump to the next sibling and continue the loop\n while ($sibling) {\n if ($sibling.matches(selector)) return $sibling\n $sibling = $sibling.previousElementSibling\n }\n}\n\n/**\n * @param {Element | null} $element\n * @param {string} [selector]\n */\nexport function findNearestMatchingElement($element, selector) {\n // If no element or selector is provided, return\n if (!$element || !($element instanceof HTMLElement) || !selector) {\n return\n }\n\n // Start with the current element\n let $currentElement = $element\n\n while ($currentElement) {\n // First check the current element\n if ($currentElement.matches(selector)) {\n return $currentElement\n }\n\n // Check all previous siblings\n let $sibling = $currentElement.previousElementSibling\n while ($sibling) {\n // Check if the sibling itself is a heading\n if ($sibling.matches(selector)) {\n return $sibling\n }\n $sibling = $sibling.previousElementSibling\n }\n\n // If no match found in siblings, move up to parent\n $currentElement = $currentElement.parentElement\n }\n}\n"],"names":["removeAttributeValue","$element","attr","value","re","m","getAttribute","removeAttribute","RegExp","match","length","setAttribute","replace","addAttributeValue","test","getNextSibling","selector","HTMLElement","$sibling","nextElementSibling","matches","getPreviousSibling","previousElementSibling","findNearestMatchingElement","$currentElement","parentElement"],"mappings":";;;;;;EAAA;EACA;EACA;EACA;EACA;EACO,SAASA,oBAAoBA,CAACC,QAAQ,EAAEC,IAAI,EAAEC,KAAK,EAAE;IAC1D,IAAIC,EAAE,EAAEC,CAAC;EACT,EAAA,IAAIJ,QAAQ,CAACK,YAAY,CAACJ,IAAI,CAAC,EAAE;MAC/B,IAAID,QAAQ,CAACK,YAAY,CAACJ,IAAI,CAAC,KAAKC,KAAK,EAAE;EACzCF,MAAAA,QAAQ,CAACM,eAAe,CAACL,IAAI,CAAC;EAChC,KAAC,MAAM;EACLE,MAAAA,EAAE,GAAG,IAAII,MAAM,CAAC,CAAUL,OAAAA,EAAAA,KAAK,SAAS,CAAC;QACzCE,CAAC,GAAGJ,QAAQ,CAACK,YAAY,CAACJ,IAAI,CAAC,CAACO,KAAK,CAACL,EAAE,CAAC;EACzC,MAAA,IAAIC,CAAC,IAAIA,CAAC,CAACK,MAAM,KAAK,CAAC,EAAE;EACvBT,QAAAA,QAAQ,CAACU,YAAY,CACnBT,IAAI,EACJD,QAAQ,CAACK,YAAY,CAACJ,IAAI,CAAC,CAACU,O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$element - Element to remove attribute value from
|
|
3
|
+
* @param {string} attr - Attribute name
|
|
4
|
+
* @param {string} value - Attribute value
|
|
5
|
+
*/
|
|
6
|
+
function removeAttributeValue($element, attr, value) {
|
|
7
|
+
let re, m;
|
|
8
|
+
if ($element.getAttribute(attr)) {
|
|
9
|
+
if ($element.getAttribute(attr) === value) {
|
|
10
|
+
$element.removeAttribute(attr);
|
|
11
|
+
} else {
|
|
12
|
+
re = new RegExp(`(^|\\s)${value}(\\s|$)`);
|
|
13
|
+
m = $element.getAttribute(attr).match(re);
|
|
14
|
+
if (m && m.length === 3) {
|
|
15
|
+
$element.setAttribute(attr, $element.getAttribute(attr).replace(re, m[1] && m[2] ? ' ' : ''));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {Element} $element - Element to add attribute value to
|
|
23
|
+
* @param {string} attr - Attribute name
|
|
24
|
+
* @param {string} value - Attribute value
|
|
25
|
+
*/
|
|
26
|
+
function addAttributeValue($element, attr, value) {
|
|
27
|
+
let re;
|
|
28
|
+
if (!$element.getAttribute(attr)) {
|
|
29
|
+
$element.setAttribute(attr, value);
|
|
30
|
+
} else {
|
|
31
|
+
re = new RegExp(`(^|\\s)${value}(\\s|$)`);
|
|
32
|
+
if (!re.test($element.getAttribute(attr))) {
|
|
33
|
+
$element.setAttribute(attr, `${$element.getAttribute(attr)} ${value}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Find an elements next sibling
|
|
40
|
+
*
|
|
41
|
+
* Utility function to find an elements next sibling matching the provided
|
|
42
|
+
* selector.
|
|
43
|
+
*
|
|
44
|
+
* @param {Element | null} $element - Element to find siblings for
|
|
45
|
+
* @param {string} [selector] - selector for required sibling
|
|
46
|
+
*/
|
|
47
|
+
function getNextSibling($element, selector) {
|
|
48
|
+
if (!$element || !($element instanceof HTMLElement)) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Get the next sibling element
|
|
53
|
+
let $sibling = $element.nextElementSibling;
|
|
54
|
+
|
|
55
|
+
// If there's no selector, return the first sibling
|
|
56
|
+
if (!selector) return $sibling;
|
|
57
|
+
|
|
58
|
+
// If the sibling matches our selector, use it
|
|
59
|
+
// If not, jump to the next sibling and continue the loop
|
|
60
|
+
while ($sibling) {
|
|
61
|
+
if ($sibling.matches(selector)) return $sibling;
|
|
62
|
+
$sibling = $sibling.nextElementSibling;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Find an elements preceding sibling
|
|
68
|
+
*
|
|
69
|
+
* Utility function to find an elements previous sibling matching the provided
|
|
70
|
+
* selector.
|
|
71
|
+
*
|
|
72
|
+
* @param {Element | null} $element - Element to find siblings for
|
|
73
|
+
* @param {string} [selector] - selector for required sibling
|
|
74
|
+
*/
|
|
75
|
+
function getPreviousSibling($element, selector) {
|
|
76
|
+
if (!$element || !($element instanceof HTMLElement)) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Get the previous sibling element
|
|
81
|
+
let $sibling = $element.previousElementSibling;
|
|
82
|
+
|
|
83
|
+
// If there's no selector, return the first sibling
|
|
84
|
+
if (!selector) return $sibling;
|
|
85
|
+
|
|
86
|
+
// If the sibling matches our selector, use it
|
|
87
|
+
// If not, jump to the next sibling and continue the loop
|
|
88
|
+
while ($sibling) {
|
|
89
|
+
if ($sibling.matches(selector)) return $sibling;
|
|
90
|
+
$sibling = $sibling.previousElementSibling;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @param {Element | null} $element
|
|
96
|
+
* @param {string} [selector]
|
|
97
|
+
*/
|
|
98
|
+
function findNearestMatchingElement($element, selector) {
|
|
99
|
+
// If no element or selector is provided, return
|
|
100
|
+
if (!$element || !($element instanceof HTMLElement) || !selector) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Start with the current element
|
|
105
|
+
let $currentElement = $element;
|
|
106
|
+
while ($currentElement) {
|
|
107
|
+
// First check the current element
|
|
108
|
+
if ($currentElement.matches(selector)) {
|
|
109
|
+
return $currentElement;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Check all previous siblings
|
|
113
|
+
let $sibling = $currentElement.previousElementSibling;
|
|
114
|
+
while ($sibling) {
|
|
115
|
+
// Check if the sibling itself is a heading
|
|
116
|
+
if ($sibling.matches(selector)) {
|
|
117
|
+
return $sibling;
|
|
118
|
+
}
|
|
119
|
+
$sibling = $sibling.previousElementSibling;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// If no match found in siblings, move up to parent
|
|
123
|
+
$currentElement = $currentElement.parentElement;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export { addAttributeValue, findNearestMatchingElement, getNextSibling, getPreviousSibling, removeAttributeValue };
|
|
128
|
+
//# sourceMappingURL=helpers.bundle.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.bundle.mjs","sources":["../../src/moj/helpers.mjs"],"sourcesContent":["/**\n * @param {Element} $element - Element to remove attribute value from\n * @param {string} attr - Attribute name\n * @param {string} value - Attribute value\n */\nexport function removeAttributeValue($element, attr, value) {\n let re, m\n if ($element.getAttribute(attr)) {\n if ($element.getAttribute(attr) === value) {\n $element.removeAttribute(attr)\n } else {\n re = new RegExp(`(^|\\\\s)${value}(\\\\s|$)`)\n m = $element.getAttribute(attr).match(re)\n if (m && m.length === 3) {\n $element.setAttribute(\n attr,\n $element.getAttribute(attr).replace(re, m[1] && m[2] ? ' ' : '')\n )\n }\n }\n }\n}\n\n/**\n * @param {Element} $element - Element to add attribute value to\n * @param {string} attr - Attribute name\n * @param {string} value - Attribute value\n */\nexport function addAttributeValue($element, attr, value) {\n let re\n if (!$element.getAttribute(attr)) {\n $element.setAttribute(attr, value)\n } else {\n re = new RegExp(`(^|\\\\s)${value}(\\\\s|$)`)\n if (!re.test($element.getAttribute(attr))) {\n $element.setAttribute(attr, `${$element.getAttribute(attr)} ${value}`)\n }\n }\n}\n\n/**\n * Find an elements next sibling\n *\n * Utility function to find an elements next sibling matching the provided\n * selector.\n *\n * @param {Element | null} $element - Element to find siblings for\n * @param {string} [selector] - selector for required sibling\n */\nexport function getNextSibling($element, selector) {\n if (!$element || !($element instanceof HTMLElement)) {\n return\n }\n\n // Get the next sibling element\n let $sibling = $element.nextElementSibling\n\n // If there's no selector, return the first sibling\n if (!selector) return $sibling\n\n // If the sibling matches our selector, use it\n // If not, jump to the next sibling and continue the loop\n while ($sibling) {\n if ($sibling.matches(selector)) return $sibling\n $sibling = $sibling.nextElementSibling\n }\n}\n\n/**\n * Find an elements preceding sibling\n *\n * Utility function to find an elements previous sibling matching the provided\n * selector.\n *\n * @param {Element | null} $element - Element to find siblings for\n * @param {string} [selector] - selector for required sibling\n */\nexport function getPreviousSibling($element, selector) {\n if (!$element || !($element instanceof HTMLElement)) {\n return\n }\n\n // Get the previous sibling element\n let $sibling = $element.previousElementSibling\n\n // If there's no selector, return the first sibling\n if (!selector) return $sibling\n\n // If the sibling matches our selector, use it\n // If not, jump to the next sibling and continue the loop\n while ($sibling) {\n if ($sibling.matches(selector)) return $sibling\n $sibling = $sibling.previousElementSibling\n }\n}\n\n/**\n * @param {Element | null} $element\n * @param {string} [selector]\n */\nexport function findNearestMatchingElement($element, selector) {\n // If no element or selector is provided, return\n if (!$element || !($element instanceof HTMLElement) || !selector) {\n return\n }\n\n // Start with the current element\n let $currentElement = $element\n\n while ($currentElement) {\n // First check the current element\n if ($currentElement.matches(selector)) {\n return $currentElement\n }\n\n // Check all previous siblings\n let $sibling = $currentElement.previousElementSibling\n while ($sibling) {\n // Check if the sibling itself is a heading\n if ($sibling.matches(selector)) {\n return $sibling\n }\n $sibling = $sibling.previousElementSibling\n }\n\n // If no match found in siblings, move up to parent\n $currentElement = $currentElement.parentElement\n }\n}\n"],"names":["removeAttributeValue","$element","attr","value","re","m","getAttribute","removeAttribute","RegExp","match","length","setAttribute","replace","addAttributeValue","test","getNextSibling","selector","HTMLElement","$sibling","nextElementSibling","matches","getPreviousSibling","previousElementSibling","findNearestMatchingElement","$currentElement","parentElement"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACO,SAASA,oBAAoBA,CAACC,QAAQ,EAAEC,IAAI,EAAEC,KAAK,EAAE;EAC1D,IAAIC,EAAE,EAAEC,CAAC;AACT,EAAA,IAAIJ,QAAQ,CAACK,YAAY,CAACJ,IAAI,CAAC,EAAE;IAC/B,IAAID,QAAQ,CAACK,YAAY,CAACJ,IAAI,CAAC,KAAKC,KAAK,EAAE;AACzCF,MAAAA,QAAQ,CAACM,eAAe,CAACL,IAAI,CAAC;AAChC,KAAC,MAAM;AACLE,MAAAA,EAAE,GAAG,IAAII,MAAM,CAAC,CAAUL,OAAAA,EAAAA,KAAK,SAAS,CAAC;MACzCE,CAAC,GAAGJ,QAAQ,CAACK,YAAY,CAACJ,IAAI,CAAC,CAACO,KAAK,CAACL,EAAE,CAAC;AACzC,MAAA,IAAIC,CAAC,IAAIA,CAAC,CAACK,MAAM,KAAK,CAAC,EAAE;AACvBT,QAAAA,QAAQ,CAACU,YAAY,CACnBT,IAAI,EACJD,QAAQ,CAACK,YAAY,CAACJ,IAAI,CAAC,CAACU,OAAO,CAACR,EAAE,EAAEC,CAAC,CAAC,CAAC,CAAC,IAAIA,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,EAAE,CACjE,CAAC;AACH;AACF;AACF;AACF;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASQ,iBAAiBA,CAACZ,QAAQ,EAAEC,IAAI,EAAEC,KAAK,EAAE;AACvD,EAAA,IAAIC,EAAE;AACN,EAAA,IAAI,CAACH,QAAQ,CAACK,YAAY,CAACJ,IAAI,CAAC,EAAE;A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ACA,EAAA,OAAOA,QAAQ,EAAE;IACf,IAAIA,QAAQ,CAACE,OAAO,CAACJ,QAAQ,CAAC,EAAE,OAAOE,QAAQ;IAC/CA,QAAQ,GAAGA,QAAQ,CAACI,sBAAsB;AAC5C;AACF;;AAEA;AACA;AACA;AACA;AACO,SAASC,0BAA0BA,CAACtB,QAAQ,EAAEe,QAAQ,EAAE;AAC7D;EACA,IAAI,CAACf,QAAQ,IAAI,EAAEA,QAAQ,YAAYgB,WAAW,CAAC,IAAI,CAACD,QAAQ,EAAE;AAChE,IAAA;AACF;;AAEA;EACA,IAAIQ,eAAe,GAAGvB,QAAQ;AAE9B,EAAA,OAAOuB,eAAe,EAAE;AACtB;AACA,IAAA,IAAIA,eAAe,CAACJ,OAAO,CAACJ,QAAQ,CAAC,EAAE;AACrC,MAAA,OAAOQ,eAAe;AACxB;;AAEA;AACA,IAAA,IAAIN,QAAQ,GAAGM,eAAe,CAACF,sBAAsB;AACrD,IAAA,OAAOJ,QAAQ,EAAE;AACf;AACA,MAAA,IAAIA,QAAQ,CAACE,OAAO,CAACJ,QAAQ,CAAC,EAAE;AAC9B,QAAA,OAAOE,QAAQ;AACjB;MACAA,QAAQ,GAAGA,QAAQ,CAACI,sBAAsB;AAC5C;;AAEA;IACAE,eAAe,GAAGA,eAAe,CAACC,aAAa;AACjD;AACF;;;;"}
|
package/moj/helpers.mjs
CHANGED
|
@@ -1,24 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @param {Element} $element - Element to remove attribute value from
|
|
3
|
+
* @param {string} attr - Attribute name
|
|
4
|
+
* @param {string} value - Attribute value
|
|
5
|
+
*/
|
|
6
|
+
function removeAttributeValue($element, attr, value) {
|
|
7
|
+
let re, m;
|
|
8
|
+
if ($element.getAttribute(attr)) {
|
|
9
|
+
if ($element.getAttribute(attr) === value) {
|
|
10
|
+
$element.removeAttribute(attr);
|
|
11
|
+
} else {
|
|
12
|
+
re = new RegExp(`(^|\\s)${value}(\\s|$)`);
|
|
13
|
+
m = $element.getAttribute(attr).match(re);
|
|
14
|
+
if (m && m.length === 3) {
|
|
15
|
+
$element.setAttribute(attr, $element.getAttribute(attr).replace(re, m[1] && m[2] ? ' ' : ''));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
14
19
|
}
|
|
15
20
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
/**
|
|
22
|
+
* @param {Element} $element - Element to add attribute value to
|
|
23
|
+
* @param {string} attr - Attribute name
|
|
24
|
+
* @param {string} value - Attribute value
|
|
25
|
+
*/
|
|
26
|
+
function addAttributeValue($element, attr, value) {
|
|
27
|
+
let re;
|
|
28
|
+
if (!$element.getAttribute(attr)) {
|
|
29
|
+
$element.setAttribute(attr, value);
|
|
30
|
+
} else {
|
|
31
|
+
re = new RegExp(`(^|\\s)${value}(\\s|$)`);
|
|
32
|
+
if (!re.test($element.getAttribute(attr))) {
|
|
33
|
+
$element.setAttribute(attr, `${$element.getAttribute(attr)} ${value}`);
|
|
34
|
+
}
|
|
22
35
|
}
|
|
23
36
|
}
|
|
24
37
|
|
|
@@ -28,33 +41,41 @@ function nodeListForEach(nodes, callback) {
|
|
|
28
41
|
* Utility function to find an elements previous sibling matching the provided
|
|
29
42
|
* selector.
|
|
30
43
|
*
|
|
31
|
-
* @param {
|
|
32
|
-
* @param {string} selector - selector for required sibling
|
|
44
|
+
* @param {Element | null} $element - Element to find siblings for
|
|
45
|
+
* @param {string} [selector] - selector for required sibling
|
|
33
46
|
*/
|
|
34
47
|
function getPreviousSibling($element, selector) {
|
|
35
|
-
if (!$element)
|
|
48
|
+
if (!$element || !($element instanceof HTMLElement)) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
36
52
|
// Get the previous sibling element
|
|
37
53
|
let $sibling = $element.previousElementSibling;
|
|
38
54
|
|
|
39
55
|
// If the sibling matches our selector, use it
|
|
40
56
|
// If not, jump to the next sibling and continue the loop
|
|
41
57
|
while ($sibling) {
|
|
42
|
-
if ($sibling.matches(selector)) return $sibling
|
|
58
|
+
if ($sibling.matches(selector)) return $sibling;
|
|
43
59
|
$sibling = $sibling.previousElementSibling;
|
|
44
60
|
}
|
|
45
61
|
}
|
|
46
62
|
|
|
63
|
+
/**
|
|
64
|
+
* @param {Element | null} $element
|
|
65
|
+
* @param {string} [selector]
|
|
66
|
+
*/
|
|
47
67
|
function findNearestMatchingElement($element, selector) {
|
|
48
|
-
// If no element or selector is provided, return
|
|
49
|
-
if (!$element)
|
|
68
|
+
// If no element or selector is provided, return
|
|
69
|
+
if (!$element || !($element instanceof HTMLElement) || false) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
50
72
|
|
|
51
73
|
// Start with the current element
|
|
52
74
|
let $currentElement = $element;
|
|
53
|
-
|
|
54
75
|
while ($currentElement) {
|
|
55
76
|
// First check the current element
|
|
56
77
|
if ($currentElement.matches(selector)) {
|
|
57
|
-
return $currentElement
|
|
78
|
+
return $currentElement;
|
|
58
79
|
}
|
|
59
80
|
|
|
60
81
|
// Check all previous siblings
|
|
@@ -62,7 +83,7 @@ function findNearestMatchingElement($element, selector) {
|
|
|
62
83
|
while ($sibling) {
|
|
63
84
|
// Check if the sibling itself is a heading
|
|
64
85
|
if ($sibling.matches(selector)) {
|
|
65
|
-
return $sibling
|
|
86
|
+
return $sibling;
|
|
66
87
|
}
|
|
67
88
|
$sibling = $sibling.previousElementSibling;
|
|
68
89
|
}
|
|
@@ -72,53 +93,5 @@ function findNearestMatchingElement($element, selector) {
|
|
|
72
93
|
}
|
|
73
94
|
}
|
|
74
95
|
|
|
75
|
-
|
|
76
|
-
* Move focus to element
|
|
77
|
-
*
|
|
78
|
-
* Sets tabindex to -1 to make the element programmatically focusable,
|
|
79
|
-
* but removes it on blur as the element doesn't need to be focused again.
|
|
80
|
-
*
|
|
81
|
-
* @param {HTMLElement} $element - HTML element
|
|
82
|
-
* @param {object} [options] - Handler options
|
|
83
|
-
* @param {function(this: HTMLElement): void} [options.onBeforeFocus] - Callback before focus
|
|
84
|
-
* @param {function(this: HTMLElement): void} [options.onBlur] - Callback on blur
|
|
85
|
-
*/
|
|
86
|
-
function setFocus($element, options = {}) {
|
|
87
|
-
const isFocusable = $element.getAttribute('tabindex');
|
|
88
|
-
|
|
89
|
-
if (!isFocusable) {
|
|
90
|
-
$element.setAttribute('tabindex', '-1');
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Handle element focus
|
|
95
|
-
*/
|
|
96
|
-
function onFocus() {
|
|
97
|
-
$element.addEventListener('blur', onBlur, { once: true });
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Handle element blur
|
|
102
|
-
*/
|
|
103
|
-
function onBlur() {
|
|
104
|
-
if (options.onBlur) {
|
|
105
|
-
options.onBlur.call($element);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (!isFocusable) {
|
|
109
|
-
$element.removeAttribute('tabindex');
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// Add listener to reset element on blur, after focus
|
|
114
|
-
$element.addEventListener('focus', onFocus, { once: true });
|
|
115
|
-
|
|
116
|
-
// Focus element
|
|
117
|
-
if (options.onBeforeFocus) {
|
|
118
|
-
options.onBeforeFocus.call($element);
|
|
119
|
-
}
|
|
120
|
-
$element.focus();
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export { dragAndDropSupported, fileApiSupported, findNearestMatchingElement, formDataSupported, getPreviousSibling, nodeListForEach, setFocus };
|
|
96
|
+
export { addAttributeValue, findNearestMatchingElement, getPreviousSibling, removeAttributeValue };
|
|
124
97
|
//# sourceMappingURL=helpers.mjs.map
|
package/moj/helpers.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.mjs","sources":["../../src/moj/helpers.mjs"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"helpers.mjs","sources":["../../src/moj/helpers.mjs"],"sourcesContent":["/**\n * @param {Element} $element - Element to remove attribute value from\n * @param {string} attr - Attribute name\n * @param {string} value - Attribute value\n */\nexport function removeAttributeValue($element, attr, value) {\n let re, m\n if ($element.getAttribute(attr)) {\n if ($element.getAttribute(attr) === value) {\n $element.removeAttribute(attr)\n } else {\n re = new RegExp(`(^|\\\\s)${value}(\\\\s|$)`)\n m = $element.getAttribute(attr).match(re)\n if (m && m.length === 3) {\n $element.setAttribute(\n attr,\n $element.getAttribute(attr).replace(re, m[1] && m[2] ? ' ' : '')\n )\n }\n }\n }\n}\n\n/**\n * @param {Element} $element - Element to add attribute value to\n * @param {string} attr - Attribute name\n * @param {string} value - Attribute value\n */\nexport function addAttributeValue($element, attr, value) {\n let re\n if (!$element.getAttribute(attr)) {\n $element.setAttribute(attr, value)\n } else {\n re = new RegExp(`(^|\\\\s)${value}(\\\\s|$)`)\n if (!re.test($element.getAttribute(attr))) {\n $element.setAttribute(attr, `${$element.getAttribute(attr)} ${value}`)\n }\n }\n}\n\n/**\n * Find an elements next sibling\n *\n * Utility function to find an elements next sibling matching the provided\n * selector.\n *\n * @param {Element | null} $element - Element to find siblings for\n * @param {string} [selector] - selector for required sibling\n */\nexport function getNextSibling($element, selector) {\n if (!$element || !($element instanceof HTMLElement)) {\n return\n }\n\n // Get the next sibling element\n let $sibling = $element.nextElementSibling\n\n // If there's no selector, return the first sibling\n if (!selector) return $sibling\n\n // If the sibling matches our selector, use it\n // If not, jump to the next sibling and continue the loop\n while ($sibling) {\n if ($sibling.matches(selector)) return $sibling\n $sibling = $sibling.nextElementSibling\n }\n}\n\n/**\n * Find an elements preceding sibling\n *\n * Utility function to find an elements previous sibling matching the provided\n * selector.\n *\n * @param {Element | null} $element - Element to find siblings for\n * @param {string} [selector] - selector for required sibling\n */\nexport function getPreviousSibling($element, selector) {\n if (!$element || !($element instanceof HTMLElement)) {\n return\n }\n\n // Get the previous sibling element\n let $sibling = $element.previousElementSibling\n\n // If there's no selector, return the first sibling\n if (!selector) return $sibling\n\n // If the sibling matches our selector, use it\n // If not, jump to the next sibling and continue the loop\n while ($sibling) {\n if ($sibling.matches(selector)) return $sibling\n $sibling = $sibling.previousElementSibling\n }\n}\n\n/**\n * @param {Element | null} $element\n * @param {string} [selector]\n */\nexport function findNearestMatchingElement($element, selector) {\n // If no element or selector is provided, return\n if (!$element || !($element instanceof HTMLElement) || !selector) {\n return\n }\n\n // Start with the current element\n let $currentElement = $element\n\n while ($currentElement) {\n // First check the current element\n if ($currentElement.matches(selector)) {\n return $currentElement\n }\n\n // Check all previous siblings\n let $sibling = $currentElement.previousElementSibling\n while ($sibling) {\n // Check if the sibling itself is a heading\n if ($sibling.matches(selector)) {\n return $sibling\n }\n $sibling = $sibling.previousElementSibling\n }\n\n // If no match found in siblings, move up to parent\n $currentElement = $currentElement.parentElement\n }\n}\n"],"names":["removeAttributeValue","$element","attr","value","re","m","getAttribute","removeAttribute","RegExp","match","length","setAttribute","replace","addAttributeValue","test","getPreviousSibling","selector","HTMLElement","$sibling","previousElementSibling","matches","findNearestMatchingElement","$currentElement","parentElement"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACO,SAASA,oBAAoBA,CAACC,QAAQ,EAAEC,IAAI,EAAEC,KAAK,EAAE;EAC1D,IAAIC,EAAE,EAAEC,CAAC;AACT,EAAA,IAAIJ,QAAQ,CAACK,YAAY,CAACJ,IAAI,CAAC,EAAE;IAC/B,IAAID,QAAQ,CAACK,YAAY,CAACJ,IAAI,CAAC,KAAKC,KAAK,EAAE;AACzCF,MAAAA,QAAQ,CAACM,eAAe,CAACL,IAAI,CAAC;AAChC,KAAC,MAAM;AACLE,MAAAA,EAAE,GAAG,IAAII,MAAM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AAA;AACF;;AAEA;AACA,EAAA,IAAIC,QAAQ,GAAGjB,QAAQ,CAACkB,sBAAsB;;AAK9C;AACA;AACA,EAAA,OAAOD,QAAQ,EAAE;IACf,IAAIA,QAAQ,CAACE,OAAO,CAACJ,QAAQ,CAAC,EAAE,OAAOE,QAAQ;IAC/CA,QAAQ,GAAGA,QAAQ,CAACC,sBAAsB;AAC5C;AACF;;AAEA;AACA;AACA;AACA;AACO,SAASE,0BAA0BA,CAACpB,QAAQ,EAAEe,QAAQ,EAAE;AAC7D;EACA,IAAI,CAACf,QAAQ,IAAI,EAAEA,QAAQ,YAAYgB,WAAW,CAAC,IAAI,KAAS,EAAE;AAChE,IAAA;AACF;;AAEA;EACA,IAAIK,eAAe,GAAGrB,QAAQ;AAE9B,EAAA,OAAOqB,eAAe,EAAE;AACtB;AACA,IAAA,IAAIA,eAAe,CAACF,OAAO,CAACJ,QAAQ,CAAC,EAAE;AACrC,MAAA,OAAOM,eAAe;AACxB;;AAEA;AACA,IAAA,IAAIJ,QAAQ,GAAGI,eAAe,CAACH,sBAAsB;AACrD,IAAA,OAAOD,QAAQ,EAAE;AACf;AACA,MAAA,IAAIA,QAAQ,CAACE,OAAO,CAACJ,QAAQ,CAAC,EAAE;AAC9B,QAAA,OAAOE,QAAQ;AACjB;MACAA,QAAQ,GAAGA,QAAQ,CAACC,sBAAsB;AAC5C;;AAEA;IACAG,eAAe,GAAGA,eAAe,CAACC,aAAa;AACjD;AACF;;;;"}
|
package/moj/init.js
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import * as MOJFrontend from '../moj/moj-frontend.min.js'
|
|
2
|
+
|
|
3
|
+
// Maintain window global for compatibility
|
|
4
|
+
window.MOJFrontend = MOJFrontend
|
|
5
|
+
|
|
6
|
+
if (
|
|
7
|
+
window.GOVUKPrototypeKit &&
|
|
8
|
+
window.GOVUKPrototypeKit.documentReady &&
|
|
9
|
+
window.GOVUKPrototypeKit.majorVersion >= 13
|
|
10
|
+
) {
|
|
11
|
+
window.GOVUKPrototypeKit.documentReady(() => {
|
|
3
12
|
window.MOJFrontend.initAll()
|
|
4
13
|
})
|
|
5
14
|
}
|