@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.
Files changed (33) hide show
  1. package/moj/all.jquery.min.js +7 -70
  2. package/moj/all.js +2856 -2865
  3. package/moj/components/add-another/add-another.js +135 -104
  4. package/moj/components/alert/alert.js +482 -247
  5. package/moj/components/alert/alert.spec.helper.js +30 -5
  6. package/moj/components/button-menu/button-menu.js +346 -319
  7. package/moj/components/date-picker/date-picker.js +925 -900
  8. package/moj/components/filter-toggle-button/filter-toggle-button.js +122 -91
  9. package/moj/components/form-validator/form-validator.js +399 -164
  10. package/moj/components/multi-file-upload/multi-file-upload.js +445 -210
  11. package/moj/components/multi-select/multi-select.js +106 -75
  12. package/moj/components/password-reveal/password-reveal.js +64 -33
  13. package/moj/components/rich-text-editor/rich-text-editor.js +186 -153
  14. package/moj/components/search-toggle/search-toggle.js +77 -46
  15. package/moj/components/sortable-table/sortable-table.js +167 -146
  16. package/moj/helpers/_links.scss +1 -1
  17. package/moj/helpers.js +218 -180
  18. package/moj/moj-frontend.min.js +7 -70
  19. package/moj/version.js +28 -1
  20. package/package.json +1 -1
  21. package/moj/all.spec.js +0 -24
  22. package/moj/components/add-another/add-another.spec.js +0 -165
  23. package/moj/components/alert/alert.spec.js +0 -229
  24. package/moj/components/button-menu/button-menu.spec.js +0 -360
  25. package/moj/components/date-picker/date-picker.spec.js +0 -1178
  26. package/moj/components/filter-toggle-button/filter-toggle-button.spec.js +0 -302
  27. package/moj/components/multi-file-upload/multi-file-upload.spec.js +0 -510
  28. package/moj/components/multi-select/multi-select.spec.js +0 -128
  29. package/moj/components/password-reveal/password-reveal.spec.js +0 -57
  30. package/moj/components/search-toggle/search-toggle.spec.js +0 -129
  31. package/moj/components/sortable-table/sortable-table.spec.js +0 -362
  32. package/moj/helpers.spec.js +0 -235
  33. package/moj/namespace.js +0 -2
@@ -1,52 +1,83 @@
1
- MOJFrontend.SearchToggle = function (options) {
2
- this.options = options
3
- this.container = $(this.options.search.container)
4
- this.toggleButtonContainer = $(this.options.toggleButton.container)
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
- if (this.container.data('moj-search-toggle-initialised')) {
7
- return
8
- }
7
+ function getDefaultExportFromCjs (x) {
8
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
9
+ }
9
10
 
10
- this.container.data('moj-search-toggle-initialised', true)
11
+ var _global_window_jQuery = window.jQuery;
11
12
 
12
- const svg =
13
- '<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>'
13
+ var searchToggle$1;
14
+ var hasRequiredSearchToggle;
14
15
 
15
- this.toggleButton = $(
16
- `<button class="moj-search-toggle__button" type="button" aria-haspopup="true" aria-expanded="false">
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
- this.toggleButton.on('click', $.proxy(this, 'onToggleButtonClick'))
21
- this.toggleButtonContainer.append(this.toggleButton)
22
- $(document).on('click', this.onDocumentClick.bind(this))
23
- $(document).on('focusin', this.onDocumentClick.bind(this))
24
- }
25
-
26
- MOJFrontend.SearchToggle.prototype.showMenu = function () {
27
- this.toggleButton.attr('aria-expanded', 'true')
28
- this.container.removeClass('moj-js-hidden')
29
- this.container.find('input').first().get(0).focus()
30
- }
31
-
32
- MOJFrontend.SearchToggle.prototype.hideMenu = function () {
33
- this.container.addClass('moj-js-hidden')
34
- this.toggleButton.attr('aria-expanded', 'false')
35
- }
36
-
37
- MOJFrontend.SearchToggle.prototype.onToggleButtonClick = function () {
38
- if (this.toggleButton.attr('aria-expanded') === 'false') {
39
- this.showMenu()
40
- } else {
41
- this.hideMenu()
42
- }
43
- }
44
-
45
- MOJFrontend.SearchToggle.prototype.onDocumentClick = function (e) {
46
- if (
47
- !$.contains(this.toggleButtonContainer[0], e.target) &&
48
- !$.contains(this.container[0], e.target)
49
- ) {
50
- this.hideMenu()
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
- MOJFrontend.SortableTable = function (params) {
2
- this.table = $(params.table)
3
-
4
- if (this.table.data('moj-search-toggle-initialised')) {
5
- return
6
- }
7
-
8
- this.table.data('moj-search-toggle-initialised', true)
9
-
10
- this.setupOptions(params)
11
- this.body = this.table.find('tbody')
12
- this.createHeadingButtons()
13
- this.createStatusBox()
14
- this.initialiseSortedColumn()
15
- this.table.on('click', 'th button', $.proxy(this, 'onSortButtonClick'))
16
- }
17
-
18
- MOJFrontend.SortableTable.prototype.setupOptions = function (params) {
19
- params = params || {}
20
- this.statusMessage = params.statusMessage || 'Sort by %heading% (%direction%)'
21
- this.ascendingText = params.ascendingText || 'ascending'
22
- this.descendingText = params.descendingText || 'descending'
23
- }
24
-
25
- MOJFrontend.SortableTable.prototype.createHeadingButtons = function () {
26
- const headings = this.table.find('thead th')
27
- let heading
28
- for (let i = 0; i < headings.length; i++) {
29
- heading = $(headings[i])
30
- if (heading.attr('aria-sort')) {
31
- this.createHeadingButton(heading, i)
32
- }
33
- }
34
- }
35
-
36
- MOJFrontend.SortableTable.prototype.createHeadingButton = function (
37
- heading,
38
- i
39
- ) {
40
- const text = heading.text()
41
- const button = $(`<button type="button" data-index="${i}">${text}</button>`)
42
- heading.text('')
43
- heading.append(button)
44
- }
45
-
46
- MOJFrontend.SortableTable.prototype.createStatusBox = function () {
47
- this.status = $(
48
- '<div aria-live="polite" role="status" aria-atomic="true" class="govuk-visually-hidden" />'
49
- )
50
- this.table.parent().append(this.status)
51
- }
52
-
53
- MOJFrontend.SortableTable.prototype.initialiseSortedColumn = function () {
54
- const rows = this.getTableRowsArray()
55
-
56
- this.table
57
- .find('th')
58
- .filter('[aria-sort="ascending"], [aria-sort="descending"]')
59
- .first()
60
- .each((index, el) => {
61
- const sortDirection = $(el).attr('aria-sort')
62
- const columnNumber = $(el).find('button').attr('data-index')
63
- const sortedRows = this.sort(rows, columnNumber, sortDirection)
64
- this.addRows(sortedRows)
65
- })
66
- }
67
-
68
- MOJFrontend.SortableTable.prototype.onSortButtonClick = function (e) {
69
- const columnNumber = e.currentTarget.getAttribute('data-index')
70
- const sortDirection = $(e.currentTarget).parent().attr('aria-sort')
71
- let newSortDirection
72
- if (sortDirection === 'none' || sortDirection === 'descending') {
73
- newSortDirection = 'ascending'
74
- } else {
75
- newSortDirection = 'descending'
76
- }
77
- const rows = this.getTableRowsArray()
78
- const sortedRows = this.sort(rows, columnNumber, newSortDirection)
79
- this.addRows(sortedRows)
80
- this.removeButtonStates()
81
- this.updateButtonState($(e.currentTarget), newSortDirection)
82
- }
83
-
84
- MOJFrontend.SortableTable.prototype.updateButtonState = function (
85
- button,
86
- direction
87
- ) {
88
- button.parent().attr('aria-sort', direction)
89
- let message = this.statusMessage
90
- message = message.replace(/%heading%/, button.text())
91
- message = message.replace(/%direction%/, this[`${direction}Text`])
92
- this.status.text(message)
93
- }
94
-
95
- MOJFrontend.SortableTable.prototype.removeButtonStates = function () {
96
- this.table.find('thead th').attr('aria-sort', 'none')
97
- }
98
-
99
- MOJFrontend.SortableTable.prototype.addRows = function (rows) {
100
- for (let i = 0; i < rows.length; i++) {
101
- this.body.append(rows[i])
102
- }
103
- }
104
-
105
- MOJFrontend.SortableTable.prototype.getTableRowsArray = function () {
106
- const rows = []
107
- const trs = this.body.find('tr')
108
- for (let i = 0; i < trs.length; i++) {
109
- rows.push(trs[i])
110
- }
111
- return rows
112
- }
113
-
114
- MOJFrontend.SortableTable.prototype.sort = function (
115
- rows,
116
- columnNumber,
117
- sortDirection
118
- ) {
119
- const newRows = rows.sort(
120
- function (rowA, rowB) {
121
- const tdA = $(rowA).find('td,th').eq(columnNumber)
122
- const tdB = $(rowB).find('td,th').eq(columnNumber)
123
-
124
- const valueA =
125
- sortDirection === 'ascending'
126
- ? this.getCellValue(tdA)
127
- : this.getCellValue(tdB)
128
- const valueB =
129
- sortDirection === 'ascending'
130
- ? this.getCellValue(tdB)
131
- : this.getCellValue(tdA)
132
-
133
- if (typeof valueA === 'string' || typeof valueB === 'string')
134
- return valueA.toString().localeCompare(valueB.toString())
135
- return valueA - valueB
136
- }.bind(this)
137
- )
138
- return newRows
139
- }
140
-
141
- MOJFrontend.SortableTable.prototype.getCellValue = function (cell) {
142
- const val = cell.attr('data-sort-value') || cell.html()
143
-
144
- const valAsNumber = Number(val)
145
- return isNaN(valAsNumber) ? val : valAsNumber
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
+ }));
@@ -1,4 +1,4 @@
1
- @import '../settings/colours';
1
+ @import "../settings/colours";
2
2
 
3
3
  @mixin moj-link-style-warning {
4
4
  &:link,