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