@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,104 +1,135 @@
1
- MOJFrontend.AddAnother = function (container) {
2
- this.container = $(container)
3
-
4
- if (this.container.data('moj-add-another-initialised')) {
5
- return
6
- }
7
-
8
- this.container.data('moj-add-another-initialised', true)
9
-
10
- this.container.on(
11
- 'click',
12
- '.moj-add-another__remove-button',
13
- $.proxy(this, 'onRemoveButtonClick')
14
- )
15
- this.container.on(
16
- 'click',
17
- '.moj-add-another__add-button',
18
- $.proxy(this, 'onAddButtonClick')
19
- )
20
- this.container
21
- .find('.moj-add-another__add-button, moj-add-another__remove-button')
22
- .prop('type', 'button')
23
- }
24
-
25
- MOJFrontend.AddAnother.prototype.onAddButtonClick = function (e) {
26
- const item = this.getNewItem()
27
- this.updateAttributes(this.getItems().length, item)
28
- this.resetItem(item)
29
- const firstItem = this.getItems().first()
30
- if (!this.hasRemoveButton(firstItem)) {
31
- this.createRemoveButton(firstItem)
32
- }
33
- this.getItems().last().after(item)
34
- item.find('input, textarea, select').first().focus()
35
- }
36
-
37
- MOJFrontend.AddAnother.prototype.hasRemoveButton = function (item) {
38
- return item.find('.moj-add-another__remove-button').length
39
- }
40
-
41
- MOJFrontend.AddAnother.prototype.getItems = function () {
42
- return this.container.find('.moj-add-another__item')
43
- }
44
-
45
- MOJFrontend.AddAnother.prototype.getNewItem = function () {
46
- const item = this.getItems().first().clone()
47
- if (!this.hasRemoveButton(item)) {
48
- this.createRemoveButton(item)
49
- }
50
- return item
51
- }
52
-
53
- MOJFrontend.AddAnother.prototype.updateAttributes = function (index, item) {
54
- item.find('[data-name]').each(function (i, el) {
55
- const originalId = el.id
56
-
57
- el.name = $(el)
58
- .attr('data-name')
59
- .replace(/%index%/, index)
60
- el.id = $(el)
61
- .attr('data-id')
62
- .replace(/%index%/, index)
63
-
64
- const label =
65
- $(el).siblings('label')[0] ||
66
- $(el).parents('label')[0] ||
67
- item.find(`[for="${originalId}"]`)[0]
68
- label.htmlFor = el.id
69
- })
70
- }
71
-
72
- MOJFrontend.AddAnother.prototype.createRemoveButton = function (item) {
73
- item.append(
74
- '<button type="button" class="govuk-button govuk-button--secondary moj-add-another__remove-button">Remove</button>'
75
- )
76
- }
77
-
78
- MOJFrontend.AddAnother.prototype.resetItem = function (item) {
79
- item.find('[data-name], [data-id]').each(function (index, el) {
80
- if (el.type === 'checkbox' || el.type === 'radio') {
81
- el.checked = false
82
- } else {
83
- el.value = ''
84
- }
85
- })
86
- }
87
-
88
- MOJFrontend.AddAnother.prototype.onRemoveButtonClick = function (e) {
89
- $(e.currentTarget).parents('.moj-add-another__item').remove()
90
- const items = this.getItems()
91
- if (items.length === 1) {
92
- items.find('.moj-add-another__remove-button').remove()
93
- }
94
- items.each(
95
- $.proxy(function (index, el) {
96
- this.updateAttributes(index, $(el))
97
- }, this)
98
- )
99
- this.focusHeading()
100
- }
101
-
102
- MOJFrontend.AddAnother.prototype.focusHeading = function () {
103
- this.container.find('.moj-add-another__heading').get(0).focus()
104
- }
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 addAnother$1;
14
+ var hasRequiredAddAnother;
15
+
16
+ function requireAddAnother () {
17
+ if (hasRequiredAddAnother) return addAnother$1;
18
+ hasRequiredAddAnother = 1;
19
+ const $ = _global_window_jQuery;
20
+
21
+ function AddAnother(container) {
22
+ this.container = $(container);
23
+
24
+ if (this.container.data('moj-add-another-initialised')) {
25
+ return
26
+ }
27
+
28
+ this.container.data('moj-add-another-initialised', true);
29
+
30
+ this.container.on(
31
+ 'click',
32
+ '.moj-add-another__remove-button',
33
+ $.proxy(this, 'onRemoveButtonClick')
34
+ );
35
+ this.container.on(
36
+ 'click',
37
+ '.moj-add-another__add-button',
38
+ $.proxy(this, 'onAddButtonClick')
39
+ );
40
+ this.container
41
+ .find('.moj-add-another__add-button, moj-add-another__remove-button')
42
+ .prop('type', 'button');
43
+ }
44
+
45
+ AddAnother.prototype.onAddButtonClick = function (e) {
46
+ const item = this.getNewItem();
47
+ this.updateAttributes(this.getItems().length, item);
48
+ this.resetItem(item);
49
+ const firstItem = this.getItems().first();
50
+ if (!this.hasRemoveButton(firstItem)) {
51
+ this.createRemoveButton(firstItem);
52
+ }
53
+ this.getItems().last().after(item);
54
+ item.find('input, textarea, select').first().focus();
55
+ };
56
+
57
+ AddAnother.prototype.hasRemoveButton = function (item) {
58
+ return item.find('.moj-add-another__remove-button').length
59
+ };
60
+
61
+ AddAnother.prototype.getItems = function () {
62
+ return this.container.find('.moj-add-another__item')
63
+ };
64
+
65
+ AddAnother.prototype.getNewItem = function () {
66
+ const item = this.getItems().first().clone();
67
+ if (!this.hasRemoveButton(item)) {
68
+ this.createRemoveButton(item);
69
+ }
70
+ return item
71
+ };
72
+
73
+ AddAnother.prototype.updateAttributes = function (index, item) {
74
+ item.find('[data-name]').each(function (i, el) {
75
+ const originalId = el.id;
76
+
77
+ el.name = $(el)
78
+ .attr('data-name')
79
+ .replace(/%index%/, index);
80
+ el.id = $(el)
81
+ .attr('data-id')
82
+ .replace(/%index%/, index);
83
+
84
+ const label =
85
+ $(el).siblings('label')[0] ||
86
+ $(el).parents('label')[0] ||
87
+ item.find(`[for="${originalId}"]`)[0];
88
+ label.htmlFor = el.id;
89
+ });
90
+ };
91
+
92
+ AddAnother.prototype.createRemoveButton = function (item) {
93
+ item.append(
94
+ '<button type="button" class="govuk-button govuk-button--secondary moj-add-another__remove-button">Remove</button>'
95
+ );
96
+ };
97
+
98
+ AddAnother.prototype.resetItem = function (item) {
99
+ item.find('[data-name], [data-id]').each(function (index, el) {
100
+ if (el.type === 'checkbox' || el.type === 'radio') {
101
+ el.checked = false;
102
+ } else {
103
+ el.value = '';
104
+ }
105
+ });
106
+ };
107
+
108
+ AddAnother.prototype.onRemoveButtonClick = function (e) {
109
+ $(e.currentTarget).parents('.moj-add-another__item').remove();
110
+ const items = this.getItems();
111
+ if (items.length === 1) {
112
+ items.find('.moj-add-another__remove-button').remove();
113
+ }
114
+ items.each(
115
+ $.proxy(function (index, el) {
116
+ this.updateAttributes(index, $(el));
117
+ }, this)
118
+ );
119
+ this.focusHeading();
120
+ };
121
+
122
+ AddAnother.prototype.focusHeading = function () {
123
+ this.container.find('.moj-add-another__heading').get(0).focus();
124
+ };
125
+
126
+ addAnother$1 = { AddAnother };
127
+ return addAnother$1;
128
+ }
129
+
130
+ var addAnotherExports = requireAddAnother();
131
+ var addAnother = /*@__PURE__*/getDefaultExportFromCjs(addAnotherExports);
132
+
133
+ return addAnother;
134
+
135
+ }));