@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.
- package/moj/all.jquery.min.js +1 -81
- package/moj/all.js +2577 -2853
- package/moj/all.mjs +126 -0
- package/moj/all.scss +1 -1
- package/moj/components/add-another/add-another.js +111 -132
- package/moj/components/add-another/add-another.mjs +106 -0
- package/moj/components/alert/alert.js +352 -479
- package/moj/components/alert/alert.mjs +251 -0
- package/moj/components/alert/alert.spec.helper.js +6 -24
- package/moj/components/alert/alert.spec.helper.mjs +66 -0
- package/moj/components/button-menu/button-menu.js +326 -343
- package/moj/components/button-menu/button-menu.mjs +329 -0
- package/moj/components/cookie-banner/_cookie-banner.scss +1 -1
- package/moj/components/date-picker/date-picker.js +905 -922
- package/moj/components/date-picker/date-picker.mjs +961 -0
- package/moj/components/filter-toggle-button/filter-toggle-button.js +98 -119
- package/moj/components/filter-toggle-button/filter-toggle-button.mjs +93 -0
- package/moj/components/form-validator/form-validator.js +201 -396
- package/moj/components/form-validator/form-validator.mjs +168 -0
- package/moj/components/multi-file-upload/multi-file-upload.js +227 -441
- package/moj/components/multi-file-upload/multi-file-upload.mjs +219 -0
- package/moj/components/multi-select/multi-select.js +82 -103
- package/moj/components/multi-select/multi-select.mjs +77 -0
- package/moj/components/password-reveal/password-reveal.js +40 -61
- package/moj/components/password-reveal/password-reveal.mjs +35 -0
- package/moj/components/rich-text-editor/rich-text-editor.js +162 -183
- package/moj/components/rich-text-editor/rich-text-editor.mjs +157 -0
- package/moj/components/search-toggle/search-toggle.js +52 -73
- package/moj/components/search-toggle/search-toggle.mjs +54 -0
- package/moj/components/sortable-table/sortable-table.js +143 -164
- package/moj/components/sortable-table/sortable-table.mjs +138 -0
- package/moj/helpers.js +196 -215
- package/moj/helpers.mjs +123 -0
- package/moj/moj-frontend.min.js +1 -81
- package/moj/version.js +6 -23
- package/moj/version.mjs +3 -0
- package/package.json +24 -6
|
@@ -1,347 +1,140 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
})(this, (function () { 'use strict';
|
|
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
|
-
let $sibling = $currentElement.previousElementSibling;
|
|
139
|
-
while ($sibling) {
|
|
140
|
-
// Check if the sibling itself is a heading
|
|
141
|
-
if ($sibling.matches(selector)) {
|
|
142
|
-
return $sibling
|
|
143
|
-
}
|
|
144
|
-
$sibling = $sibling.previousElementSibling;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// If no match found in siblings, move up to parent
|
|
148
|
-
$currentElement = $currentElement.parentElement;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Move focus to element
|
|
154
|
-
*
|
|
155
|
-
* Sets tabindex to -1 to make the element programmatically focusable,
|
|
156
|
-
* but removes it on blur as the element doesn't need to be focused again.
|
|
157
|
-
*
|
|
158
|
-
* @param {HTMLElement} $element - HTML element
|
|
159
|
-
* @param {object} [options] - Handler options
|
|
160
|
-
* @param {function(this: HTMLElement): void} [options.onBeforeFocus] - Callback before focus
|
|
161
|
-
* @param {function(this: HTMLElement): void} [options.onBlur] - Callback on blur
|
|
162
|
-
*/
|
|
163
|
-
function setFocus($element, options = {}) {
|
|
164
|
-
const isFocusable = $element.getAttribute('tabindex');
|
|
165
|
-
|
|
166
|
-
if (!isFocusable) {
|
|
167
|
-
$element.setAttribute('tabindex', '-1');
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Handle element focus
|
|
172
|
-
*/
|
|
173
|
-
function onFocus() {
|
|
174
|
-
$element.addEventListener('blur', onBlur, { once: true });
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Handle element blur
|
|
179
|
-
*/
|
|
180
|
-
function onBlur() {
|
|
181
|
-
if (options.onBlur) {
|
|
182
|
-
options.onBlur.call($element);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
if (!isFocusable) {
|
|
186
|
-
$element.removeAttribute('tabindex');
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// Add listener to reset element on blur, after focus
|
|
191
|
-
$element.addEventListener('focus', onFocus, { once: true });
|
|
192
|
-
|
|
193
|
-
// Focus element
|
|
194
|
-
if (options.onBeforeFocus) {
|
|
195
|
-
options.onBeforeFocus.call($element);
|
|
196
|
-
}
|
|
197
|
-
$element.focus();
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
helpers = {
|
|
201
|
-
removeAttributeValue,
|
|
202
|
-
addAttributeValue,
|
|
203
|
-
dragAndDropSupported,
|
|
204
|
-
formDataSupported,
|
|
205
|
-
fileApiSupported,
|
|
206
|
-
nodeListForEach,
|
|
207
|
-
getNextSibling,
|
|
208
|
-
getPreviousSibling,
|
|
209
|
-
findNearestMatchingElement,
|
|
210
|
-
setFocus
|
|
211
|
-
};
|
|
212
|
-
return helpers;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
var multiFileUpload$1;
|
|
216
|
-
var hasRequiredMultiFileUpload;
|
|
217
|
-
|
|
218
|
-
function requireMultiFileUpload () {
|
|
219
|
-
if (hasRequiredMultiFileUpload) return multiFileUpload$1;
|
|
220
|
-
hasRequiredMultiFileUpload = 1;
|
|
221
|
-
const $ = _global_window_jQuery;
|
|
222
|
-
|
|
223
|
-
const {
|
|
224
|
-
dragAndDropSupported,
|
|
225
|
-
fileApiSupported,
|
|
226
|
-
formDataSupported
|
|
227
|
-
} = requireHelpers();
|
|
228
|
-
|
|
229
|
-
function MultiFileUpload(params) {
|
|
230
|
-
if (!(dragAndDropSupported() && formDataSupported() && fileApiSupported())) {
|
|
231
|
-
return
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
this.defaultParams = {
|
|
235
|
-
uploadFileEntryHook: $.noop,
|
|
236
|
-
uploadFileExitHook: $.noop,
|
|
237
|
-
uploadFileErrorHook: $.noop,
|
|
238
|
-
fileDeleteHook: $.noop,
|
|
239
|
-
uploadStatusText: 'Uploading files, please wait',
|
|
240
|
-
dropzoneHintText: 'Drag and drop files here or',
|
|
241
|
-
dropzoneButtonText: 'Choose files'
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
this.params = $.extend({}, this.defaultParams, params);
|
|
245
|
-
this.container = $(this.params.container);
|
|
246
|
-
|
|
247
|
-
this.container.addClass('moj-multi-file-upload--enhanced');
|
|
248
|
-
|
|
249
|
-
this.feedbackContainer = this.container.find(
|
|
250
|
-
'.moj-multi-file__uploaded-files'
|
|
251
|
-
);
|
|
252
|
-
this.setupFileInput();
|
|
253
|
-
this.setupDropzone();
|
|
254
|
-
this.setupLabel();
|
|
255
|
-
this.setupStatusBox();
|
|
256
|
-
this.container.on(
|
|
257
|
-
'click',
|
|
258
|
-
'.moj-multi-file-upload__delete',
|
|
259
|
-
$.proxy(this, 'onFileDeleteClick')
|
|
260
|
-
);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
MultiFileUpload.prototype.setupDropzone = function () {
|
|
264
|
-
this.fileInput.wrap('<div class="moj-multi-file-upload__dropzone" />');
|
|
265
|
-
this.dropzone = this.container.find('.moj-multi-file-upload__dropzone');
|
|
266
|
-
this.dropzone.on('dragover', $.proxy(this, 'onDragOver'));
|
|
267
|
-
this.dropzone.on('dragleave', $.proxy(this, 'onDragLeave'));
|
|
268
|
-
this.dropzone.on('drop', $.proxy(this, 'onDrop'));
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
MultiFileUpload.prototype.setupLabel = function () {
|
|
272
|
-
this.label = $(
|
|
273
|
-
`<label for="${this.fileInput[0].id}" class="govuk-button govuk-button--secondary">${this.params.dropzoneButtonText}</label>`
|
|
274
|
-
);
|
|
275
|
-
this.dropzone.append(
|
|
276
|
-
`<p class="govuk-body">${this.params.dropzoneHintText}</p>`
|
|
277
|
-
);
|
|
278
|
-
this.dropzone.append(this.label);
|
|
279
|
-
};
|
|
280
|
-
|
|
281
|
-
MultiFileUpload.prototype.setupFileInput = function () {
|
|
282
|
-
this.fileInput = this.container.find('.moj-multi-file-upload__input');
|
|
283
|
-
this.fileInput.on('change', $.proxy(this, 'onFileChange'));
|
|
284
|
-
this.fileInput.on('focus', $.proxy(this, 'onFileFocus'));
|
|
285
|
-
this.fileInput.on('blur', $.proxy(this, 'onFileBlur'));
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
MultiFileUpload.prototype.setupStatusBox = function () {
|
|
289
|
-
this.status = $(
|
|
290
|
-
'<div aria-live="polite" role="status" class="govuk-visually-hidden" />'
|
|
291
|
-
);
|
|
292
|
-
this.dropzone.append(this.status);
|
|
293
|
-
};
|
|
294
|
-
|
|
295
|
-
MultiFileUpload.prototype.onDragOver = function (e) {
|
|
296
|
-
e.preventDefault();
|
|
297
|
-
this.dropzone.addClass('moj-multi-file-upload--dragover');
|
|
298
|
-
};
|
|
299
|
-
|
|
300
|
-
MultiFileUpload.prototype.onDragLeave = function () {
|
|
301
|
-
this.dropzone.removeClass('moj-multi-file-upload--dragover');
|
|
302
|
-
};
|
|
303
|
-
|
|
304
|
-
MultiFileUpload.prototype.onDrop = function (e) {
|
|
305
|
-
e.preventDefault();
|
|
306
|
-
this.dropzone.removeClass('moj-multi-file-upload--dragover');
|
|
307
|
-
this.feedbackContainer.removeClass('moj-hidden');
|
|
308
|
-
this.status.html(this.params.uploadStatusText);
|
|
309
|
-
this.uploadFiles(e.originalEvent.dataTransfer.files);
|
|
310
|
-
};
|
|
311
|
-
|
|
312
|
-
MultiFileUpload.prototype.uploadFiles = function (files) {
|
|
313
|
-
for (let i = 0; i < files.length; i++) {
|
|
314
|
-
this.uploadFile(files[i]);
|
|
315
|
-
}
|
|
316
|
-
};
|
|
317
|
-
|
|
318
|
-
MultiFileUpload.prototype.onFileChange = function (e) {
|
|
319
|
-
this.feedbackContainer.removeClass('moj-hidden');
|
|
320
|
-
this.status.html(this.params.uploadStatusText);
|
|
321
|
-
this.uploadFiles(e.currentTarget.files);
|
|
322
|
-
this.fileInput.replaceWith($(e.currentTarget).val('').clone(true));
|
|
323
|
-
this.setupFileInput();
|
|
324
|
-
this.fileInput.get(0).focus();
|
|
325
|
-
};
|
|
326
|
-
|
|
327
|
-
MultiFileUpload.prototype.onFileFocus = function (e) {
|
|
328
|
-
this.label.addClass('moj-multi-file-upload--focused');
|
|
329
|
-
};
|
|
330
|
-
|
|
331
|
-
MultiFileUpload.prototype.onFileBlur = function (e) {
|
|
332
|
-
this.label.removeClass('moj-multi-file-upload--focused');
|
|
333
|
-
};
|
|
334
|
-
|
|
335
|
-
MultiFileUpload.prototype.getSuccessHtml = function (success) {
|
|
336
|
-
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>`
|
|
337
|
-
};
|
|
338
|
-
|
|
339
|
-
MultiFileUpload.prototype.getErrorHtml = function (error) {
|
|
340
|
-
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>`
|
|
341
|
-
};
|
|
342
|
-
|
|
343
|
-
MultiFileUpload.prototype.getFileRowHtml = function (file) {
|
|
344
|
-
const html = `
|
|
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 dragAndDropSupported() {
|
|
8
|
+
const div = document.createElement('div');
|
|
9
|
+
return typeof div.ondrop !== 'undefined'
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function formDataSupported() {
|
|
13
|
+
return typeof FormData === 'function'
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function fileApiSupported() {
|
|
17
|
+
const input = document.createElement('input');
|
|
18
|
+
input.type = 'file';
|
|
19
|
+
return typeof input.files !== 'undefined'
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function MultiFileUpload(params) {
|
|
23
|
+
if (!(dragAndDropSupported() && formDataSupported() && fileApiSupported())) {
|
|
24
|
+
return
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
this.defaultParams = {
|
|
28
|
+
uploadFileEntryHook: window.jQuery.noop,
|
|
29
|
+
uploadFileExitHook: window.jQuery.noop,
|
|
30
|
+
uploadFileErrorHook: window.jQuery.noop,
|
|
31
|
+
fileDeleteHook: window.jQuery.noop,
|
|
32
|
+
uploadStatusText: 'Uploading files, please wait',
|
|
33
|
+
dropzoneHintText: 'Drag and drop files here or',
|
|
34
|
+
dropzoneButtonText: 'Choose files'
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
this.params = window.jQuery.extend({}, this.defaultParams, params);
|
|
38
|
+
this.container = window.jQuery(this.params.container);
|
|
39
|
+
|
|
40
|
+
this.container.addClass('moj-multi-file-upload--enhanced');
|
|
41
|
+
|
|
42
|
+
this.feedbackContainer = this.container.find(
|
|
43
|
+
'.moj-multi-file__uploaded-files'
|
|
44
|
+
);
|
|
45
|
+
this.setupFileInput();
|
|
46
|
+
this.setupDropzone();
|
|
47
|
+
this.setupLabel();
|
|
48
|
+
this.setupStatusBox();
|
|
49
|
+
this.container.on(
|
|
50
|
+
'click',
|
|
51
|
+
'.moj-multi-file-upload__delete',
|
|
52
|
+
window.jQuery.proxy(this, 'onFileDeleteClick')
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
MultiFileUpload.prototype.setupDropzone = function () {
|
|
57
|
+
this.fileInput.wrap('<div class="moj-multi-file-upload__dropzone" />');
|
|
58
|
+
this.dropzone = this.container.find('.moj-multi-file-upload__dropzone');
|
|
59
|
+
this.dropzone.on('dragover', window.jQuery.proxy(this, 'onDragOver'));
|
|
60
|
+
this.dropzone.on('dragleave', window.jQuery.proxy(this, 'onDragLeave'));
|
|
61
|
+
this.dropzone.on('drop', window.jQuery.proxy(this, 'onDrop'));
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
MultiFileUpload.prototype.setupLabel = function () {
|
|
65
|
+
this.label = window.jQuery(
|
|
66
|
+
`<label for="${this.fileInput[0].id}" class="govuk-button govuk-button--secondary">${this.params.dropzoneButtonText}</label>`
|
|
67
|
+
);
|
|
68
|
+
this.dropzone.append(
|
|
69
|
+
`<p class="govuk-body">${this.params.dropzoneHintText}</p>`
|
|
70
|
+
);
|
|
71
|
+
this.dropzone.append(this.label);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
MultiFileUpload.prototype.setupFileInput = function () {
|
|
75
|
+
this.fileInput = this.container.find('.moj-multi-file-upload__input');
|
|
76
|
+
this.fileInput.on('change', window.jQuery.proxy(this, 'onFileChange'));
|
|
77
|
+
this.fileInput.on('focus', window.jQuery.proxy(this, 'onFileFocus'));
|
|
78
|
+
this.fileInput.on('blur', window.jQuery.proxy(this, 'onFileBlur'));
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
MultiFileUpload.prototype.setupStatusBox = function () {
|
|
82
|
+
this.status = window.jQuery(
|
|
83
|
+
'<div aria-live="polite" role="status" class="govuk-visually-hidden" />'
|
|
84
|
+
);
|
|
85
|
+
this.dropzone.append(this.status);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
MultiFileUpload.prototype.onDragOver = function (e) {
|
|
89
|
+
e.preventDefault();
|
|
90
|
+
this.dropzone.addClass('moj-multi-file-upload--dragover');
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
MultiFileUpload.prototype.onDragLeave = function () {
|
|
94
|
+
this.dropzone.removeClass('moj-multi-file-upload--dragover');
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
MultiFileUpload.prototype.onDrop = function (e) {
|
|
98
|
+
e.preventDefault();
|
|
99
|
+
this.dropzone.removeClass('moj-multi-file-upload--dragover');
|
|
100
|
+
this.feedbackContainer.removeClass('moj-hidden');
|
|
101
|
+
this.status.html(this.params.uploadStatusText);
|
|
102
|
+
this.uploadFiles(e.originalEvent.dataTransfer.files);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
MultiFileUpload.prototype.uploadFiles = function (files) {
|
|
106
|
+
for (let i = 0; i < files.length; i++) {
|
|
107
|
+
this.uploadFile(files[i]);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
MultiFileUpload.prototype.onFileChange = function (e) {
|
|
112
|
+
this.feedbackContainer.removeClass('moj-hidden');
|
|
113
|
+
this.status.html(this.params.uploadStatusText);
|
|
114
|
+
this.uploadFiles(e.currentTarget.files);
|
|
115
|
+
this.fileInput.replaceWith(window.jQuery(e.currentTarget).val('').clone(true));
|
|
116
|
+
this.setupFileInput();
|
|
117
|
+
this.fileInput.get(0).focus();
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
MultiFileUpload.prototype.onFileFocus = function (e) {
|
|
121
|
+
this.label.addClass('moj-multi-file-upload--focused');
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
MultiFileUpload.prototype.onFileBlur = function (e) {
|
|
125
|
+
this.label.removeClass('moj-multi-file-upload--focused');
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
MultiFileUpload.prototype.getSuccessHtml = function (success) {
|
|
129
|
+
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>`
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
MultiFileUpload.prototype.getErrorHtml = function (error) {
|
|
133
|
+
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>`
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
MultiFileUpload.prototype.getFileRowHtml = function (file) {
|
|
137
|
+
const html = `
|
|
345
138
|
<div class="govuk-summary-list__row moj-multi-file-upload__row">;
|
|
346
139
|
<div class="govuk-summary-list__value moj-multi-file-upload__message">;
|
|
347
140
|
<span class="moj-multi-file-upload__filename">${file.name}</span>;
|
|
@@ -349,106 +142,99 @@
|
|
|
349
142
|
</div>';
|
|
350
143
|
<div class="govuk-summary-list__actions moj-multi-file-upload__actions"></div>;
|
|
351
144
|
</div>`;
|
|
352
|
-
|
|
353
|
-
|
|
145
|
+
return html
|
|
146
|
+
};
|
|
354
147
|
|
|
355
|
-
|
|
356
|
-
|
|
148
|
+
MultiFileUpload.prototype.getDeleteButtonHtml = function (file) {
|
|
149
|
+
return `<button class="moj-multi-file-upload__delete govuk-button govuk-button--secondary govuk-!-margin-bottom-0" type="button" name="delete" value="${file.filename}">
|
|
357
150
|
Delete <span class="govuk-visually-hidden">${file.originalname}</span>
|
|
358
151
|
</button>`
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
return multiFileUpload$1;
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
var multiFileUploadExports = requireMultiFileUpload();
|
|
450
|
-
var multiFileUpload = /*@__PURE__*/getDefaultExportFromCjs(multiFileUploadExports);
|
|
451
|
-
|
|
452
|
-
return multiFileUpload;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
MultiFileUpload.prototype.uploadFile = function (file) {
|
|
155
|
+
this.params.uploadFileEntryHook(this, file);
|
|
156
|
+
const item = window.jQuery(this.getFileRowHtml(file));
|
|
157
|
+
const formData = new FormData();
|
|
158
|
+
formData.append('documents', file);
|
|
159
|
+
this.feedbackContainer.find('.moj-multi-file-upload__list').append(item);
|
|
160
|
+
|
|
161
|
+
window.jQuery.ajax({
|
|
162
|
+
url: this.params.uploadUrl,
|
|
163
|
+
type: 'post',
|
|
164
|
+
data: formData,
|
|
165
|
+
processData: false,
|
|
166
|
+
contentType: false,
|
|
167
|
+
success: window.jQuery.proxy(function (response) {
|
|
168
|
+
if (response.error) {
|
|
169
|
+
item
|
|
170
|
+
.find('.moj-multi-file-upload__message')
|
|
171
|
+
.html(this.getErrorHtml(response.error));
|
|
172
|
+
this.status.html(response.error.message);
|
|
173
|
+
} else {
|
|
174
|
+
item
|
|
175
|
+
.find('.moj-multi-file-upload__message')
|
|
176
|
+
.html(this.getSuccessHtml(response.success));
|
|
177
|
+
this.status.html(response.success.messageText);
|
|
178
|
+
}
|
|
179
|
+
item
|
|
180
|
+
.find('.moj-multi-file-upload__actions')
|
|
181
|
+
.append(this.getDeleteButtonHtml(response.file));
|
|
182
|
+
this.params.uploadFileExitHook(this, file, response);
|
|
183
|
+
}, this),
|
|
184
|
+
error: window.jQuery.proxy(function (jqXHR, textStatus, errorThrown) {
|
|
185
|
+
this.params.uploadFileErrorHook(
|
|
186
|
+
this,
|
|
187
|
+
file,
|
|
188
|
+
jqXHR,
|
|
189
|
+
textStatus,
|
|
190
|
+
errorThrown
|
|
191
|
+
);
|
|
192
|
+
}, this),
|
|
193
|
+
xhr: function () {
|
|
194
|
+
const xhr = new XMLHttpRequest();
|
|
195
|
+
xhr.upload.addEventListener(
|
|
196
|
+
'progress',
|
|
197
|
+
function (e) {
|
|
198
|
+
if (e.lengthComputable) {
|
|
199
|
+
let percentComplete = e.loaded / e.total;
|
|
200
|
+
percentComplete = parseInt(percentComplete * 100, 10);
|
|
201
|
+
item
|
|
202
|
+
.find('.moj-multi-file-upload__progress')
|
|
203
|
+
.text(` ${percentComplete}%`);
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
false
|
|
207
|
+
);
|
|
208
|
+
return xhr
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
MultiFileUpload.prototype.onFileDeleteClick = function (e) {
|
|
214
|
+
e.preventDefault(); // if user refreshes page and then deletes
|
|
215
|
+
const button = window.jQuery(e.currentTarget);
|
|
216
|
+
const data = {};
|
|
217
|
+
data[button[0].name] = button[0].value;
|
|
218
|
+
window.jQuery.ajax({
|
|
219
|
+
url: this.params.deleteUrl,
|
|
220
|
+
type: 'post',
|
|
221
|
+
dataType: 'json',
|
|
222
|
+
data,
|
|
223
|
+
success: window.jQuery.proxy(function (response) {
|
|
224
|
+
if (response.error) ; else {
|
|
225
|
+
button.parents('.moj-multi-file-upload__row').remove();
|
|
226
|
+
if (
|
|
227
|
+
this.feedbackContainer.find('.moj-multi-file-upload__row').length ===
|
|
228
|
+
0
|
|
229
|
+
) {
|
|
230
|
+
this.feedbackContainer.addClass('moj-hidden');
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
this.params.fileDeleteHook(this, response);
|
|
234
|
+
}, this)
|
|
235
|
+
});
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
exports.MultiFileUpload = MultiFileUpload;
|
|
453
239
|
|
|
454
240
|
}));
|