@ministryofjustice/frontend 3.5.0 → 3.6.1

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 (37) hide show
  1. package/moj/all.jquery.min.js +1 -81
  2. package/moj/all.js +2577 -2853
  3. package/moj/all.mjs +126 -0
  4. package/moj/all.scss +1 -1
  5. package/moj/components/add-another/add-another.js +111 -132
  6. package/moj/components/add-another/add-another.mjs +106 -0
  7. package/moj/components/alert/alert.js +352 -479
  8. package/moj/components/alert/alert.mjs +251 -0
  9. package/moj/components/alert/alert.spec.helper.js +6 -24
  10. package/moj/components/alert/alert.spec.helper.mjs +66 -0
  11. package/moj/components/button-menu/button-menu.js +326 -343
  12. package/moj/components/button-menu/button-menu.mjs +329 -0
  13. package/moj/components/cookie-banner/_cookie-banner.scss +1 -1
  14. package/moj/components/date-picker/date-picker.js +905 -922
  15. package/moj/components/date-picker/date-picker.mjs +961 -0
  16. package/moj/components/filter-toggle-button/filter-toggle-button.js +98 -119
  17. package/moj/components/filter-toggle-button/filter-toggle-button.mjs +93 -0
  18. package/moj/components/form-validator/form-validator.js +201 -396
  19. package/moj/components/form-validator/form-validator.mjs +168 -0
  20. package/moj/components/multi-file-upload/multi-file-upload.js +227 -441
  21. package/moj/components/multi-file-upload/multi-file-upload.mjs +219 -0
  22. package/moj/components/multi-select/multi-select.js +82 -103
  23. package/moj/components/multi-select/multi-select.mjs +77 -0
  24. package/moj/components/password-reveal/password-reveal.js +40 -61
  25. package/moj/components/password-reveal/password-reveal.mjs +35 -0
  26. package/moj/components/rich-text-editor/rich-text-editor.js +162 -183
  27. package/moj/components/rich-text-editor/rich-text-editor.mjs +157 -0
  28. package/moj/components/search-toggle/search-toggle.js +52 -73
  29. package/moj/components/search-toggle/search-toggle.mjs +54 -0
  30. package/moj/components/sortable-table/sortable-table.js +143 -164
  31. package/moj/components/sortable-table/sortable-table.mjs +138 -0
  32. package/moj/helpers.js +196 -215
  33. package/moj/helpers.mjs +123 -0
  34. package/moj/moj-frontend.min.js +1 -81
  35. package/moj/version.js +6 -23
  36. package/moj/version.mjs +3 -0
  37. package/package.json +24 -6
@@ -0,0 +1,219 @@
1
+ import { dragAndDropSupported, formDataSupported, fileApiSupported } from '../../helpers.mjs';
2
+
3
+ function MultiFileUpload(params) {
4
+ if (!(dragAndDropSupported() && formDataSupported() && fileApiSupported())) {
5
+ return
6
+ }
7
+
8
+ this.defaultParams = {
9
+ uploadFileEntryHook: window.jQuery.noop,
10
+ uploadFileExitHook: window.jQuery.noop,
11
+ uploadFileErrorHook: window.jQuery.noop,
12
+ fileDeleteHook: window.jQuery.noop,
13
+ uploadStatusText: 'Uploading files, please wait',
14
+ dropzoneHintText: 'Drag and drop files here or',
15
+ dropzoneButtonText: 'Choose files'
16
+ };
17
+
18
+ this.params = window.jQuery.extend({}, this.defaultParams, params);
19
+ this.container = window.jQuery(this.params.container);
20
+
21
+ this.container.addClass('moj-multi-file-upload--enhanced');
22
+
23
+ this.feedbackContainer = this.container.find(
24
+ '.moj-multi-file__uploaded-files'
25
+ );
26
+ this.setupFileInput();
27
+ this.setupDropzone();
28
+ this.setupLabel();
29
+ this.setupStatusBox();
30
+ this.container.on(
31
+ 'click',
32
+ '.moj-multi-file-upload__delete',
33
+ window.jQuery.proxy(this, 'onFileDeleteClick')
34
+ );
35
+ }
36
+
37
+ MultiFileUpload.prototype.setupDropzone = function () {
38
+ this.fileInput.wrap('<div class="moj-multi-file-upload__dropzone" />');
39
+ this.dropzone = this.container.find('.moj-multi-file-upload__dropzone');
40
+ this.dropzone.on('dragover', window.jQuery.proxy(this, 'onDragOver'));
41
+ this.dropzone.on('dragleave', window.jQuery.proxy(this, 'onDragLeave'));
42
+ this.dropzone.on('drop', window.jQuery.proxy(this, 'onDrop'));
43
+ };
44
+
45
+ MultiFileUpload.prototype.setupLabel = function () {
46
+ this.label = window.jQuery(
47
+ `<label for="${this.fileInput[0].id}" class="govuk-button govuk-button--secondary">${this.params.dropzoneButtonText}</label>`
48
+ );
49
+ this.dropzone.append(
50
+ `<p class="govuk-body">${this.params.dropzoneHintText}</p>`
51
+ );
52
+ this.dropzone.append(this.label);
53
+ };
54
+
55
+ MultiFileUpload.prototype.setupFileInput = function () {
56
+ this.fileInput = this.container.find('.moj-multi-file-upload__input');
57
+ this.fileInput.on('change', window.jQuery.proxy(this, 'onFileChange'));
58
+ this.fileInput.on('focus', window.jQuery.proxy(this, 'onFileFocus'));
59
+ this.fileInput.on('blur', window.jQuery.proxy(this, 'onFileBlur'));
60
+ };
61
+
62
+ MultiFileUpload.prototype.setupStatusBox = function () {
63
+ this.status = window.jQuery(
64
+ '<div aria-live="polite" role="status" class="govuk-visually-hidden" />'
65
+ );
66
+ this.dropzone.append(this.status);
67
+ };
68
+
69
+ MultiFileUpload.prototype.onDragOver = function (e) {
70
+ e.preventDefault();
71
+ this.dropzone.addClass('moj-multi-file-upload--dragover');
72
+ };
73
+
74
+ MultiFileUpload.prototype.onDragLeave = function () {
75
+ this.dropzone.removeClass('moj-multi-file-upload--dragover');
76
+ };
77
+
78
+ MultiFileUpload.prototype.onDrop = function (e) {
79
+ e.preventDefault();
80
+ this.dropzone.removeClass('moj-multi-file-upload--dragover');
81
+ this.feedbackContainer.removeClass('moj-hidden');
82
+ this.status.html(this.params.uploadStatusText);
83
+ this.uploadFiles(e.originalEvent.dataTransfer.files);
84
+ };
85
+
86
+ MultiFileUpload.prototype.uploadFiles = function (files) {
87
+ for (let i = 0; i < files.length; i++) {
88
+ this.uploadFile(files[i]);
89
+ }
90
+ };
91
+
92
+ MultiFileUpload.prototype.onFileChange = function (e) {
93
+ this.feedbackContainer.removeClass('moj-hidden');
94
+ this.status.html(this.params.uploadStatusText);
95
+ this.uploadFiles(e.currentTarget.files);
96
+ this.fileInput.replaceWith(window.jQuery(e.currentTarget).val('').clone(true));
97
+ this.setupFileInput();
98
+ this.fileInput.get(0).focus();
99
+ };
100
+
101
+ MultiFileUpload.prototype.onFileFocus = function (e) {
102
+ this.label.addClass('moj-multi-file-upload--focused');
103
+ };
104
+
105
+ MultiFileUpload.prototype.onFileBlur = function (e) {
106
+ this.label.removeClass('moj-multi-file-upload--focused');
107
+ };
108
+
109
+ MultiFileUpload.prototype.getSuccessHtml = function (success) {
110
+ return `<span class="moj-multi-file-upload__success"> <svg class="moj-banner__icon" fill="currentColor" role="presentation" focusable="false" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 25 25" height="25" width="25"><path d="M25,6.2L8.7,23.2L0,14.1l4-4.2l4.7,4.9L21,2L25,6.2z"/></svg>${success.messageHtml}</span>`
111
+ };
112
+
113
+ MultiFileUpload.prototype.getErrorHtml = function (error) {
114
+ return `<span class="moj-multi-file-upload__error"> <svg class="moj-banner__icon" fill="currentColor" role="presentation" focusable="false" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 25 25" height="25" width="25"><path d="M13.6,15.4h-2.3v-4.5h2.3V15.4z M13.6,19.8h-2.3v-2.2h2.3V19.8z M0,23.2h25L12.5,2L0,23.2z"/></svg>${error.message}</span>`
115
+ };
116
+
117
+ MultiFileUpload.prototype.getFileRowHtml = function (file) {
118
+ const html = `
119
+ <div class="govuk-summary-list__row moj-multi-file-upload__row">;
120
+ <div class="govuk-summary-list__value moj-multi-file-upload__message">;
121
+ <span class="moj-multi-file-upload__filename">${file.name}</span>;
122
+ <span class="moj-multi-file-upload__progress">0%</span>;
123
+ </div>';
124
+ <div class="govuk-summary-list__actions moj-multi-file-upload__actions"></div>;
125
+ </div>`;
126
+ return html
127
+ };
128
+
129
+ MultiFileUpload.prototype.getDeleteButtonHtml = function (file) {
130
+ return `<button class="moj-multi-file-upload__delete govuk-button govuk-button--secondary govuk-!-margin-bottom-0" type="button" name="delete" value="${file.filename}">
131
+ Delete <span class="govuk-visually-hidden">${file.originalname}</span>
132
+ </button>`
133
+ };
134
+
135
+ MultiFileUpload.prototype.uploadFile = function (file) {
136
+ this.params.uploadFileEntryHook(this, file);
137
+ const item = window.jQuery(this.getFileRowHtml(file));
138
+ const formData = new FormData();
139
+ formData.append('documents', file);
140
+ this.feedbackContainer.find('.moj-multi-file-upload__list').append(item);
141
+
142
+ window.jQuery.ajax({
143
+ url: this.params.uploadUrl,
144
+ type: 'post',
145
+ data: formData,
146
+ processData: false,
147
+ contentType: false,
148
+ success: window.jQuery.proxy(function (response) {
149
+ if (response.error) {
150
+ item
151
+ .find('.moj-multi-file-upload__message')
152
+ .html(this.getErrorHtml(response.error));
153
+ this.status.html(response.error.message);
154
+ } else {
155
+ item
156
+ .find('.moj-multi-file-upload__message')
157
+ .html(this.getSuccessHtml(response.success));
158
+ this.status.html(response.success.messageText);
159
+ }
160
+ item
161
+ .find('.moj-multi-file-upload__actions')
162
+ .append(this.getDeleteButtonHtml(response.file));
163
+ this.params.uploadFileExitHook(this, file, response);
164
+ }, this),
165
+ error: window.jQuery.proxy(function (jqXHR, textStatus, errorThrown) {
166
+ this.params.uploadFileErrorHook(
167
+ this,
168
+ file,
169
+ jqXHR,
170
+ textStatus,
171
+ errorThrown
172
+ );
173
+ }, this),
174
+ xhr: function () {
175
+ const xhr = new XMLHttpRequest();
176
+ xhr.upload.addEventListener(
177
+ 'progress',
178
+ function (e) {
179
+ if (e.lengthComputable) {
180
+ let percentComplete = e.loaded / e.total;
181
+ percentComplete = parseInt(percentComplete * 100, 10);
182
+ item
183
+ .find('.moj-multi-file-upload__progress')
184
+ .text(` ${percentComplete}%`);
185
+ }
186
+ },
187
+ false
188
+ );
189
+ return xhr
190
+ }
191
+ });
192
+ };
193
+
194
+ MultiFileUpload.prototype.onFileDeleteClick = function (e) {
195
+ e.preventDefault(); // if user refreshes page and then deletes
196
+ const button = window.jQuery(e.currentTarget);
197
+ const data = {};
198
+ data[button[0].name] = button[0].value;
199
+ window.jQuery.ajax({
200
+ url: this.params.deleteUrl,
201
+ type: 'post',
202
+ dataType: 'json',
203
+ data,
204
+ success: window.jQuery.proxy(function (response) {
205
+ if (response.error) ; else {
206
+ button.parents('.moj-multi-file-upload__row').remove();
207
+ if (
208
+ this.feedbackContainer.find('.moj-multi-file-upload__row').length ===
209
+ 0
210
+ ) {
211
+ this.feedbackContainer.addClass('moj-hidden');
212
+ }
213
+ }
214
+ this.params.fileDeleteHook(this, response);
215
+ }, this)
216
+ });
217
+ };
218
+
219
+ export { MultiFileUpload };
@@ -1,106 +1,85 @@
1
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 multiSelect$1;
14
- var hasRequiredMultiSelect;
15
-
16
- function requireMultiSelect () {
17
- if (hasRequiredMultiSelect) return multiSelect$1;
18
- hasRequiredMultiSelect = 1;
19
- const $ = _global_window_jQuery;
20
-
21
- function MultiSelect(options) {
22
- this.container = $(options.container);
23
-
24
- if (this.container.data('moj-multi-select-initialised')) {
25
- return
26
- }
27
-
28
- this.container.data('moj-multi-select-initialised', true);
29
-
30
- const idPrefix = options.id_prefix;
31
- let allId = 'checkboxes-all';
32
- if (typeof idPrefix !== 'undefined') {
33
- allId = `${idPrefix}checkboxes-all`;
34
- }
35
-
36
- this.toggle = $(this.getToggleHtml(allId));
37
- this.toggleButton = this.toggle.find('input');
38
- this.toggleButton.on('click', $.proxy(this, 'onButtonClick'));
39
- this.container.append(this.toggle);
40
- this.checkboxes = $(options.checkboxes);
41
- this.checkboxes.on('click', $.proxy(this, 'onCheckboxClick'));
42
- this.checked = options.checked || false;
43
- }
44
-
45
- MultiSelect.prototype.getToggleHtml = function (allId) {
46
- let html = '';
47
- html +=
48
- '<div class="govuk-checkboxes__item govuk-checkboxes--small moj-multi-select__checkbox">';
49
- html += ` <input type="checkbox" class="govuk-checkboxes__input" id="${allId}">`;
50
- html += ` <label class="govuk-label govuk-checkboxes__label moj-multi-select__toggle-label" for="${allId}">`;
51
- html += ' <span class="govuk-visually-hidden">Select all</span>';
52
- html += ' </label>';
53
- html += '</div>';
54
- return html
55
- };
56
-
57
- MultiSelect.prototype.onButtonClick = function (e) {
58
- if (this.checked) {
59
- this.uncheckAll();
60
- this.toggleButton[0].checked = false;
61
- } else {
62
- this.checkAll();
63
- this.toggleButton[0].checked = true;
64
- }
65
- };
66
-
67
- MultiSelect.prototype.checkAll = function () {
68
- this.checkboxes.each(
69
- $.proxy(function (index, el) {
70
- el.checked = true;
71
- }, this)
72
- );
73
- this.checked = true;
74
- };
75
-
76
- MultiSelect.prototype.uncheckAll = function () {
77
- this.checkboxes.each(
78
- $.proxy(function (index, el) {
79
- el.checked = false;
80
- }, this)
81
- );
82
- this.checked = false;
83
- };
84
-
85
- MultiSelect.prototype.onCheckboxClick = function (e) {
86
- if (!e.target.checked) {
87
- this.toggleButton[0].checked = false;
88
- this.checked = false;
89
- } else {
90
- if (this.checkboxes.filter(':checked').length === this.checkboxes.length) {
91
- this.toggleButton[0].checked = true;
92
- this.checked = true;
93
- }
94
- }
95
- };
96
-
97
- multiSelect$1 = { MultiSelect };
98
- return multiSelect$1;
99
- }
100
-
101
- var multiSelectExports = requireMultiSelect();
102
- var multiSelect = /*@__PURE__*/getDefaultExportFromCjs(multiSelectExports);
103
-
104
- return multiSelect;
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
+ function MultiSelect(options) {
8
+ this.container = window.jQuery(options.container);
9
+
10
+ if (this.container.data('moj-multi-select-initialised')) {
11
+ return
12
+ }
13
+
14
+ this.container.data('moj-multi-select-initialised', true);
15
+
16
+ const idPrefix = options.id_prefix;
17
+ let allId = 'checkboxes-all';
18
+ if (typeof idPrefix !== 'undefined') {
19
+ allId = `${idPrefix}checkboxes-all`;
20
+ }
21
+
22
+ this.toggle = window.jQuery(this.getToggleHtml(allId));
23
+ this.toggleButton = this.toggle.find('input');
24
+ this.toggleButton.on('click', window.jQuery.proxy(this, 'onButtonClick'));
25
+ this.container.append(this.toggle);
26
+ this.checkboxes = window.jQuery(options.checkboxes);
27
+ this.checkboxes.on('click', window.jQuery.proxy(this, 'onCheckboxClick'));
28
+ this.checked = options.checked || false;
29
+ }
30
+
31
+ MultiSelect.prototype.getToggleHtml = function (allId) {
32
+ let html = '';
33
+ html +=
34
+ '<div class="govuk-checkboxes__item govuk-checkboxes--small moj-multi-select__checkbox">';
35
+ html += ` <input type="checkbox" class="govuk-checkboxes__input" id="${allId}">`;
36
+ html += ` <label class="govuk-label govuk-checkboxes__label moj-multi-select__toggle-label" for="${allId}">`;
37
+ html += ' <span class="govuk-visually-hidden">Select all</span>';
38
+ html += ' </label>';
39
+ html += '</div>';
40
+ return html
41
+ };
42
+
43
+ MultiSelect.prototype.onButtonClick = function (e) {
44
+ if (this.checked) {
45
+ this.uncheckAll();
46
+ this.toggleButton[0].checked = false;
47
+ } else {
48
+ this.checkAll();
49
+ this.toggleButton[0].checked = true;
50
+ }
51
+ };
52
+
53
+ MultiSelect.prototype.checkAll = function () {
54
+ this.checkboxes.each(
55
+ window.jQuery.proxy(function (index, el) {
56
+ el.checked = true;
57
+ }, this)
58
+ );
59
+ this.checked = true;
60
+ };
61
+
62
+ MultiSelect.prototype.uncheckAll = function () {
63
+ this.checkboxes.each(
64
+ window.jQuery.proxy(function (index, el) {
65
+ el.checked = false;
66
+ }, this)
67
+ );
68
+ this.checked = false;
69
+ };
70
+
71
+ MultiSelect.prototype.onCheckboxClick = function (e) {
72
+ if (!e.target.checked) {
73
+ this.toggleButton[0].checked = false;
74
+ this.checked = false;
75
+ } else {
76
+ if (this.checkboxes.filter(':checked').length === this.checkboxes.length) {
77
+ this.toggleButton[0].checked = true;
78
+ this.checked = true;
79
+ }
80
+ }
81
+ };
82
+
83
+ exports.MultiSelect = MultiSelect;
105
84
 
106
85
  }));
@@ -0,0 +1,77 @@
1
+ function MultiSelect(options) {
2
+ this.container = window.jQuery(options.container);
3
+
4
+ if (this.container.data('moj-multi-select-initialised')) {
5
+ return
6
+ }
7
+
8
+ this.container.data('moj-multi-select-initialised', true);
9
+
10
+ const idPrefix = options.id_prefix;
11
+ let allId = 'checkboxes-all';
12
+ if (typeof idPrefix !== 'undefined') {
13
+ allId = `${idPrefix}checkboxes-all`;
14
+ }
15
+
16
+ this.toggle = window.jQuery(this.getToggleHtml(allId));
17
+ this.toggleButton = this.toggle.find('input');
18
+ this.toggleButton.on('click', window.jQuery.proxy(this, 'onButtonClick'));
19
+ this.container.append(this.toggle);
20
+ this.checkboxes = window.jQuery(options.checkboxes);
21
+ this.checkboxes.on('click', window.jQuery.proxy(this, 'onCheckboxClick'));
22
+ this.checked = options.checked || false;
23
+ }
24
+
25
+ MultiSelect.prototype.getToggleHtml = function (allId) {
26
+ let html = '';
27
+ html +=
28
+ '<div class="govuk-checkboxes__item govuk-checkboxes--small moj-multi-select__checkbox">';
29
+ html += ` <input type="checkbox" class="govuk-checkboxes__input" id="${allId}">`;
30
+ html += ` <label class="govuk-label govuk-checkboxes__label moj-multi-select__toggle-label" for="${allId}">`;
31
+ html += ' <span class="govuk-visually-hidden">Select all</span>';
32
+ html += ' </label>';
33
+ html += '</div>';
34
+ return html
35
+ };
36
+
37
+ MultiSelect.prototype.onButtonClick = function (e) {
38
+ if (this.checked) {
39
+ this.uncheckAll();
40
+ this.toggleButton[0].checked = false;
41
+ } else {
42
+ this.checkAll();
43
+ this.toggleButton[0].checked = true;
44
+ }
45
+ };
46
+
47
+ MultiSelect.prototype.checkAll = function () {
48
+ this.checkboxes.each(
49
+ window.jQuery.proxy(function (index, el) {
50
+ el.checked = true;
51
+ }, this)
52
+ );
53
+ this.checked = true;
54
+ };
55
+
56
+ MultiSelect.prototype.uncheckAll = function () {
57
+ this.checkboxes.each(
58
+ window.jQuery.proxy(function (index, el) {
59
+ el.checked = false;
60
+ }, this)
61
+ );
62
+ this.checked = false;
63
+ };
64
+
65
+ MultiSelect.prototype.onCheckboxClick = function (e) {
66
+ if (!e.target.checked) {
67
+ this.toggleButton[0].checked = false;
68
+ this.checked = false;
69
+ } else {
70
+ if (this.checkboxes.filter(':checked').length === this.checkboxes.length) {
71
+ this.toggleButton[0].checked = true;
72
+ this.checked = true;
73
+ }
74
+ }
75
+ };
76
+
77
+ export { MultiSelect };
@@ -1,64 +1,43 @@
1
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 passwordReveal$1;
14
- var hasRequiredPasswordReveal;
15
-
16
- function requirePasswordReveal () {
17
- if (hasRequiredPasswordReveal) return passwordReveal$1;
18
- hasRequiredPasswordReveal = 1;
19
- const $ = _global_window_jQuery;
20
-
21
- function PasswordReveal(element) {
22
- this.el = element;
23
- const $el = $(this.el);
24
-
25
- if ($el.data('moj-password-reveal-initialised')) {
26
- return
27
- }
28
-
29
- $el.data('moj-password-reveal-initialised', true);
30
- $el.attr('spellcheck', 'false');
31
-
32
- $el.wrap('<div class="moj-password-reveal"></div>');
33
- this.container = $(this.el).parent();
34
- this.createButton();
35
- }
36
-
37
- PasswordReveal.prototype.createButton = function () {
38
- this.button = $(
39
- '<button type="button" class="govuk-button govuk-button--secondary moj-password-reveal__button">Show <span class="govuk-visually-hidden">password</span></button>'
40
- );
41
- this.container.append(this.button);
42
- this.button.on('click', $.proxy(this, 'onButtonClick'));
43
- };
44
-
45
- PasswordReveal.prototype.onButtonClick = function () {
46
- if (this.el.type === 'password') {
47
- this.el.type = 'text';
48
- this.button.html('Hide <span class="govuk-visually-hidden">password</span>');
49
- } else {
50
- this.el.type = 'password';
51
- this.button.html('Show <span class="govuk-visually-hidden">password</span>');
52
- }
53
- };
54
-
55
- passwordReveal$1 = { PasswordReveal };
56
- return passwordReveal$1;
57
- }
58
-
59
- var passwordRevealExports = requirePasswordReveal();
60
- var passwordReveal = /*@__PURE__*/getDefaultExportFromCjs(passwordRevealExports);
61
-
62
- return passwordReveal;
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
+ function PasswordReveal(element) {
8
+ this.el = element;
9
+ const $el = window.jQuery(this.el);
10
+
11
+ if ($el.data('moj-password-reveal-initialised')) {
12
+ return
13
+ }
14
+
15
+ $el.data('moj-password-reveal-initialised', true);
16
+ $el.attr('spellcheck', 'false');
17
+
18
+ $el.wrap('<div class="moj-password-reveal"></div>');
19
+ this.container = window.jQuery(this.el).parent();
20
+ this.createButton();
21
+ }
22
+
23
+ PasswordReveal.prototype.createButton = function () {
24
+ this.button = window.jQuery(
25
+ '<button type="button" class="govuk-button govuk-button--secondary moj-password-reveal__button">Show <span class="govuk-visually-hidden">password</span></button>'
26
+ );
27
+ this.container.append(this.button);
28
+ this.button.on('click', window.jQuery.proxy(this, 'onButtonClick'));
29
+ };
30
+
31
+ PasswordReveal.prototype.onButtonClick = function () {
32
+ if (this.el.type === 'password') {
33
+ this.el.type = 'text';
34
+ this.button.html('Hide <span class="govuk-visually-hidden">password</span>');
35
+ } else {
36
+ this.el.type = 'password';
37
+ this.button.html('Show <span class="govuk-visually-hidden">password</span>');
38
+ }
39
+ };
40
+
41
+ exports.PasswordReveal = PasswordReveal;
63
42
 
64
43
  }));
@@ -0,0 +1,35 @@
1
+ function PasswordReveal(element) {
2
+ this.el = element;
3
+ const $el = window.jQuery(this.el);
4
+
5
+ if ($el.data('moj-password-reveal-initialised')) {
6
+ return
7
+ }
8
+
9
+ $el.data('moj-password-reveal-initialised', true);
10
+ $el.attr('spellcheck', 'false');
11
+
12
+ $el.wrap('<div class="moj-password-reveal"></div>');
13
+ this.container = window.jQuery(this.el).parent();
14
+ this.createButton();
15
+ }
16
+
17
+ PasswordReveal.prototype.createButton = function () {
18
+ this.button = window.jQuery(
19
+ '<button type="button" class="govuk-button govuk-button--secondary moj-password-reveal__button">Show <span class="govuk-visually-hidden">password</span></button>'
20
+ );
21
+ this.container.append(this.button);
22
+ this.button.on('click', window.jQuery.proxy(this, 'onButtonClick'));
23
+ };
24
+
25
+ PasswordReveal.prototype.onButtonClick = function () {
26
+ if (this.el.type === 'password') {
27
+ this.el.type = 'text';
28
+ this.button.html('Hide <span class="govuk-visually-hidden">password</span>');
29
+ } else {
30
+ this.el.type = 'password';
31
+ this.button.html('Show <span class="govuk-visually-hidden">password</span>');
32
+ }
33
+ };
34
+
35
+ export { PasswordReveal };