@ministryofjustice/frontend 3.4.0 → 3.5.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/moj/all.jquery.min.js +7 -70
- package/moj/all.js +2856 -2865
- package/moj/components/add-another/add-another.js +135 -104
- package/moj/components/alert/alert.js +482 -247
- package/moj/components/alert/alert.spec.helper.js +30 -5
- package/moj/components/button-menu/button-menu.js +346 -319
- package/moj/components/date-picker/date-picker.js +925 -900
- package/moj/components/filter-toggle-button/filter-toggle-button.js +122 -91
- package/moj/components/form-validator/form-validator.js +399 -164
- package/moj/components/multi-file-upload/multi-file-upload.js +445 -210
- package/moj/components/multi-select/multi-select.js +106 -75
- package/moj/components/password-reveal/password-reveal.js +64 -33
- package/moj/components/rich-text-editor/rich-text-editor.js +186 -153
- package/moj/components/search-toggle/search-toggle.js +77 -46
- package/moj/components/sortable-table/sortable-table.js +167 -146
- package/moj/helpers/_links.scss +1 -1
- package/moj/helpers.js +218 -180
- package/moj/moj-frontend.min.js +7 -70
- package/moj/version.js +28 -1
- package/package.json +1 -1
- package/moj/all.spec.js +0 -24
- package/moj/components/add-another/add-another.spec.js +0 -165
- package/moj/components/alert/alert.spec.js +0 -229
- package/moj/components/button-menu/button-menu.spec.js +0 -360
- package/moj/components/date-picker/date-picker.spec.js +0 -1178
- package/moj/components/filter-toggle-button/filter-toggle-button.spec.js +0 -302
- package/moj/components/multi-file-upload/multi-file-upload.spec.js +0 -510
- package/moj/components/multi-select/multi-select.spec.js +0 -128
- package/moj/components/password-reveal/password-reveal.spec.js +0 -57
- package/moj/components/search-toggle/search-toggle.spec.js +0 -129
- package/moj/components/sortable-table/sortable-table.spec.js +0 -362
- package/moj/helpers.spec.js +0 -235
- package/moj/namespace.js +0 -2
|
@@ -1,52 +1,83 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.MOJFrontend = factory());
|
|
5
|
+
})(this, (function () { 'use strict';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
function getDefaultExportFromCjs (x) {
|
|
8
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
9
|
+
}
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
var _global_window_jQuery = window.jQuery;
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
var searchToggle$1;
|
|
14
|
+
var hasRequiredSearchToggle;
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
function requireSearchToggle () {
|
|
17
|
+
if (hasRequiredSearchToggle) return searchToggle$1;
|
|
18
|
+
hasRequiredSearchToggle = 1;
|
|
19
|
+
const $ = _global_window_jQuery;
|
|
20
|
+
|
|
21
|
+
function SearchToggle(options) {
|
|
22
|
+
this.options = options;
|
|
23
|
+
this.container = $(this.options.search.container);
|
|
24
|
+
this.toggleButtonContainer = $(this.options.toggleButton.container);
|
|
25
|
+
|
|
26
|
+
if (this.container.data('moj-search-toggle-initialised')) {
|
|
27
|
+
return
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
this.container.data('moj-search-toggle-initialised', true);
|
|
31
|
+
|
|
32
|
+
const svg =
|
|
33
|
+
'<svg viewBox="0 0 20 20" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" class="moj-search-toggle__button__icon"><path d="M7.433,12.5790048 C6.06762625,12.5808611 4.75763941,12.0392925 3.79217348,11.0738265 C2.82670755,10.1083606 2.28513891,8.79837375 2.28699522,7.433 C2.28513891,6.06762625 2.82670755,4.75763941 3.79217348,3.79217348 C4.75763941,2.82670755 6.06762625,2.28513891 7.433,2.28699522 C8.79837375,2.28513891 10.1083606,2.82670755 11.0738265,3.79217348 C12.0392925,4.75763941 12.5808611,6.06762625 12.5790048,7.433 C12.5808611,8.79837375 12.0392925,10.1083606 11.0738265,11.0738265 C10.1083606,12.0392925 8.79837375,12.5808611 7.433,12.5790048 L7.433,12.5790048 Z M14.293,12.579 L13.391,12.579 L13.071,12.269 C14.2300759,10.9245158 14.8671539,9.20813198 14.866,7.433 C14.866,3.32786745 11.5381325,-1.65045755e-15 7.433,-1.65045755e-15 C3.32786745,-1.65045755e-15 -1.65045755e-15,3.32786745 -1.65045755e-15,7.433 C-1.65045755e-15,11.5381325 3.32786745,14.866 7.433,14.866 C9.208604,14.8671159 10.9253982,14.2296624 12.27,13.07 L12.579,13.39 L12.579,14.294 L18.296,20 L20,18.296 L14.294,12.579 L14.293,12.579 Z"></path></svg>';
|
|
34
|
+
|
|
35
|
+
this.toggleButton = $(
|
|
36
|
+
`<button class="moj-search-toggle__button" type="button" aria-haspopup="true" aria-expanded="false">
|
|
17
37
|
${this.options.toggleButton.text} ${svg}
|
|
18
38
|
</button>`
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
39
|
+
);
|
|
40
|
+
this.toggleButton.on('click', $.proxy(this, 'onToggleButtonClick'));
|
|
41
|
+
this.toggleButtonContainer.append(this.toggleButton);
|
|
42
|
+
$(document).on('click', this.onDocumentClick.bind(this));
|
|
43
|
+
$(document).on('focusin', this.onDocumentClick.bind(this));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
SearchToggle.prototype.showMenu = function () {
|
|
47
|
+
this.toggleButton.attr('aria-expanded', 'true');
|
|
48
|
+
this.container.removeClass('moj-js-hidden');
|
|
49
|
+
this.container.find('input').first().get(0).focus();
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
SearchToggle.prototype.hideMenu = function () {
|
|
53
|
+
this.container.addClass('moj-js-hidden');
|
|
54
|
+
this.toggleButton.attr('aria-expanded', 'false');
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
SearchToggle.prototype.onToggleButtonClick = function () {
|
|
58
|
+
if (this.toggleButton.attr('aria-expanded') === 'false') {
|
|
59
|
+
this.showMenu();
|
|
60
|
+
} else {
|
|
61
|
+
this.hideMenu();
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
SearchToggle.prototype.onDocumentClick = function (e) {
|
|
66
|
+
if (
|
|
67
|
+
!$.contains(this.toggleButtonContainer[0], e.target) &&
|
|
68
|
+
!$.contains(this.container[0], e.target)
|
|
69
|
+
) {
|
|
70
|
+
this.hideMenu();
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
searchToggle$1 = { SearchToggle };
|
|
75
|
+
return searchToggle$1;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
var searchToggleExports = requireSearchToggle();
|
|
79
|
+
var searchToggle = /*@__PURE__*/getDefaultExportFromCjs(searchToggleExports);
|
|
80
|
+
|
|
81
|
+
return searchToggle;
|
|
82
|
+
|
|
83
|
+
}));
|
|
@@ -1,146 +1,167 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
)
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.MOJFrontend = factory());
|
|
5
|
+
})(this, (function () { 'use strict';
|
|
6
|
+
|
|
7
|
+
function getDefaultExportFromCjs (x) {
|
|
8
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
var _global_window_jQuery = window.jQuery;
|
|
12
|
+
|
|
13
|
+
var sortableTable$1;
|
|
14
|
+
var hasRequiredSortableTable;
|
|
15
|
+
|
|
16
|
+
function requireSortableTable () {
|
|
17
|
+
if (hasRequiredSortableTable) return sortableTable$1;
|
|
18
|
+
hasRequiredSortableTable = 1;
|
|
19
|
+
const $ = _global_window_jQuery;
|
|
20
|
+
|
|
21
|
+
function SortableTable(params) {
|
|
22
|
+
this.table = $(params.table);
|
|
23
|
+
|
|
24
|
+
if (this.table.data('moj-search-toggle-initialised')) {
|
|
25
|
+
return
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
this.table.data('moj-search-toggle-initialised', true);
|
|
29
|
+
|
|
30
|
+
this.setupOptions(params);
|
|
31
|
+
this.body = this.table.find('tbody');
|
|
32
|
+
this.createHeadingButtons();
|
|
33
|
+
this.createStatusBox();
|
|
34
|
+
this.initialiseSortedColumn();
|
|
35
|
+
this.table.on('click', 'th button', $.proxy(this, 'onSortButtonClick'));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
SortableTable.prototype.setupOptions = function (params) {
|
|
39
|
+
params = params || {};
|
|
40
|
+
this.statusMessage = params.statusMessage || 'Sort by %heading% (%direction%)';
|
|
41
|
+
this.ascendingText = params.ascendingText || 'ascending';
|
|
42
|
+
this.descendingText = params.descendingText || 'descending';
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
SortableTable.prototype.createHeadingButtons = function () {
|
|
46
|
+
const headings = this.table.find('thead th');
|
|
47
|
+
let heading;
|
|
48
|
+
for (let i = 0; i < headings.length; i++) {
|
|
49
|
+
heading = $(headings[i]);
|
|
50
|
+
if (heading.attr('aria-sort')) {
|
|
51
|
+
this.createHeadingButton(heading, i);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
SortableTable.prototype.createHeadingButton = function (heading, i) {
|
|
57
|
+
const text = heading.text();
|
|
58
|
+
const button = $(`<button type="button" data-index="${i}">${text}</button>`);
|
|
59
|
+
heading.text('');
|
|
60
|
+
heading.append(button);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
SortableTable.prototype.createStatusBox = function () {
|
|
64
|
+
this.status = $(
|
|
65
|
+
'<div aria-live="polite" role="status" aria-atomic="true" class="govuk-visually-hidden" />'
|
|
66
|
+
);
|
|
67
|
+
this.table.parent().append(this.status);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
SortableTable.prototype.initialiseSortedColumn = function () {
|
|
71
|
+
const rows = this.getTableRowsArray();
|
|
72
|
+
|
|
73
|
+
this.table
|
|
74
|
+
.find('th')
|
|
75
|
+
.filter('[aria-sort="ascending"], [aria-sort="descending"]')
|
|
76
|
+
.first()
|
|
77
|
+
.each((index, el) => {
|
|
78
|
+
const sortDirection = $(el).attr('aria-sort');
|
|
79
|
+
const columnNumber = $(el).find('button').attr('data-index');
|
|
80
|
+
const sortedRows = this.sort(rows, columnNumber, sortDirection);
|
|
81
|
+
this.addRows(sortedRows);
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
SortableTable.prototype.onSortButtonClick = function (e) {
|
|
86
|
+
const columnNumber = e.currentTarget.getAttribute('data-index');
|
|
87
|
+
const sortDirection = $(e.currentTarget).parent().attr('aria-sort');
|
|
88
|
+
let newSortDirection;
|
|
89
|
+
if (sortDirection === 'none' || sortDirection === 'descending') {
|
|
90
|
+
newSortDirection = 'ascending';
|
|
91
|
+
} else {
|
|
92
|
+
newSortDirection = 'descending';
|
|
93
|
+
}
|
|
94
|
+
const rows = this.getTableRowsArray();
|
|
95
|
+
const sortedRows = this.sort(rows, columnNumber, newSortDirection);
|
|
96
|
+
this.addRows(sortedRows);
|
|
97
|
+
this.removeButtonStates();
|
|
98
|
+
this.updateButtonState($(e.currentTarget), newSortDirection);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
SortableTable.prototype.updateButtonState = function (button, direction) {
|
|
102
|
+
button.parent().attr('aria-sort', direction);
|
|
103
|
+
let message = this.statusMessage;
|
|
104
|
+
message = message.replace(/%heading%/, button.text());
|
|
105
|
+
message = message.replace(/%direction%/, this[`${direction}Text`]);
|
|
106
|
+
this.status.text(message);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
SortableTable.prototype.removeButtonStates = function () {
|
|
110
|
+
this.table.find('thead th').attr('aria-sort', 'none');
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
SortableTable.prototype.addRows = function (rows) {
|
|
114
|
+
for (let i = 0; i < rows.length; i++) {
|
|
115
|
+
this.body.append(rows[i]);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
SortableTable.prototype.getTableRowsArray = function () {
|
|
120
|
+
const rows = [];
|
|
121
|
+
const trs = this.body.find('tr');
|
|
122
|
+
for (let i = 0; i < trs.length; i++) {
|
|
123
|
+
rows.push(trs[i]);
|
|
124
|
+
}
|
|
125
|
+
return rows
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
SortableTable.prototype.sort = function (rows, columnNumber, sortDirection) {
|
|
129
|
+
const newRows = rows.sort(
|
|
130
|
+
function (rowA, rowB) {
|
|
131
|
+
const tdA = $(rowA).find('td,th').eq(columnNumber);
|
|
132
|
+
const tdB = $(rowB).find('td,th').eq(columnNumber);
|
|
133
|
+
|
|
134
|
+
const valueA =
|
|
135
|
+
sortDirection === 'ascending'
|
|
136
|
+
? this.getCellValue(tdA)
|
|
137
|
+
: this.getCellValue(tdB);
|
|
138
|
+
const valueB =
|
|
139
|
+
sortDirection === 'ascending'
|
|
140
|
+
? this.getCellValue(tdB)
|
|
141
|
+
: this.getCellValue(tdA);
|
|
142
|
+
|
|
143
|
+
if (typeof valueA === 'string' || typeof valueB === 'string')
|
|
144
|
+
return valueA.toString().localeCompare(valueB.toString())
|
|
145
|
+
return valueA - valueB
|
|
146
|
+
}.bind(this)
|
|
147
|
+
);
|
|
148
|
+
return newRows
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
SortableTable.prototype.getCellValue = function (cell) {
|
|
152
|
+
const val = cell.attr('data-sort-value') || cell.html();
|
|
153
|
+
|
|
154
|
+
const valAsNumber = Number(val);
|
|
155
|
+
return isNaN(valAsNumber) ? val : valAsNumber
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
sortableTable$1 = { SortableTable };
|
|
159
|
+
return sortableTable$1;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
var sortableTableExports = requireSortableTable();
|
|
163
|
+
var sortableTable = /*@__PURE__*/getDefaultExportFromCjs(sortableTableExports);
|
|
164
|
+
|
|
165
|
+
return sortableTable;
|
|
166
|
+
|
|
167
|
+
}));
|
package/moj/helpers/_links.scss
CHANGED