sweetalert2 11.5.0 → 11.5.2
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/README.md +2 -1
- package/dist/sweetalert2.all.js +376 -721
- package/dist/sweetalert2.all.min.js +1 -1
- package/dist/sweetalert2.js +376 -721
- package/dist/sweetalert2.min.js +1 -1
- package/package.json +5 -5
- package/src/SweetAlert.js +1 -1
- package/src/staticMethods/timer.js +13 -0
- package/src/utils/dom/domUtils.js +3 -1
- package/src/utils/params.js +1 -1
package/dist/sweetalert2.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sweetalert2 v11.5.
|
|
2
|
+
* sweetalert2 v11.5.2
|
|
3
3
|
* Released under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
(function (global, factory) {
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
* Once we have the changes from that PR in Babel, and our core class fits reasonable in *one module*
|
|
18
18
|
* then we can use that language feature.
|
|
19
19
|
*/
|
|
20
|
+
|
|
20
21
|
var privateProps = {
|
|
21
22
|
awaitingPromise: new WeakMap(),
|
|
22
23
|
promise: new WeakMap(),
|
|
@@ -25,98 +26,95 @@
|
|
|
25
26
|
};
|
|
26
27
|
|
|
27
28
|
const swalPrefix = 'swal2-';
|
|
29
|
+
|
|
28
30
|
/**
|
|
29
31
|
* @param {string[]} items
|
|
30
32
|
* @returns {object}
|
|
31
33
|
*/
|
|
32
|
-
|
|
33
34
|
const prefix = items => {
|
|
34
35
|
const result = {};
|
|
35
|
-
|
|
36
36
|
for (const i in items) {
|
|
37
37
|
result[items[i]] = swalPrefix + items[i];
|
|
38
38
|
}
|
|
39
|
-
|
|
40
39
|
return result;
|
|
41
40
|
};
|
|
42
41
|
const swalClasses = prefix(['container', 'shown', 'height-auto', 'iosfix', 'popup', 'modal', 'no-backdrop', 'no-transition', 'toast', 'toast-shown', 'show', 'hide', 'close', 'title', 'html-container', 'actions', 'confirm', 'deny', 'cancel', 'default-outline', 'footer', 'icon', 'icon-content', 'image', 'input', 'file', 'range', 'select', 'radio', 'checkbox', 'label', 'textarea', 'inputerror', 'input-label', 'validation-message', 'progress-steps', 'active-progress-step', 'progress-step', 'progress-step-line', 'loader', 'loading', 'styled', 'top', 'top-start', 'top-end', 'top-left', 'top-right', 'center', 'center-start', 'center-end', 'center-left', 'center-right', 'bottom', 'bottom-start', 'bottom-end', 'bottom-left', 'bottom-right', 'grow-row', 'grow-column', 'grow-fullscreen', 'rtl', 'timer-progress-bar', 'timer-progress-bar-container', 'scrollbar-measure', 'icon-success', 'icon-warning', 'icon-info', 'icon-question', 'icon-error', 'no-war']);
|
|
43
42
|
const iconTypes = prefix(['success', 'warning', 'info', 'question', 'error']);
|
|
44
43
|
|
|
45
44
|
const consolePrefix = 'SweetAlert2:';
|
|
45
|
+
|
|
46
46
|
/**
|
|
47
47
|
* Filter the unique values into a new array
|
|
48
48
|
*
|
|
49
49
|
* @param {Array} arr
|
|
50
50
|
* @returns {Array}
|
|
51
51
|
*/
|
|
52
|
-
|
|
53
52
|
const uniqueArray = arr => {
|
|
54
53
|
const result = [];
|
|
55
|
-
|
|
56
54
|
for (let i = 0; i < arr.length; i++) {
|
|
57
55
|
if (result.indexOf(arr[i]) === -1) {
|
|
58
56
|
result.push(arr[i]);
|
|
59
57
|
}
|
|
60
58
|
}
|
|
61
|
-
|
|
62
59
|
return result;
|
|
63
60
|
};
|
|
61
|
+
|
|
64
62
|
/**
|
|
65
63
|
* Capitalize the first letter of a string
|
|
66
64
|
*
|
|
67
65
|
* @param {string} str
|
|
68
66
|
* @returns {string}
|
|
69
67
|
*/
|
|
70
|
-
|
|
71
68
|
const capitalizeFirstLetter = str => str.charAt(0).toUpperCase() + str.slice(1);
|
|
69
|
+
|
|
72
70
|
/**
|
|
73
71
|
* Standardize console warnings
|
|
74
72
|
*
|
|
75
73
|
* @param {string | Array} message
|
|
76
74
|
*/
|
|
77
|
-
|
|
78
75
|
const warn = message => {
|
|
79
76
|
console.warn("".concat(consolePrefix, " ").concat(typeof message === 'object' ? message.join(' ') : message));
|
|
80
77
|
};
|
|
78
|
+
|
|
81
79
|
/**
|
|
82
80
|
* Standardize console errors
|
|
83
81
|
*
|
|
84
82
|
* @param {string} message
|
|
85
83
|
*/
|
|
86
|
-
|
|
87
84
|
const error = message => {
|
|
88
85
|
console.error("".concat(consolePrefix, " ").concat(message));
|
|
89
86
|
};
|
|
87
|
+
|
|
90
88
|
/**
|
|
91
89
|
* Private global state for `warnOnce`
|
|
92
90
|
*
|
|
93
91
|
* @type {Array}
|
|
94
92
|
* @private
|
|
95
93
|
*/
|
|
96
|
-
|
|
97
94
|
const previousWarnOnceMessages = [];
|
|
95
|
+
|
|
98
96
|
/**
|
|
99
97
|
* Show a console warning, but only if it hasn't already been shown
|
|
100
98
|
*
|
|
101
99
|
* @param {string} message
|
|
102
100
|
*/
|
|
103
|
-
|
|
104
101
|
const warnOnce = message => {
|
|
105
102
|
if (!previousWarnOnceMessages.includes(message)) {
|
|
106
103
|
previousWarnOnceMessages.push(message);
|
|
107
104
|
warn(message);
|
|
108
105
|
}
|
|
109
106
|
};
|
|
107
|
+
|
|
110
108
|
/**
|
|
111
109
|
* Show a one-time console warning about deprecated params/methods
|
|
112
110
|
*
|
|
113
111
|
* @param {string} deprecatedParam
|
|
114
112
|
* @param {string} useInstead
|
|
115
113
|
*/
|
|
116
|
-
|
|
117
114
|
const warnAboutDeprecation = (deprecatedParam, useInstead) => {
|
|
118
115
|
warnOnce("\"".concat(deprecatedParam, "\" is deprecated and will be removed in the next major release. Please use \"").concat(useInstead, "\" instead."));
|
|
119
116
|
};
|
|
117
|
+
|
|
120
118
|
/**
|
|
121
119
|
* If `arg` is a function, call it (with no arguments or context) and return the result.
|
|
122
120
|
* Otherwise, just pass the value through
|
|
@@ -124,25 +122,24 @@
|
|
|
124
122
|
* @param {Function | any} arg
|
|
125
123
|
* @returns {any}
|
|
126
124
|
*/
|
|
127
|
-
|
|
128
125
|
const callIfFunction = arg => typeof arg === 'function' ? arg() : arg;
|
|
126
|
+
|
|
129
127
|
/**
|
|
130
128
|
* @param {any} arg
|
|
131
129
|
* @returns {boolean}
|
|
132
130
|
*/
|
|
133
|
-
|
|
134
131
|
const hasToPromiseFn = arg => arg && typeof arg.toPromise === 'function';
|
|
132
|
+
|
|
135
133
|
/**
|
|
136
134
|
* @param {any} arg
|
|
137
135
|
* @returns {Promise}
|
|
138
136
|
*/
|
|
139
|
-
|
|
140
137
|
const asPromise = arg => hasToPromiseFn(arg) ? arg.toPromise() : Promise.resolve(arg);
|
|
138
|
+
|
|
141
139
|
/**
|
|
142
140
|
* @param {any} arg
|
|
143
141
|
* @returns {boolean}
|
|
144
142
|
*/
|
|
145
|
-
|
|
146
143
|
const isPromise = arg => arg && Promise.resolve(arg) === arg;
|
|
147
144
|
|
|
148
145
|
/**
|
|
@@ -150,154 +147,153 @@
|
|
|
150
147
|
*
|
|
151
148
|
* @returns {HTMLElement | null}
|
|
152
149
|
*/
|
|
153
|
-
|
|
154
150
|
const getContainer = () => document.body.querySelector(".".concat(swalClasses.container));
|
|
151
|
+
|
|
155
152
|
/**
|
|
156
153
|
* @param {string} selectorString
|
|
157
154
|
* @returns {HTMLElement | null}
|
|
158
155
|
*/
|
|
159
|
-
|
|
160
156
|
const elementBySelector = selectorString => {
|
|
161
157
|
const container = getContainer();
|
|
162
158
|
return container ? container.querySelector(selectorString) : null;
|
|
163
159
|
};
|
|
160
|
+
|
|
164
161
|
/**
|
|
165
162
|
* @param {string} className
|
|
166
163
|
* @returns {HTMLElement | null}
|
|
167
164
|
*/
|
|
168
|
-
|
|
169
165
|
const elementByClass = className => {
|
|
170
166
|
return elementBySelector(".".concat(className));
|
|
171
167
|
};
|
|
168
|
+
|
|
172
169
|
/**
|
|
173
170
|
* @returns {HTMLElement | null}
|
|
174
171
|
*/
|
|
175
|
-
|
|
176
|
-
|
|
177
172
|
const getPopup = () => elementByClass(swalClasses.popup);
|
|
173
|
+
|
|
178
174
|
/**
|
|
179
175
|
* @returns {HTMLElement | null}
|
|
180
176
|
*/
|
|
181
|
-
|
|
182
177
|
const getIcon = () => elementByClass(swalClasses.icon);
|
|
178
|
+
|
|
183
179
|
/**
|
|
184
180
|
* @returns {HTMLElement | null}
|
|
185
181
|
*/
|
|
186
|
-
|
|
187
182
|
const getTitle = () => elementByClass(swalClasses.title);
|
|
183
|
+
|
|
188
184
|
/**
|
|
189
185
|
* @returns {HTMLElement | null}
|
|
190
186
|
*/
|
|
191
|
-
|
|
192
187
|
const getHtmlContainer = () => elementByClass(swalClasses['html-container']);
|
|
188
|
+
|
|
193
189
|
/**
|
|
194
190
|
* @returns {HTMLElement | null}
|
|
195
191
|
*/
|
|
196
|
-
|
|
197
192
|
const getImage = () => elementByClass(swalClasses.image);
|
|
193
|
+
|
|
198
194
|
/**
|
|
199
195
|
* @returns {HTMLElement | null}
|
|
200
196
|
*/
|
|
201
|
-
|
|
202
197
|
const getProgressSteps = () => elementByClass(swalClasses['progress-steps']);
|
|
198
|
+
|
|
203
199
|
/**
|
|
204
200
|
* @returns {HTMLElement | null}
|
|
205
201
|
*/
|
|
206
|
-
|
|
207
202
|
const getValidationMessage = () => elementByClass(swalClasses['validation-message']);
|
|
203
|
+
|
|
208
204
|
/**
|
|
209
205
|
* @returns {HTMLElement | null}
|
|
210
206
|
*/
|
|
211
|
-
|
|
212
207
|
const getConfirmButton = () => elementBySelector(".".concat(swalClasses.actions, " .").concat(swalClasses.confirm));
|
|
208
|
+
|
|
213
209
|
/**
|
|
214
210
|
* @returns {HTMLElement | null}
|
|
215
211
|
*/
|
|
216
|
-
|
|
217
212
|
const getDenyButton = () => elementBySelector(".".concat(swalClasses.actions, " .").concat(swalClasses.deny));
|
|
213
|
+
|
|
218
214
|
/**
|
|
219
215
|
* @returns {HTMLElement | null}
|
|
220
216
|
*/
|
|
221
|
-
|
|
222
217
|
const getInputLabel = () => elementByClass(swalClasses['input-label']);
|
|
218
|
+
|
|
223
219
|
/**
|
|
224
220
|
* @returns {HTMLElement | null}
|
|
225
221
|
*/
|
|
226
|
-
|
|
227
222
|
const getLoader = () => elementBySelector(".".concat(swalClasses.loader));
|
|
223
|
+
|
|
228
224
|
/**
|
|
229
225
|
* @returns {HTMLElement | null}
|
|
230
226
|
*/
|
|
231
|
-
|
|
232
227
|
const getCancelButton = () => elementBySelector(".".concat(swalClasses.actions, " .").concat(swalClasses.cancel));
|
|
228
|
+
|
|
233
229
|
/**
|
|
234
230
|
* @returns {HTMLElement | null}
|
|
235
231
|
*/
|
|
236
|
-
|
|
237
232
|
const getActions = () => elementByClass(swalClasses.actions);
|
|
233
|
+
|
|
238
234
|
/**
|
|
239
235
|
* @returns {HTMLElement | null}
|
|
240
236
|
*/
|
|
241
|
-
|
|
242
237
|
const getFooter = () => elementByClass(swalClasses.footer);
|
|
238
|
+
|
|
243
239
|
/**
|
|
244
240
|
* @returns {HTMLElement | null}
|
|
245
241
|
*/
|
|
246
|
-
|
|
247
242
|
const getTimerProgressBar = () => elementByClass(swalClasses['timer-progress-bar']);
|
|
243
|
+
|
|
248
244
|
/**
|
|
249
245
|
* @returns {HTMLElement | null}
|
|
250
246
|
*/
|
|
247
|
+
const getCloseButton = () => elementByClass(swalClasses.close);
|
|
251
248
|
|
|
252
|
-
|
|
253
|
-
|
|
249
|
+
// https://github.com/jkup/focusable/blob/master/index.js
|
|
254
250
|
const focusable = "\n a[href],\n area[href],\n input:not([disabled]),\n select:not([disabled]),\n textarea:not([disabled]),\n button:not([disabled]),\n iframe,\n object,\n embed,\n [tabindex=\"0\"],\n [contenteditable],\n audio[controls],\n video[controls],\n summary\n";
|
|
255
251
|
/**
|
|
256
252
|
* @returns {HTMLElement[]}
|
|
257
253
|
*/
|
|
258
|
-
|
|
259
254
|
const getFocusableElements = () => {
|
|
260
|
-
const focusableElementsWithTabindex = Array.from(getPopup().querySelectorAll('[tabindex]:not([tabindex="-1"]):not([tabindex="0"])'))
|
|
255
|
+
const focusableElementsWithTabindex = Array.from(getPopup().querySelectorAll('[tabindex]:not([tabindex="-1"]):not([tabindex="0"])'))
|
|
256
|
+
// sort according to tabindex
|
|
261
257
|
.sort((a, b) => {
|
|
262
258
|
const tabindexA = parseInt(a.getAttribute('tabindex'));
|
|
263
259
|
const tabindexB = parseInt(b.getAttribute('tabindex'));
|
|
264
|
-
|
|
265
260
|
if (tabindexA > tabindexB) {
|
|
266
261
|
return 1;
|
|
267
262
|
} else if (tabindexA < tabindexB) {
|
|
268
263
|
return -1;
|
|
269
264
|
}
|
|
270
|
-
|
|
271
265
|
return 0;
|
|
272
266
|
});
|
|
273
267
|
const otherFocusableElements = Array.from(getPopup().querySelectorAll(focusable)).filter(el => el.getAttribute('tabindex') !== '-1');
|
|
274
268
|
return uniqueArray(focusableElementsWithTabindex.concat(otherFocusableElements)).filter(el => isVisible(el));
|
|
275
269
|
};
|
|
270
|
+
|
|
276
271
|
/**
|
|
277
272
|
* @returns {boolean}
|
|
278
273
|
*/
|
|
279
|
-
|
|
280
274
|
const isModal = () => {
|
|
281
275
|
return hasClass(document.body, swalClasses.shown) && !hasClass(document.body, swalClasses['toast-shown']) && !hasClass(document.body, swalClasses['no-backdrop']);
|
|
282
276
|
};
|
|
277
|
+
|
|
283
278
|
/**
|
|
284
279
|
* @returns {boolean}
|
|
285
280
|
*/
|
|
286
|
-
|
|
287
281
|
const isToast = () => {
|
|
288
282
|
return getPopup() && hasClass(getPopup(), swalClasses.toast);
|
|
289
283
|
};
|
|
284
|
+
|
|
290
285
|
/**
|
|
291
286
|
* @returns {boolean}
|
|
292
287
|
*/
|
|
293
|
-
|
|
294
288
|
const isLoading = () => {
|
|
295
289
|
return getPopup().hasAttribute('data-loading');
|
|
296
290
|
};
|
|
297
291
|
|
|
292
|
+
// Remember state in cases where opening and handling a modal will fiddle with it.
|
|
298
293
|
const states = {
|
|
299
294
|
previousBodyPadding: null
|
|
300
295
|
};
|
|
296
|
+
|
|
301
297
|
/**
|
|
302
298
|
* Securely set innerHTML of an element
|
|
303
299
|
* https://github.com/sweetalert2/sweetalert2/issues/1926
|
|
@@ -305,10 +301,8 @@
|
|
|
305
301
|
* @param {HTMLElement} elem
|
|
306
302
|
* @param {string} html
|
|
307
303
|
*/
|
|
308
|
-
|
|
309
304
|
const setInnerHtml = (elem, html) => {
|
|
310
305
|
elem.textContent = '';
|
|
311
|
-
|
|
312
306
|
if (html) {
|
|
313
307
|
const parser = new DOMParser();
|
|
314
308
|
const parsed = parser.parseFromString(html, "text/html");
|
|
@@ -324,32 +318,29 @@
|
|
|
324
318
|
});
|
|
325
319
|
}
|
|
326
320
|
};
|
|
321
|
+
|
|
327
322
|
/**
|
|
328
323
|
* @param {HTMLElement} elem
|
|
329
324
|
* @param {string} className
|
|
330
325
|
* @returns {boolean}
|
|
331
326
|
*/
|
|
332
|
-
|
|
333
327
|
const hasClass = (elem, className) => {
|
|
334
328
|
if (!className) {
|
|
335
329
|
return false;
|
|
336
330
|
}
|
|
337
|
-
|
|
338
331
|
const classList = className.split(/\s+/);
|
|
339
|
-
|
|
340
332
|
for (let i = 0; i < classList.length; i++) {
|
|
341
333
|
if (!elem.classList.contains(classList[i])) {
|
|
342
334
|
return false;
|
|
343
335
|
}
|
|
344
336
|
}
|
|
345
|
-
|
|
346
337
|
return true;
|
|
347
338
|
};
|
|
339
|
+
|
|
348
340
|
/**
|
|
349
341
|
* @param {HTMLElement} elem
|
|
350
342
|
* @param {SweetAlertOptions} params
|
|
351
343
|
*/
|
|
352
|
-
|
|
353
344
|
const removeCustomClasses = (elem, params) => {
|
|
354
345
|
Array.from(elem.classList).forEach(className => {
|
|
355
346
|
if (!Object.values(swalClasses).includes(className) && !Object.values(iconTypes).includes(className) && !Object.values(params.showClass).includes(className)) {
|
|
@@ -357,61 +348,55 @@
|
|
|
357
348
|
}
|
|
358
349
|
});
|
|
359
350
|
};
|
|
351
|
+
|
|
360
352
|
/**
|
|
361
353
|
* @param {HTMLElement} elem
|
|
362
354
|
* @param {SweetAlertOptions} params
|
|
363
355
|
* @param {string} className
|
|
364
356
|
*/
|
|
365
|
-
|
|
366
|
-
|
|
367
357
|
const applyCustomClass = (elem, params, className) => {
|
|
368
358
|
removeCustomClasses(elem, params);
|
|
369
|
-
|
|
370
359
|
if (params.customClass && params.customClass[className]) {
|
|
371
360
|
if (typeof params.customClass[className] !== 'string' && !params.customClass[className].forEach) {
|
|
372
|
-
|
|
361
|
+
warn("Invalid type of customClass.".concat(className, "! Expected string or iterable object, got \"").concat(typeof params.customClass[className], "\""));
|
|
362
|
+
return;
|
|
373
363
|
}
|
|
374
|
-
|
|
375
364
|
addClass(elem, params.customClass[className]);
|
|
376
365
|
}
|
|
377
366
|
};
|
|
367
|
+
|
|
378
368
|
/**
|
|
379
369
|
* @param {HTMLElement} popup
|
|
380
370
|
* @param {import('./renderers/renderInput').InputClass} inputClass
|
|
381
371
|
* @returns {HTMLInputElement | null}
|
|
382
372
|
*/
|
|
383
|
-
|
|
384
373
|
const getInput = (popup, inputClass) => {
|
|
385
374
|
if (!inputClass) {
|
|
386
375
|
return null;
|
|
387
376
|
}
|
|
388
|
-
|
|
389
377
|
switch (inputClass) {
|
|
390
378
|
case 'select':
|
|
391
379
|
case 'textarea':
|
|
392
380
|
case 'file':
|
|
393
381
|
return popup.querySelector(".".concat(swalClasses.popup, " > .").concat(swalClasses[inputClass]));
|
|
394
|
-
|
|
395
382
|
case 'checkbox':
|
|
396
383
|
return popup.querySelector(".".concat(swalClasses.popup, " > .").concat(swalClasses.checkbox, " input"));
|
|
397
|
-
|
|
398
384
|
case 'radio':
|
|
399
385
|
return popup.querySelector(".".concat(swalClasses.popup, " > .").concat(swalClasses.radio, " input:checked")) || popup.querySelector(".".concat(swalClasses.popup, " > .").concat(swalClasses.radio, " input:first-child"));
|
|
400
|
-
|
|
401
386
|
case 'range':
|
|
402
387
|
return popup.querySelector(".".concat(swalClasses.popup, " > .").concat(swalClasses.range, " input"));
|
|
403
|
-
|
|
404
388
|
default:
|
|
405
389
|
return popup.querySelector(".".concat(swalClasses.popup, " > .").concat(swalClasses.input));
|
|
406
390
|
}
|
|
407
391
|
};
|
|
392
|
+
|
|
408
393
|
/**
|
|
409
394
|
* @param {HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement} input
|
|
410
395
|
*/
|
|
411
|
-
|
|
412
396
|
const focusInput = input => {
|
|
413
|
-
input.focus();
|
|
397
|
+
input.focus();
|
|
414
398
|
|
|
399
|
+
// place cursor at end of text in text input
|
|
415
400
|
if (input.type !== 'file') {
|
|
416
401
|
// http://stackoverflow.com/a/2345915
|
|
417
402
|
const val = input.value;
|
|
@@ -419,21 +404,19 @@
|
|
|
419
404
|
input.value = val;
|
|
420
405
|
}
|
|
421
406
|
};
|
|
407
|
+
|
|
422
408
|
/**
|
|
423
409
|
* @param {HTMLElement | HTMLElement[] | null} target
|
|
424
410
|
* @param {string | string[] | readonly string[]} classList
|
|
425
411
|
* @param {boolean} condition
|
|
426
412
|
*/
|
|
427
|
-
|
|
428
413
|
const toggleClass = (target, classList, condition) => {
|
|
429
414
|
if (!target || !classList) {
|
|
430
415
|
return;
|
|
431
416
|
}
|
|
432
|
-
|
|
433
417
|
if (typeof classList === 'string') {
|
|
434
418
|
classList = classList.split(/\s+/).filter(Boolean);
|
|
435
419
|
}
|
|
436
|
-
|
|
437
420
|
classList.forEach(className => {
|
|
438
421
|
if (Array.isArray(target)) {
|
|
439
422
|
target.forEach(elem => {
|
|
@@ -444,22 +427,23 @@
|
|
|
444
427
|
}
|
|
445
428
|
});
|
|
446
429
|
};
|
|
430
|
+
|
|
447
431
|
/**
|
|
448
432
|
* @param {HTMLElement | HTMLElement[] | null} target
|
|
449
433
|
* @param {string | string[] | readonly string[]} classList
|
|
450
434
|
*/
|
|
451
|
-
|
|
452
435
|
const addClass = (target, classList) => {
|
|
453
436
|
toggleClass(target, classList, true);
|
|
454
437
|
};
|
|
438
|
+
|
|
455
439
|
/**
|
|
456
440
|
* @param {HTMLElement | HTMLElement[] | null} target
|
|
457
441
|
* @param {string | string[] | readonly string[]} classList
|
|
458
442
|
*/
|
|
459
|
-
|
|
460
443
|
const removeClass = (target, classList) => {
|
|
461
444
|
toggleClass(target, classList, false);
|
|
462
445
|
};
|
|
446
|
+
|
|
463
447
|
/**
|
|
464
448
|
* Get direct child of an element by class name
|
|
465
449
|
*
|
|
@@ -467,122 +451,116 @@
|
|
|
467
451
|
* @param {string} className
|
|
468
452
|
* @returns {HTMLElement | null}
|
|
469
453
|
*/
|
|
470
|
-
|
|
471
454
|
const getDirectChildByClass = (elem, className) => {
|
|
472
455
|
const children = Array.from(elem.children);
|
|
473
|
-
|
|
474
456
|
for (let i = 0; i < children.length; i++) {
|
|
475
457
|
const child = children[i];
|
|
476
|
-
|
|
477
458
|
if (child instanceof HTMLElement && hasClass(child, className)) {
|
|
478
459
|
return child;
|
|
479
460
|
}
|
|
480
461
|
}
|
|
481
462
|
};
|
|
463
|
+
|
|
482
464
|
/**
|
|
483
465
|
* @param {HTMLElement} elem
|
|
484
466
|
* @param {string} property
|
|
485
467
|
* @param {*} value
|
|
486
468
|
*/
|
|
487
|
-
|
|
488
469
|
const applyNumericalStyle = (elem, property, value) => {
|
|
489
470
|
if (value === "".concat(parseInt(value))) {
|
|
490
471
|
value = parseInt(value);
|
|
491
472
|
}
|
|
492
|
-
|
|
493
473
|
if (value || parseInt(value) === 0) {
|
|
494
474
|
elem.style[property] = typeof value === 'number' ? "".concat(value, "px") : value;
|
|
495
475
|
} else {
|
|
496
476
|
elem.style.removeProperty(property);
|
|
497
477
|
}
|
|
498
478
|
};
|
|
479
|
+
|
|
499
480
|
/**
|
|
500
481
|
* @param {HTMLElement} elem
|
|
501
482
|
* @param {string} display
|
|
502
483
|
*/
|
|
503
|
-
|
|
504
484
|
const show = function (elem) {
|
|
505
485
|
let display = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'flex';
|
|
506
486
|
elem.style.display = display;
|
|
507
487
|
};
|
|
488
|
+
|
|
508
489
|
/**
|
|
509
490
|
* @param {HTMLElement} elem
|
|
510
491
|
*/
|
|
511
|
-
|
|
512
492
|
const hide = elem => {
|
|
513
493
|
elem.style.display = 'none';
|
|
514
494
|
};
|
|
495
|
+
|
|
515
496
|
/**
|
|
516
497
|
* @param {HTMLElement} parent
|
|
517
498
|
* @param {string} selector
|
|
518
499
|
* @param {string} property
|
|
519
500
|
* @param {string} value
|
|
520
501
|
*/
|
|
521
|
-
|
|
522
502
|
const setStyle = (parent, selector, property, value) => {
|
|
523
503
|
/** @type {HTMLElement} */
|
|
524
504
|
const el = parent.querySelector(selector);
|
|
525
|
-
|
|
526
505
|
if (el) {
|
|
527
506
|
el.style[property] = value;
|
|
528
507
|
}
|
|
529
508
|
};
|
|
509
|
+
|
|
530
510
|
/**
|
|
531
511
|
* @param {HTMLElement} elem
|
|
532
512
|
* @param {any} condition
|
|
533
513
|
* @param {string} display
|
|
534
514
|
*/
|
|
535
|
-
|
|
536
515
|
const toggle = function (elem, condition) {
|
|
537
516
|
let display = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'flex';
|
|
538
517
|
condition ? show(elem, display) : hide(elem);
|
|
539
518
|
};
|
|
519
|
+
|
|
540
520
|
/**
|
|
541
521
|
* borrowed from jquery $(elem).is(':visible') implementation
|
|
542
522
|
*
|
|
543
523
|
* @param {HTMLElement} elem
|
|
544
524
|
* @returns {boolean}
|
|
545
525
|
*/
|
|
546
|
-
|
|
547
526
|
const isVisible = elem => !!(elem && (elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length));
|
|
527
|
+
|
|
548
528
|
/**
|
|
549
529
|
* @returns {boolean}
|
|
550
530
|
*/
|
|
551
|
-
|
|
552
531
|
const allButtonsAreHidden = () => !isVisible(getConfirmButton()) && !isVisible(getDenyButton()) && !isVisible(getCancelButton());
|
|
532
|
+
|
|
553
533
|
/**
|
|
534
|
+
* @param {HTMLElement} elem
|
|
554
535
|
* @returns {boolean}
|
|
555
536
|
*/
|
|
556
|
-
|
|
557
537
|
const isScrollable = elem => !!(elem.scrollHeight > elem.clientHeight);
|
|
538
|
+
|
|
558
539
|
/**
|
|
559
540
|
* borrowed from https://stackoverflow.com/a/46352119
|
|
560
541
|
*
|
|
561
542
|
* @param {HTMLElement} elem
|
|
562
543
|
* @returns {boolean}
|
|
563
544
|
*/
|
|
564
|
-
|
|
565
545
|
const hasCssAnimation = elem => {
|
|
566
546
|
const style = window.getComputedStyle(elem);
|
|
567
547
|
const animDuration = parseFloat(style.getPropertyValue('animation-duration') || '0');
|
|
568
548
|
const transDuration = parseFloat(style.getPropertyValue('transition-duration') || '0');
|
|
569
549
|
return animDuration > 0 || transDuration > 0;
|
|
570
550
|
};
|
|
551
|
+
|
|
571
552
|
/**
|
|
572
553
|
* @param {number} timer
|
|
573
554
|
* @param {boolean} reset
|
|
574
555
|
*/
|
|
575
|
-
|
|
576
556
|
const animateTimerProgressBar = function (timer) {
|
|
577
557
|
let reset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
578
558
|
const timerProgressBar = getTimerProgressBar();
|
|
579
|
-
|
|
580
559
|
if (isVisible(timerProgressBar)) {
|
|
581
560
|
if (reset) {
|
|
582
561
|
timerProgressBar.style.transition = 'none';
|
|
583
562
|
timerProgressBar.style.width = '100%';
|
|
584
563
|
}
|
|
585
|
-
|
|
586
564
|
setTimeout(() => {
|
|
587
565
|
timerProgressBar.style.transition = "width ".concat(timer / 1000, "s linear");
|
|
588
566
|
timerProgressBar.style.width = '0%';
|
|
@@ -603,9 +581,7 @@
|
|
|
603
581
|
const RESTORE_FOCUS_TIMEOUT = 100;
|
|
604
582
|
|
|
605
583
|
/** @type {GlobalState} */
|
|
606
|
-
|
|
607
584
|
const globalState = {};
|
|
608
|
-
|
|
609
585
|
const focusPreviousActiveElement = () => {
|
|
610
586
|
if (globalState.previousActiveElement instanceof HTMLElement) {
|
|
611
587
|
globalState.previousActiveElement.focus();
|
|
@@ -614,20 +590,18 @@
|
|
|
614
590
|
document.body.focus();
|
|
615
591
|
}
|
|
616
592
|
};
|
|
593
|
+
|
|
617
594
|
/**
|
|
618
595
|
* Restore previous active (focused) element
|
|
619
596
|
*
|
|
620
597
|
* @param {boolean} returnFocus
|
|
621
598
|
* @returns {Promise}
|
|
622
599
|
*/
|
|
623
|
-
|
|
624
|
-
|
|
625
600
|
const restoreActiveElement = returnFocus => {
|
|
626
601
|
return new Promise(resolve => {
|
|
627
602
|
if (!returnFocus) {
|
|
628
603
|
return resolve();
|
|
629
604
|
}
|
|
630
|
-
|
|
631
605
|
const x = window.scrollX;
|
|
632
606
|
const y = window.scrollY;
|
|
633
607
|
globalState.restoreFocusTimeout = setTimeout(() => {
|
|
@@ -647,39 +621,32 @@
|
|
|
647
621
|
const isNodeEnv = () => typeof window === 'undefined' || typeof document === 'undefined';
|
|
648
622
|
|
|
649
623
|
const sweetHTML = "\n <div aria-labelledby=\"".concat(swalClasses.title, "\" aria-describedby=\"").concat(swalClasses['html-container'], "\" class=\"").concat(swalClasses.popup, "\" tabindex=\"-1\">\n <button type=\"button\" class=\"").concat(swalClasses.close, "\"></button>\n <ul class=\"").concat(swalClasses['progress-steps'], "\"></ul>\n <div class=\"").concat(swalClasses.icon, "\"></div>\n <img class=\"").concat(swalClasses.image, "\" />\n <h2 class=\"").concat(swalClasses.title, "\" id=\"").concat(swalClasses.title, "\"></h2>\n <div class=\"").concat(swalClasses['html-container'], "\" id=\"").concat(swalClasses['html-container'], "\"></div>\n <input class=\"").concat(swalClasses.input, "\" />\n <input type=\"file\" class=\"").concat(swalClasses.file, "\" />\n <div class=\"").concat(swalClasses.range, "\">\n <input type=\"range\" />\n <output></output>\n </div>\n <select class=\"").concat(swalClasses.select, "\"></select>\n <div class=\"").concat(swalClasses.radio, "\"></div>\n <label for=\"").concat(swalClasses.checkbox, "\" class=\"").concat(swalClasses.checkbox, "\">\n <input type=\"checkbox\" />\n <span class=\"").concat(swalClasses.label, "\"></span>\n </label>\n <textarea class=\"").concat(swalClasses.textarea, "\"></textarea>\n <div class=\"").concat(swalClasses['validation-message'], "\" id=\"").concat(swalClasses['validation-message'], "\"></div>\n <div class=\"").concat(swalClasses.actions, "\">\n <div class=\"").concat(swalClasses.loader, "\"></div>\n <button type=\"button\" class=\"").concat(swalClasses.confirm, "\"></button>\n <button type=\"button\" class=\"").concat(swalClasses.deny, "\"></button>\n <button type=\"button\" class=\"").concat(swalClasses.cancel, "\"></button>\n </div>\n <div class=\"").concat(swalClasses.footer, "\"></div>\n <div class=\"").concat(swalClasses['timer-progress-bar-container'], "\">\n <div class=\"").concat(swalClasses['timer-progress-bar'], "\"></div>\n </div>\n </div>\n").replace(/(^|\n)\s*/g, '');
|
|
624
|
+
|
|
650
625
|
/**
|
|
651
626
|
* @returns {boolean}
|
|
652
627
|
*/
|
|
653
|
-
|
|
654
628
|
const resetOldContainer = () => {
|
|
655
629
|
const oldContainer = getContainer();
|
|
656
|
-
|
|
657
630
|
if (!oldContainer) {
|
|
658
631
|
return false;
|
|
659
632
|
}
|
|
660
|
-
|
|
661
633
|
oldContainer.remove();
|
|
662
634
|
removeClass([document.documentElement, document.body], [swalClasses['no-backdrop'], swalClasses['toast-shown'], swalClasses['has-column']]);
|
|
663
635
|
return true;
|
|
664
636
|
};
|
|
665
|
-
|
|
666
637
|
const resetValidationMessage = () => {
|
|
667
638
|
globalState.currentInstance.resetValidationMessage();
|
|
668
639
|
};
|
|
669
|
-
|
|
670
640
|
const addInputChangeListeners = () => {
|
|
671
641
|
const popup = getPopup();
|
|
672
642
|
const input = getDirectChildByClass(popup, swalClasses.input);
|
|
673
643
|
const file = getDirectChildByClass(popup, swalClasses.file);
|
|
674
644
|
/** @type {HTMLInputElement} */
|
|
675
|
-
|
|
676
645
|
const range = popup.querySelector(".".concat(swalClasses.range, " input"));
|
|
677
646
|
/** @type {HTMLOutputElement} */
|
|
678
|
-
|
|
679
647
|
const rangeOutput = popup.querySelector(".".concat(swalClasses.range, " output"));
|
|
680
648
|
const select = getDirectChildByClass(popup, swalClasses.select);
|
|
681
649
|
/** @type {HTMLInputElement} */
|
|
682
|
-
|
|
683
650
|
const checkbox = popup.querySelector(".".concat(swalClasses.checkbox, " input"));
|
|
684
651
|
const textarea = getDirectChildByClass(popup, swalClasses.textarea);
|
|
685
652
|
input.oninput = resetValidationMessage;
|
|
@@ -687,72 +654,62 @@
|
|
|
687
654
|
select.onchange = resetValidationMessage;
|
|
688
655
|
checkbox.onchange = resetValidationMessage;
|
|
689
656
|
textarea.oninput = resetValidationMessage;
|
|
690
|
-
|
|
691
657
|
range.oninput = () => {
|
|
692
658
|
resetValidationMessage();
|
|
693
659
|
rangeOutput.value = range.value;
|
|
694
660
|
};
|
|
695
|
-
|
|
696
661
|
range.onchange = () => {
|
|
697
662
|
resetValidationMessage();
|
|
698
663
|
rangeOutput.value = range.value;
|
|
699
664
|
};
|
|
700
665
|
};
|
|
666
|
+
|
|
701
667
|
/**
|
|
702
668
|
* @param {string | HTMLElement} target
|
|
703
669
|
* @returns {HTMLElement}
|
|
704
670
|
*/
|
|
705
|
-
|
|
706
|
-
|
|
707
671
|
const getTarget = target => typeof target === 'string' ? document.querySelector(target) : target;
|
|
672
|
+
|
|
708
673
|
/**
|
|
709
674
|
* @param {SweetAlertOptions} params
|
|
710
675
|
*/
|
|
711
|
-
|
|
712
|
-
|
|
713
676
|
const setupAccessibility = params => {
|
|
714
677
|
const popup = getPopup();
|
|
715
678
|
popup.setAttribute('role', params.toast ? 'alert' : 'dialog');
|
|
716
679
|
popup.setAttribute('aria-live', params.toast ? 'polite' : 'assertive');
|
|
717
|
-
|
|
718
680
|
if (!params.toast) {
|
|
719
681
|
popup.setAttribute('aria-modal', 'true');
|
|
720
682
|
}
|
|
721
683
|
};
|
|
684
|
+
|
|
722
685
|
/**
|
|
723
686
|
* @param {HTMLElement} targetElement
|
|
724
687
|
*/
|
|
725
|
-
|
|
726
|
-
|
|
727
688
|
const setupRTL = targetElement => {
|
|
728
689
|
if (window.getComputedStyle(targetElement).direction === 'rtl') {
|
|
729
690
|
addClass(getContainer(), swalClasses.rtl);
|
|
730
691
|
}
|
|
731
692
|
};
|
|
693
|
+
|
|
732
694
|
/**
|
|
733
695
|
* Add modal + backdrop + no-war message for Russians to DOM
|
|
734
696
|
*
|
|
735
697
|
* @param {SweetAlertOptions} params
|
|
736
698
|
*/
|
|
737
|
-
|
|
738
|
-
|
|
739
699
|
const init = params => {
|
|
740
700
|
// Clean up the old popup container if it exists
|
|
741
701
|
const oldContainerExisted = resetOldContainer();
|
|
742
|
-
/* istanbul ignore if */
|
|
743
702
|
|
|
703
|
+
/* istanbul ignore if */
|
|
744
704
|
if (isNodeEnv()) {
|
|
745
705
|
error('SweetAlert2 requires document to initialize');
|
|
746
706
|
return;
|
|
747
707
|
}
|
|
748
|
-
|
|
749
708
|
const container = document.createElement('div');
|
|
750
709
|
container.className = swalClasses.container;
|
|
751
|
-
|
|
752
710
|
if (oldContainerExisted) {
|
|
753
711
|
addClass(container, swalClasses['no-transition']);
|
|
754
712
|
}
|
|
755
|
-
|
|
756
713
|
setInnerHtml(container, sweetHTML);
|
|
757
714
|
const targetElement = getTarget(params.target);
|
|
758
715
|
targetElement.appendChild(container);
|
|
@@ -765,42 +722,45 @@
|
|
|
765
722
|
* @param {HTMLElement | object | string} param
|
|
766
723
|
* @param {HTMLElement} target
|
|
767
724
|
*/
|
|
768
|
-
|
|
769
725
|
const parseHtmlToContainer = (param, target) => {
|
|
770
726
|
// DOM element
|
|
771
727
|
if (param instanceof HTMLElement) {
|
|
772
728
|
target.appendChild(param);
|
|
773
|
-
}
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
// Object
|
|
774
732
|
else if (typeof param === 'object') {
|
|
775
733
|
handleObject(param, target);
|
|
776
|
-
}
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
// Plain string
|
|
777
737
|
else if (param) {
|
|
778
738
|
setInnerHtml(target, param);
|
|
779
739
|
}
|
|
780
740
|
};
|
|
741
|
+
|
|
781
742
|
/**
|
|
782
743
|
* @param {object} param
|
|
783
744
|
* @param {HTMLElement} target
|
|
784
745
|
*/
|
|
785
|
-
|
|
786
746
|
const handleObject = (param, target) => {
|
|
787
747
|
// JQuery element(s)
|
|
788
748
|
if (param.jquery) {
|
|
789
749
|
handleJqueryElem(target, param);
|
|
790
|
-
}
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
// For other objects use their string representation
|
|
791
753
|
else {
|
|
792
754
|
setInnerHtml(target, param.toString());
|
|
793
755
|
}
|
|
794
756
|
};
|
|
757
|
+
|
|
795
758
|
/**
|
|
796
759
|
* @param {HTMLElement} target
|
|
797
760
|
* @param {HTMLElement} elem
|
|
798
761
|
*/
|
|
799
|
-
|
|
800
|
-
|
|
801
762
|
const handleJqueryElem = (target, elem) => {
|
|
802
763
|
target.textContent = '';
|
|
803
|
-
|
|
804
764
|
if (0 in elem) {
|
|
805
765
|
for (let i = 0; (i in elem); i++) {
|
|
806
766
|
target.appendChild(elem[i].cloneNode(true));
|
|
@@ -813,21 +773,17 @@
|
|
|
813
773
|
/**
|
|
814
774
|
* @returns {'webkitAnimationEnd' | 'animationend' | false}
|
|
815
775
|
*/
|
|
816
|
-
|
|
817
776
|
const animationEndEvent = (() => {
|
|
818
777
|
// Prevent run in Node env
|
|
819
|
-
|
|
820
778
|
/* istanbul ignore if */
|
|
821
779
|
if (isNodeEnv()) {
|
|
822
780
|
return false;
|
|
823
781
|
}
|
|
824
|
-
|
|
825
782
|
const testEl = document.createElement('div');
|
|
826
783
|
const transEndEventNames = {
|
|
827
784
|
WebkitAnimation: 'webkitAnimationEnd',
|
|
828
785
|
// Chrome, Safari and Opera
|
|
829
786
|
animation: 'animationend' // Standard syntax
|
|
830
|
-
|
|
831
787
|
};
|
|
832
788
|
|
|
833
789
|
for (const i in transEndEventNames) {
|
|
@@ -835,7 +791,6 @@
|
|
|
835
791
|
return transEndEventNames[i];
|
|
836
792
|
}
|
|
837
793
|
}
|
|
838
|
-
|
|
839
794
|
return false;
|
|
840
795
|
})();
|
|
841
796
|
|
|
@@ -845,7 +800,6 @@
|
|
|
845
800
|
*
|
|
846
801
|
* @returns {number}
|
|
847
802
|
*/
|
|
848
|
-
|
|
849
803
|
const measureScrollbar = () => {
|
|
850
804
|
const scrollDiv = document.createElement('div');
|
|
851
805
|
scrollDiv.className = swalClasses['scrollbar-measure'];
|
|
@@ -859,41 +813,43 @@
|
|
|
859
813
|
* @param {SweetAlert2} instance
|
|
860
814
|
* @param {SweetAlertOptions} params
|
|
861
815
|
*/
|
|
862
|
-
|
|
863
816
|
const renderActions = (instance, params) => {
|
|
864
817
|
const actions = getActions();
|
|
865
|
-
const loader = getLoader();
|
|
818
|
+
const loader = getLoader();
|
|
866
819
|
|
|
820
|
+
// Actions (buttons) wrapper
|
|
867
821
|
if (!params.showConfirmButton && !params.showDenyButton && !params.showCancelButton) {
|
|
868
822
|
hide(actions);
|
|
869
823
|
} else {
|
|
870
824
|
show(actions);
|
|
871
|
-
}
|
|
872
|
-
|
|
825
|
+
}
|
|
873
826
|
|
|
874
|
-
|
|
827
|
+
// Custom class
|
|
828
|
+
applyCustomClass(actions, params, 'actions');
|
|
875
829
|
|
|
876
|
-
|
|
830
|
+
// Render all the buttons
|
|
831
|
+
renderButtons(actions, loader, params);
|
|
877
832
|
|
|
833
|
+
// Loader
|
|
878
834
|
setInnerHtml(loader, params.loaderHtml);
|
|
879
835
|
applyCustomClass(loader, params, 'loader');
|
|
880
836
|
};
|
|
837
|
+
|
|
881
838
|
/**
|
|
882
839
|
* @param {HTMLElement} actions
|
|
883
840
|
* @param {HTMLElement} loader
|
|
884
841
|
* @param {SweetAlertOptions} params
|
|
885
842
|
*/
|
|
886
|
-
|
|
887
843
|
function renderButtons(actions, loader, params) {
|
|
888
844
|
const confirmButton = getConfirmButton();
|
|
889
845
|
const denyButton = getDenyButton();
|
|
890
|
-
const cancelButton = getCancelButton();
|
|
846
|
+
const cancelButton = getCancelButton();
|
|
891
847
|
|
|
848
|
+
// Render buttons
|
|
892
849
|
renderButton(confirmButton, 'confirm', params);
|
|
893
850
|
renderButton(denyButton, 'deny', params);
|
|
894
851
|
renderButton(cancelButton, 'cancel', params);
|
|
895
852
|
handleButtonsStyling(confirmButton, denyButton, cancelButton, params);
|
|
896
|
-
|
|
897
853
|
if (params.reverseButtons) {
|
|
898
854
|
if (params.toast) {
|
|
899
855
|
actions.insertBefore(cancelButton, confirmButton);
|
|
@@ -905,51 +861,46 @@
|
|
|
905
861
|
}
|
|
906
862
|
}
|
|
907
863
|
}
|
|
864
|
+
|
|
908
865
|
/**
|
|
909
866
|
* @param {HTMLElement} confirmButton
|
|
910
867
|
* @param {HTMLElement} denyButton
|
|
911
868
|
* @param {HTMLElement} cancelButton
|
|
912
869
|
* @param {SweetAlertOptions} params
|
|
913
870
|
*/
|
|
914
|
-
|
|
915
|
-
|
|
916
871
|
function handleButtonsStyling(confirmButton, denyButton, cancelButton, params) {
|
|
917
872
|
if (!params.buttonsStyling) {
|
|
918
873
|
removeClass([confirmButton, denyButton, cancelButton], swalClasses.styled);
|
|
919
874
|
return;
|
|
920
875
|
}
|
|
876
|
+
addClass([confirmButton, denyButton, cancelButton], swalClasses.styled);
|
|
921
877
|
|
|
922
|
-
|
|
923
|
-
|
|
878
|
+
// Buttons background colors
|
|
924
879
|
if (params.confirmButtonColor) {
|
|
925
880
|
confirmButton.style.backgroundColor = params.confirmButtonColor;
|
|
926
881
|
addClass(confirmButton, swalClasses['default-outline']);
|
|
927
882
|
}
|
|
928
|
-
|
|
929
883
|
if (params.denyButtonColor) {
|
|
930
884
|
denyButton.style.backgroundColor = params.denyButtonColor;
|
|
931
885
|
addClass(denyButton, swalClasses['default-outline']);
|
|
932
886
|
}
|
|
933
|
-
|
|
934
887
|
if (params.cancelButtonColor) {
|
|
935
888
|
cancelButton.style.backgroundColor = params.cancelButtonColor;
|
|
936
889
|
addClass(cancelButton, swalClasses['default-outline']);
|
|
937
890
|
}
|
|
938
891
|
}
|
|
892
|
+
|
|
939
893
|
/**
|
|
940
894
|
* @param {HTMLElement} button
|
|
941
895
|
* @param {'confirm' | 'deny' | 'cancel'} buttonType
|
|
942
896
|
* @param {SweetAlertOptions} params
|
|
943
897
|
*/
|
|
944
|
-
|
|
945
|
-
|
|
946
898
|
function renderButton(button, buttonType, params) {
|
|
947
899
|
toggle(button, params["show".concat(capitalizeFirstLetter(buttonType), "Button")], 'inline-block');
|
|
948
900
|
setInnerHtml(button, params["".concat(buttonType, "ButtonText")]); // Set caption text
|
|
949
|
-
|
|
950
901
|
button.setAttribute('aria-label', params["".concat(buttonType, "ButtonAriaLabel")]); // ARIA label
|
|
951
|
-
// Add buttons custom classes
|
|
952
902
|
|
|
903
|
+
// Add buttons custom classes
|
|
953
904
|
button.className = swalClasses[buttonType];
|
|
954
905
|
applyCustomClass(button, params, "".concat(buttonType, "Button"));
|
|
955
906
|
addClass(button, params["".concat(buttonType, "ButtonClass")]);
|
|
@@ -959,11 +910,11 @@
|
|
|
959
910
|
* @param {SweetAlert2} instance
|
|
960
911
|
* @param {SweetAlertOptions} params
|
|
961
912
|
*/
|
|
962
|
-
|
|
963
913
|
const renderCloseButton = (instance, params) => {
|
|
964
914
|
const closeButton = getCloseButton();
|
|
965
|
-
setInnerHtml(closeButton, params.closeButtonHtml);
|
|
915
|
+
setInnerHtml(closeButton, params.closeButtonHtml);
|
|
966
916
|
|
|
917
|
+
// Custom class
|
|
967
918
|
applyCustomClass(closeButton, params, 'closeButton');
|
|
968
919
|
toggle(closeButton, params.showCloseButton);
|
|
969
920
|
closeButton.setAttribute('aria-label', params.closeButtonAriaLabel);
|
|
@@ -973,25 +924,23 @@
|
|
|
973
924
|
* @param {SweetAlert2} instance
|
|
974
925
|
* @param {SweetAlertOptions} params
|
|
975
926
|
*/
|
|
976
|
-
|
|
977
927
|
const renderContainer = (instance, params) => {
|
|
978
928
|
const container = getContainer();
|
|
979
|
-
|
|
980
929
|
if (!container) {
|
|
981
930
|
return;
|
|
982
931
|
}
|
|
983
|
-
|
|
984
932
|
handleBackdropParam(container, params.backdrop);
|
|
985
933
|
handlePositionParam(container, params.position);
|
|
986
|
-
handleGrowParam(container, params.grow);
|
|
934
|
+
handleGrowParam(container, params.grow);
|
|
987
935
|
|
|
936
|
+
// Custom class
|
|
988
937
|
applyCustomClass(container, params, 'container');
|
|
989
938
|
};
|
|
939
|
+
|
|
990
940
|
/**
|
|
991
941
|
* @param {HTMLElement} container
|
|
992
942
|
* @param {SweetAlertOptions['backdrop']} backdrop
|
|
993
943
|
*/
|
|
994
|
-
|
|
995
944
|
function handleBackdropParam(container, backdrop) {
|
|
996
945
|
if (typeof backdrop === 'string') {
|
|
997
946
|
container.style.background = backdrop;
|
|
@@ -999,12 +948,11 @@
|
|
|
999
948
|
addClass([document.documentElement, document.body], swalClasses['no-backdrop']);
|
|
1000
949
|
}
|
|
1001
950
|
}
|
|
951
|
+
|
|
1002
952
|
/**
|
|
1003
953
|
* @param {HTMLElement} container
|
|
1004
954
|
* @param {SweetAlertOptions['position']} position
|
|
1005
955
|
*/
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
956
|
function handlePositionParam(container, position) {
|
|
1009
957
|
if (position in swalClasses) {
|
|
1010
958
|
addClass(container, swalClasses[position]);
|
|
@@ -1013,16 +961,14 @@
|
|
|
1013
961
|
addClass(container, swalClasses.center);
|
|
1014
962
|
}
|
|
1015
963
|
}
|
|
964
|
+
|
|
1016
965
|
/**
|
|
1017
966
|
* @param {HTMLElement} container
|
|
1018
967
|
* @param {SweetAlertOptions['grow']} grow
|
|
1019
968
|
*/
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
969
|
function handleGrowParam(container, grow) {
|
|
1023
970
|
if (grow && typeof grow === 'string') {
|
|
1024
971
|
const growClass = "grow-".concat(grow);
|
|
1025
|
-
|
|
1026
972
|
if (growClass in swalClasses) {
|
|
1027
973
|
addClass(container, swalClasses[growClass]);
|
|
1028
974
|
}
|
|
@@ -1030,120 +976,109 @@
|
|
|
1030
976
|
}
|
|
1031
977
|
|
|
1032
978
|
/// <reference path="../../../../sweetalert2.d.ts"/>
|
|
1033
|
-
/** @type {InputClass[]} */
|
|
1034
979
|
|
|
980
|
+
/** @type {InputClass[]} */
|
|
1035
981
|
const inputClasses = ['input', 'file', 'range', 'select', 'radio', 'checkbox', 'textarea'];
|
|
982
|
+
|
|
1036
983
|
/**
|
|
1037
984
|
* @param {SweetAlert2} instance
|
|
1038
985
|
* @param {SweetAlertOptions} params
|
|
1039
986
|
*/
|
|
1040
|
-
|
|
1041
987
|
const renderInput = (instance, params) => {
|
|
1042
988
|
const popup = getPopup();
|
|
1043
989
|
const innerParams = privateProps.innerParams.get(instance);
|
|
1044
990
|
const rerender = !innerParams || params.input !== innerParams.input;
|
|
1045
991
|
inputClasses.forEach(inputClass => {
|
|
1046
|
-
const inputContainer = getDirectChildByClass(popup, swalClasses[inputClass]);
|
|
992
|
+
const inputContainer = getDirectChildByClass(popup, swalClasses[inputClass]);
|
|
1047
993
|
|
|
1048
|
-
|
|
994
|
+
// set attributes
|
|
995
|
+
setAttributes(inputClass, params.inputAttributes);
|
|
1049
996
|
|
|
997
|
+
// set class
|
|
1050
998
|
inputContainer.className = swalClasses[inputClass];
|
|
1051
|
-
|
|
1052
999
|
if (rerender) {
|
|
1053
1000
|
hide(inputContainer);
|
|
1054
1001
|
}
|
|
1055
1002
|
});
|
|
1056
|
-
|
|
1057
1003
|
if (params.input) {
|
|
1058
1004
|
if (rerender) {
|
|
1059
1005
|
showInput(params);
|
|
1060
|
-
}
|
|
1061
|
-
|
|
1062
|
-
|
|
1006
|
+
}
|
|
1007
|
+
// set custom class
|
|
1063
1008
|
setCustomClass(params);
|
|
1064
1009
|
}
|
|
1065
1010
|
};
|
|
1011
|
+
|
|
1066
1012
|
/**
|
|
1067
1013
|
* @param {SweetAlertOptions} params
|
|
1068
1014
|
*/
|
|
1069
|
-
|
|
1070
1015
|
const showInput = params => {
|
|
1071
1016
|
if (!renderInputType[params.input]) {
|
|
1072
1017
|
error("Unexpected type of input! Expected \"text\", \"email\", \"password\", \"number\", \"tel\", \"select\", \"radio\", \"checkbox\", \"textarea\", \"file\" or \"url\", got \"".concat(params.input, "\""));
|
|
1073
1018
|
return;
|
|
1074
1019
|
}
|
|
1075
|
-
|
|
1076
1020
|
const inputContainer = getInputContainer(params.input);
|
|
1077
1021
|
const input = renderInputType[params.input](inputContainer, params);
|
|
1078
|
-
show(inputContainer);
|
|
1022
|
+
show(inputContainer);
|
|
1079
1023
|
|
|
1024
|
+
// input autofocus
|
|
1080
1025
|
setTimeout(() => {
|
|
1081
1026
|
focusInput(input);
|
|
1082
1027
|
});
|
|
1083
1028
|
};
|
|
1029
|
+
|
|
1084
1030
|
/**
|
|
1085
1031
|
* @param {HTMLInputElement} input
|
|
1086
1032
|
*/
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
1033
|
const removeAttributes = input => {
|
|
1090
1034
|
for (let i = 0; i < input.attributes.length; i++) {
|
|
1091
1035
|
const attrName = input.attributes[i].name;
|
|
1092
|
-
|
|
1093
1036
|
if (!['type', 'value', 'style'].includes(attrName)) {
|
|
1094
1037
|
input.removeAttribute(attrName);
|
|
1095
1038
|
}
|
|
1096
1039
|
}
|
|
1097
1040
|
};
|
|
1041
|
+
|
|
1098
1042
|
/**
|
|
1099
1043
|
* @param {InputClass} inputClass
|
|
1100
1044
|
* @param {SweetAlertOptions['inputAttributes']} inputAttributes
|
|
1101
1045
|
*/
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
1046
|
const setAttributes = (inputClass, inputAttributes) => {
|
|
1105
1047
|
const input = getInput(getPopup(), inputClass);
|
|
1106
|
-
|
|
1107
1048
|
if (!input) {
|
|
1108
1049
|
return;
|
|
1109
1050
|
}
|
|
1110
|
-
|
|
1111
1051
|
removeAttributes(input);
|
|
1112
|
-
|
|
1113
1052
|
for (const attr in inputAttributes) {
|
|
1114
1053
|
input.setAttribute(attr, inputAttributes[attr]);
|
|
1115
1054
|
}
|
|
1116
1055
|
};
|
|
1056
|
+
|
|
1117
1057
|
/**
|
|
1118
1058
|
* @param {SweetAlertOptions} params
|
|
1119
1059
|
*/
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
1060
|
const setCustomClass = params => {
|
|
1123
1061
|
const inputContainer = getInputContainer(params.input);
|
|
1124
|
-
|
|
1125
1062
|
if (typeof params.customClass === 'object') {
|
|
1126
1063
|
addClass(inputContainer, params.customClass.input);
|
|
1127
1064
|
}
|
|
1128
1065
|
};
|
|
1066
|
+
|
|
1129
1067
|
/**
|
|
1130
1068
|
* @param {HTMLInputElement | HTMLTextAreaElement} input
|
|
1131
1069
|
* @param {SweetAlertOptions} params
|
|
1132
1070
|
*/
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
1071
|
const setInputPlaceholder = (input, params) => {
|
|
1136
1072
|
if (!input.placeholder || params.inputPlaceholder) {
|
|
1137
1073
|
input.placeholder = params.inputPlaceholder;
|
|
1138
1074
|
}
|
|
1139
1075
|
};
|
|
1076
|
+
|
|
1140
1077
|
/**
|
|
1141
1078
|
* @param {Input} input
|
|
1142
1079
|
* @param {Input} prependTo
|
|
1143
1080
|
* @param {SweetAlertOptions} params
|
|
1144
1081
|
*/
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
1082
|
const setInputLabel = (input, prependTo, params) => {
|
|
1148
1083
|
if (params.inputLabel) {
|
|
1149
1084
|
input.id = swalClasses.input;
|
|
@@ -1151,30 +1086,26 @@
|
|
|
1151
1086
|
const labelClass = swalClasses['input-label'];
|
|
1152
1087
|
label.setAttribute('for', input.id);
|
|
1153
1088
|
label.className = labelClass;
|
|
1154
|
-
|
|
1155
1089
|
if (typeof params.customClass === 'object') {
|
|
1156
1090
|
addClass(label, params.customClass.inputLabel);
|
|
1157
1091
|
}
|
|
1158
|
-
|
|
1159
1092
|
label.innerText = params.inputLabel;
|
|
1160
1093
|
prependTo.insertAdjacentElement('beforebegin', label);
|
|
1161
1094
|
}
|
|
1162
1095
|
};
|
|
1096
|
+
|
|
1163
1097
|
/**
|
|
1164
1098
|
* @param {SweetAlertOptions['input']} inputType
|
|
1165
1099
|
* @returns {HTMLElement}
|
|
1166
1100
|
*/
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
1101
|
const getInputContainer = inputType => {
|
|
1170
1102
|
return getDirectChildByClass(getPopup(), swalClasses[inputType] || swalClasses.input);
|
|
1171
1103
|
};
|
|
1104
|
+
|
|
1172
1105
|
/**
|
|
1173
1106
|
* @param {HTMLInputElement | HTMLOutputElement | HTMLTextAreaElement} input
|
|
1174
1107
|
* @param {SweetAlertOptions['inputValue']} inputValue
|
|
1175
1108
|
*/
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
1109
|
const checkAndSetInputValue = (input, inputValue) => {
|
|
1179
1110
|
if (['string', 'number'].includes(typeof inputValue)) {
|
|
1180
1111
|
input.value = "".concat(inputValue);
|
|
@@ -1182,16 +1113,15 @@
|
|
|
1182
1113
|
warn("Unexpected type of inputValue! Expected \"string\", \"number\" or \"Promise\", got \"".concat(typeof inputValue, "\""));
|
|
1183
1114
|
}
|
|
1184
1115
|
};
|
|
1185
|
-
/** @type {Record<string, (input: Input | HTMLElement, params: SweetAlertOptions) => Input>} */
|
|
1186
|
-
|
|
1187
1116
|
|
|
1117
|
+
/** @type {Record<string, (input: Input | HTMLElement, params: SweetAlertOptions) => Input>} */
|
|
1188
1118
|
const renderInputType = {};
|
|
1119
|
+
|
|
1189
1120
|
/**
|
|
1190
1121
|
* @param {HTMLInputElement} input
|
|
1191
1122
|
* @param {SweetAlertOptions} params
|
|
1192
1123
|
* @returns {HTMLInputElement}
|
|
1193
1124
|
*/
|
|
1194
|
-
|
|
1195
1125
|
renderInputType.text = renderInputType.email = renderInputType.password = renderInputType.number = renderInputType.tel = renderInputType.url = (input, params) => {
|
|
1196
1126
|
checkAndSetInputValue(input, params.inputValue);
|
|
1197
1127
|
setInputLabel(input, input, params);
|
|
@@ -1199,25 +1129,23 @@
|
|
|
1199
1129
|
input.type = params.input;
|
|
1200
1130
|
return input;
|
|
1201
1131
|
};
|
|
1132
|
+
|
|
1202
1133
|
/**
|
|
1203
1134
|
* @param {HTMLInputElement} input
|
|
1204
1135
|
* @param {SweetAlertOptions} params
|
|
1205
1136
|
* @returns {HTMLInputElement}
|
|
1206
1137
|
*/
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
1138
|
renderInputType.file = (input, params) => {
|
|
1210
1139
|
setInputLabel(input, input, params);
|
|
1211
1140
|
setInputPlaceholder(input, params);
|
|
1212
1141
|
return input;
|
|
1213
1142
|
};
|
|
1143
|
+
|
|
1214
1144
|
/**
|
|
1215
1145
|
* @param {HTMLInputElement} range
|
|
1216
1146
|
* @param {SweetAlertOptions} params
|
|
1217
1147
|
* @returns {HTMLInputElement}
|
|
1218
1148
|
*/
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
1149
|
renderInputType.range = (range, params) => {
|
|
1222
1150
|
const rangeInput = range.querySelector('input');
|
|
1223
1151
|
const rangeOutput = range.querySelector('output');
|
|
@@ -1227,16 +1155,14 @@
|
|
|
1227
1155
|
setInputLabel(rangeInput, range, params);
|
|
1228
1156
|
return range;
|
|
1229
1157
|
};
|
|
1158
|
+
|
|
1230
1159
|
/**
|
|
1231
1160
|
* @param {HTMLSelectElement} select
|
|
1232
1161
|
* @param {SweetAlertOptions} params
|
|
1233
1162
|
* @returns {HTMLSelectElement}
|
|
1234
1163
|
*/
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
1164
|
renderInputType.select = (select, params) => {
|
|
1238
1165
|
select.textContent = '';
|
|
1239
|
-
|
|
1240
1166
|
if (params.inputPlaceholder) {
|
|
1241
1167
|
const placeholder = document.createElement('option');
|
|
1242
1168
|
setInnerHtml(placeholder, params.inputPlaceholder);
|
|
@@ -1245,27 +1171,24 @@
|
|
|
1245
1171
|
placeholder.selected = true;
|
|
1246
1172
|
select.appendChild(placeholder);
|
|
1247
1173
|
}
|
|
1248
|
-
|
|
1249
1174
|
setInputLabel(select, select, params);
|
|
1250
1175
|
return select;
|
|
1251
1176
|
};
|
|
1177
|
+
|
|
1252
1178
|
/**
|
|
1253
1179
|
* @param {HTMLInputElement} radio
|
|
1254
1180
|
* @returns {HTMLInputElement}
|
|
1255
1181
|
*/
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
1182
|
renderInputType.radio = radio => {
|
|
1259
1183
|
radio.textContent = '';
|
|
1260
1184
|
return radio;
|
|
1261
1185
|
};
|
|
1186
|
+
|
|
1262
1187
|
/**
|
|
1263
1188
|
* @param {HTMLLabelElement} checkboxContainer
|
|
1264
1189
|
* @param {SweetAlertOptions} params
|
|
1265
1190
|
* @returns {HTMLInputElement}
|
|
1266
1191
|
*/
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
1192
|
renderInputType.checkbox = (checkboxContainer, params) => {
|
|
1270
1193
|
const checkbox = getInput(getPopup(), 'checkbox');
|
|
1271
1194
|
checkbox.value = '1';
|
|
@@ -1275,40 +1198,36 @@
|
|
|
1275
1198
|
setInnerHtml(label, params.inputPlaceholder);
|
|
1276
1199
|
return checkbox;
|
|
1277
1200
|
};
|
|
1201
|
+
|
|
1278
1202
|
/**
|
|
1279
1203
|
* @param {HTMLTextAreaElement} textarea
|
|
1280
1204
|
* @param {SweetAlertOptions} params
|
|
1281
1205
|
* @returns {HTMLTextAreaElement}
|
|
1282
1206
|
*/
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
1207
|
renderInputType.textarea = (textarea, params) => {
|
|
1286
1208
|
checkAndSetInputValue(textarea, params.inputValue);
|
|
1287
1209
|
setInputPlaceholder(textarea, params);
|
|
1288
1210
|
setInputLabel(textarea, textarea, params);
|
|
1211
|
+
|
|
1289
1212
|
/**
|
|
1290
1213
|
* @param {HTMLElement} el
|
|
1291
1214
|
* @returns {number}
|
|
1292
1215
|
*/
|
|
1216
|
+
const getMargin = el => parseInt(window.getComputedStyle(el).marginLeft) + parseInt(window.getComputedStyle(el).marginRight);
|
|
1293
1217
|
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1218
|
+
// https://github.com/sweetalert2/sweetalert2/issues/2291
|
|
1297
1219
|
setTimeout(() => {
|
|
1298
1220
|
// https://github.com/sweetalert2/sweetalert2/issues/1699
|
|
1299
1221
|
if ('MutationObserver' in window) {
|
|
1300
1222
|
const initialPopupWidth = parseInt(window.getComputedStyle(getPopup()).width);
|
|
1301
|
-
|
|
1302
1223
|
const textareaResizeHandler = () => {
|
|
1303
1224
|
const textareaWidth = textarea.offsetWidth + getMargin(textarea);
|
|
1304
|
-
|
|
1305
1225
|
if (textareaWidth > initialPopupWidth) {
|
|
1306
1226
|
getPopup().style.width = "".concat(textareaWidth, "px");
|
|
1307
1227
|
} else {
|
|
1308
1228
|
getPopup().style.width = null;
|
|
1309
1229
|
}
|
|
1310
1230
|
};
|
|
1311
|
-
|
|
1312
1231
|
new MutationObserver(textareaResizeHandler).observe(textarea, {
|
|
1313
1232
|
attributes: true,
|
|
1314
1233
|
attributeFilter: ['style']
|
|
@@ -1322,23 +1241,26 @@
|
|
|
1322
1241
|
* @param {SweetAlert2} instance
|
|
1323
1242
|
* @param {SweetAlertOptions} params
|
|
1324
1243
|
*/
|
|
1325
|
-
|
|
1326
1244
|
const renderContent = (instance, params) => {
|
|
1327
1245
|
const htmlContainer = getHtmlContainer();
|
|
1328
|
-
applyCustomClass(htmlContainer, params, 'htmlContainer');
|
|
1246
|
+
applyCustomClass(htmlContainer, params, 'htmlContainer');
|
|
1329
1247
|
|
|
1248
|
+
// Content as HTML
|
|
1330
1249
|
if (params.html) {
|
|
1331
1250
|
parseHtmlToContainer(params.html, htmlContainer);
|
|
1332
1251
|
show(htmlContainer, 'block');
|
|
1333
|
-
}
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
// Content as plain text
|
|
1334
1255
|
else if (params.text) {
|
|
1335
1256
|
htmlContainer.textContent = params.text;
|
|
1336
1257
|
show(htmlContainer, 'block');
|
|
1337
|
-
}
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
// No content
|
|
1338
1261
|
else {
|
|
1339
1262
|
hide(htmlContainer);
|
|
1340
1263
|
}
|
|
1341
|
-
|
|
1342
1264
|
renderInput(instance, params);
|
|
1343
1265
|
};
|
|
1344
1266
|
|
|
@@ -1346,16 +1268,14 @@
|
|
|
1346
1268
|
* @param {SweetAlert2} instance
|
|
1347
1269
|
* @param {SweetAlertOptions} params
|
|
1348
1270
|
*/
|
|
1349
|
-
|
|
1350
1271
|
const renderFooter = (instance, params) => {
|
|
1351
1272
|
const footer = getFooter();
|
|
1352
1273
|
toggle(footer, params.footer);
|
|
1353
|
-
|
|
1354
1274
|
if (params.footer) {
|
|
1355
1275
|
parseHtmlToContainer(params.footer, footer);
|
|
1356
|
-
}
|
|
1357
|
-
|
|
1276
|
+
}
|
|
1358
1277
|
|
|
1278
|
+
// Custom class
|
|
1359
1279
|
applyCustomClass(footer, params, 'footer');
|
|
1360
1280
|
};
|
|
1361
1281
|
|
|
@@ -1363,81 +1283,78 @@
|
|
|
1363
1283
|
* @param {SweetAlert2} instance
|
|
1364
1284
|
* @param {SweetAlertOptions} params
|
|
1365
1285
|
*/
|
|
1366
|
-
|
|
1367
1286
|
const renderIcon = (instance, params) => {
|
|
1368
1287
|
const innerParams = privateProps.innerParams.get(instance);
|
|
1369
|
-
const icon = getIcon();
|
|
1288
|
+
const icon = getIcon();
|
|
1370
1289
|
|
|
1290
|
+
// if the given icon already rendered, apply the styling without re-rendering the icon
|
|
1371
1291
|
if (innerParams && params.icon === innerParams.icon) {
|
|
1372
1292
|
// Custom or default content
|
|
1373
1293
|
setContent(icon, params);
|
|
1374
1294
|
applyStyles(icon, params);
|
|
1375
1295
|
return;
|
|
1376
1296
|
}
|
|
1377
|
-
|
|
1378
1297
|
if (!params.icon && !params.iconHtml) {
|
|
1379
1298
|
hide(icon);
|
|
1380
1299
|
return;
|
|
1381
1300
|
}
|
|
1382
|
-
|
|
1383
1301
|
if (params.icon && Object.keys(iconTypes).indexOf(params.icon) === -1) {
|
|
1384
1302
|
error("Unknown icon! Expected \"success\", \"error\", \"warning\", \"info\" or \"question\", got \"".concat(params.icon, "\""));
|
|
1385
1303
|
hide(icon);
|
|
1386
1304
|
return;
|
|
1387
1305
|
}
|
|
1306
|
+
show(icon);
|
|
1388
1307
|
|
|
1389
|
-
|
|
1390
|
-
|
|
1308
|
+
// Custom or default content
|
|
1391
1309
|
setContent(icon, params);
|
|
1392
|
-
applyStyles(icon, params);
|
|
1310
|
+
applyStyles(icon, params);
|
|
1393
1311
|
|
|
1312
|
+
// Animate icon
|
|
1394
1313
|
addClass(icon, params.showClass.icon);
|
|
1395
1314
|
};
|
|
1315
|
+
|
|
1396
1316
|
/**
|
|
1397
1317
|
* @param {HTMLElement} icon
|
|
1398
1318
|
* @param {SweetAlertOptions} params
|
|
1399
1319
|
*/
|
|
1400
|
-
|
|
1401
1320
|
const applyStyles = (icon, params) => {
|
|
1402
1321
|
for (const iconType in iconTypes) {
|
|
1403
1322
|
if (params.icon !== iconType) {
|
|
1404
1323
|
removeClass(icon, iconTypes[iconType]);
|
|
1405
1324
|
}
|
|
1406
1325
|
}
|
|
1326
|
+
addClass(icon, iconTypes[params.icon]);
|
|
1407
1327
|
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
setColor(icon, params); // Success icon background color
|
|
1328
|
+
// Icon color
|
|
1329
|
+
setColor(icon, params);
|
|
1411
1330
|
|
|
1412
|
-
|
|
1331
|
+
// Success icon background color
|
|
1332
|
+
adjustSuccessIconBackgroundColor();
|
|
1413
1333
|
|
|
1334
|
+
// Custom class
|
|
1414
1335
|
applyCustomClass(icon, params, 'icon');
|
|
1415
|
-
};
|
|
1416
|
-
|
|
1336
|
+
};
|
|
1417
1337
|
|
|
1338
|
+
// Adjust success icon background color to match the popup background color
|
|
1418
1339
|
const adjustSuccessIconBackgroundColor = () => {
|
|
1419
1340
|
const popup = getPopup();
|
|
1420
1341
|
const popupBackgroundColor = window.getComputedStyle(popup).getPropertyValue('background-color');
|
|
1421
1342
|
/** @type {NodeListOf<HTMLElement>} */
|
|
1422
|
-
|
|
1423
1343
|
const successIconParts = popup.querySelectorAll('[class^=swal2-success-circular-line], .swal2-success-fix');
|
|
1424
|
-
|
|
1425
1344
|
for (let i = 0; i < successIconParts.length; i++) {
|
|
1426
1345
|
successIconParts[i].style.backgroundColor = popupBackgroundColor;
|
|
1427
1346
|
}
|
|
1428
1347
|
};
|
|
1429
|
-
|
|
1430
1348
|
const successIconHtml = "\n <div class=\"swal2-success-circular-line-left\"></div>\n <span class=\"swal2-success-line-tip\"></span> <span class=\"swal2-success-line-long\"></span>\n <div class=\"swal2-success-ring\"></div> <div class=\"swal2-success-fix\"></div>\n <div class=\"swal2-success-circular-line-right\"></div>\n";
|
|
1431
1349
|
const errorIconHtml = "\n <span class=\"swal2-x-mark\">\n <span class=\"swal2-x-mark-line-left\"></span>\n <span class=\"swal2-x-mark-line-right\"></span>\n </span>\n";
|
|
1350
|
+
|
|
1432
1351
|
/**
|
|
1433
1352
|
* @param {HTMLElement} icon
|
|
1434
1353
|
* @param {SweetAlertOptions} params
|
|
1435
1354
|
*/
|
|
1436
|
-
|
|
1437
1355
|
const setContent = (icon, params) => {
|
|
1438
1356
|
let oldContent = icon.innerHTML;
|
|
1439
1357
|
let newContent;
|
|
1440
|
-
|
|
1441
1358
|
if (params.iconHtml) {
|
|
1442
1359
|
newContent = iconContent(params.iconHtml);
|
|
1443
1360
|
} else if (params.icon === 'success') {
|
|
@@ -1453,60 +1370,54 @@
|
|
|
1453
1370
|
};
|
|
1454
1371
|
newContent = iconContent(defaultIconHtml[params.icon]);
|
|
1455
1372
|
}
|
|
1456
|
-
|
|
1457
1373
|
if (oldContent.trim() !== newContent.trim()) {
|
|
1458
1374
|
setInnerHtml(icon, newContent);
|
|
1459
1375
|
}
|
|
1460
1376
|
};
|
|
1377
|
+
|
|
1461
1378
|
/**
|
|
1462
1379
|
* @param {HTMLElement} icon
|
|
1463
1380
|
* @param {SweetAlertOptions} params
|
|
1464
1381
|
*/
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
1382
|
const setColor = (icon, params) => {
|
|
1468
1383
|
if (!params.iconColor) {
|
|
1469
1384
|
return;
|
|
1470
1385
|
}
|
|
1471
|
-
|
|
1472
1386
|
icon.style.color = params.iconColor;
|
|
1473
1387
|
icon.style.borderColor = params.iconColor;
|
|
1474
|
-
|
|
1475
1388
|
for (const sel of ['.swal2-success-line-tip', '.swal2-success-line-long', '.swal2-x-mark-line-left', '.swal2-x-mark-line-right']) {
|
|
1476
1389
|
setStyle(icon, sel, 'backgroundColor', params.iconColor);
|
|
1477
1390
|
}
|
|
1478
|
-
|
|
1479
1391
|
setStyle(icon, '.swal2-success-ring', 'borderColor', params.iconColor);
|
|
1480
1392
|
};
|
|
1393
|
+
|
|
1481
1394
|
/**
|
|
1482
1395
|
* @param {string} content
|
|
1483
1396
|
* @returns {string}
|
|
1484
1397
|
*/
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
1398
|
const iconContent = content => "<div class=\"".concat(swalClasses['icon-content'], "\">").concat(content, "</div>");
|
|
1488
1399
|
|
|
1489
1400
|
/**
|
|
1490
1401
|
* @param {SweetAlert2} instance
|
|
1491
1402
|
* @param {SweetAlertOptions} params
|
|
1492
1403
|
*/
|
|
1493
|
-
|
|
1494
1404
|
const renderImage = (instance, params) => {
|
|
1495
1405
|
const image = getImage();
|
|
1496
|
-
|
|
1497
1406
|
if (!params.imageUrl) {
|
|
1498
1407
|
hide(image);
|
|
1499
1408
|
return;
|
|
1500
1409
|
}
|
|
1410
|
+
show(image, '');
|
|
1501
1411
|
|
|
1502
|
-
|
|
1503
|
-
|
|
1412
|
+
// Src, alt
|
|
1504
1413
|
image.setAttribute('src', params.imageUrl);
|
|
1505
|
-
image.setAttribute('alt', params.imageAlt);
|
|
1414
|
+
image.setAttribute('alt', params.imageAlt);
|
|
1506
1415
|
|
|
1416
|
+
// Width, height
|
|
1507
1417
|
applyNumericalStyle(image, 'width', params.imageWidth);
|
|
1508
|
-
applyNumericalStyle(image, 'height', params.imageHeight);
|
|
1418
|
+
applyNumericalStyle(image, 'height', params.imageHeight);
|
|
1509
1419
|
|
|
1420
|
+
// Class
|
|
1510
1421
|
image.className = swalClasses.image;
|
|
1511
1422
|
applyCustomClass(image, params, 'image');
|
|
1512
1423
|
};
|
|
@@ -1515,60 +1426,59 @@
|
|
|
1515
1426
|
* @param {SweetAlert2} instance
|
|
1516
1427
|
* @param {SweetAlertOptions} params
|
|
1517
1428
|
*/
|
|
1518
|
-
|
|
1519
1429
|
const renderPopup = (instance, params) => {
|
|
1520
1430
|
const container = getContainer();
|
|
1521
|
-
const popup = getPopup();
|
|
1522
|
-
// https://github.com/sweetalert2/sweetalert2/issues/2170
|
|
1431
|
+
const popup = getPopup();
|
|
1523
1432
|
|
|
1433
|
+
// Width
|
|
1434
|
+
// https://github.com/sweetalert2/sweetalert2/issues/2170
|
|
1524
1435
|
if (params.toast) {
|
|
1525
1436
|
applyNumericalStyle(container, 'width', params.width);
|
|
1526
1437
|
popup.style.width = '100%';
|
|
1527
1438
|
popup.insertBefore(getLoader(), getIcon());
|
|
1528
1439
|
} else {
|
|
1529
1440
|
applyNumericalStyle(popup, 'width', params.width);
|
|
1530
|
-
}
|
|
1531
|
-
|
|
1441
|
+
}
|
|
1532
1442
|
|
|
1533
|
-
|
|
1443
|
+
// Padding
|
|
1444
|
+
applyNumericalStyle(popup, 'padding', params.padding);
|
|
1534
1445
|
|
|
1446
|
+
// Color
|
|
1535
1447
|
if (params.color) {
|
|
1536
1448
|
popup.style.color = params.color;
|
|
1537
|
-
}
|
|
1538
|
-
|
|
1449
|
+
}
|
|
1539
1450
|
|
|
1451
|
+
// Background
|
|
1540
1452
|
if (params.background) {
|
|
1541
1453
|
popup.style.background = params.background;
|
|
1542
1454
|
}
|
|
1455
|
+
hide(getValidationMessage());
|
|
1543
1456
|
|
|
1544
|
-
|
|
1545
|
-
|
|
1457
|
+
// Classes
|
|
1546
1458
|
addClasses(popup, params);
|
|
1547
1459
|
};
|
|
1460
|
+
|
|
1548
1461
|
/**
|
|
1549
1462
|
* @param {HTMLElement} popup
|
|
1550
1463
|
* @param {SweetAlertOptions} params
|
|
1551
1464
|
*/
|
|
1552
|
-
|
|
1553
1465
|
const addClasses = (popup, params) => {
|
|
1554
1466
|
// Default Class + showClass when updating Swal.update({})
|
|
1555
1467
|
popup.className = "".concat(swalClasses.popup, " ").concat(isVisible(popup) ? params.showClass.popup : '');
|
|
1556
|
-
|
|
1557
1468
|
if (params.toast) {
|
|
1558
1469
|
addClass([document.documentElement, document.body], swalClasses['toast-shown']);
|
|
1559
1470
|
addClass(popup, swalClasses.toast);
|
|
1560
1471
|
} else {
|
|
1561
1472
|
addClass(popup, swalClasses.modal);
|
|
1562
|
-
}
|
|
1563
|
-
|
|
1473
|
+
}
|
|
1564
1474
|
|
|
1475
|
+
// Custom class
|
|
1565
1476
|
applyCustomClass(popup, params, 'popup');
|
|
1566
|
-
|
|
1567
1477
|
if (typeof params.customClass === 'string') {
|
|
1568
1478
|
addClass(popup, params.customClass);
|
|
1569
|
-
}
|
|
1570
|
-
|
|
1479
|
+
}
|
|
1571
1480
|
|
|
1481
|
+
// Icon class (#1842)
|
|
1572
1482
|
if (params.icon) {
|
|
1573
1483
|
addClass(popup, swalClasses["icon-".concat(params.icon)]);
|
|
1574
1484
|
}
|
|
@@ -1578,61 +1488,51 @@
|
|
|
1578
1488
|
* @param {SweetAlert2} instance
|
|
1579
1489
|
* @param {SweetAlertOptions} params
|
|
1580
1490
|
*/
|
|
1581
|
-
|
|
1582
1491
|
const renderProgressSteps = (instance, params) => {
|
|
1583
1492
|
const progressStepsContainer = getProgressSteps();
|
|
1584
|
-
|
|
1585
1493
|
if (!params.progressSteps || params.progressSteps.length === 0) {
|
|
1586
1494
|
hide(progressStepsContainer);
|
|
1587
1495
|
return;
|
|
1588
1496
|
}
|
|
1589
|
-
|
|
1590
1497
|
show(progressStepsContainer);
|
|
1591
1498
|
progressStepsContainer.textContent = '';
|
|
1592
|
-
|
|
1593
1499
|
if (params.currentProgressStep >= params.progressSteps.length) {
|
|
1594
1500
|
warn('Invalid currentProgressStep parameter, it should be less than progressSteps.length ' + '(currentProgressStep like JS arrays starts from 0)');
|
|
1595
1501
|
}
|
|
1596
|
-
|
|
1597
1502
|
params.progressSteps.forEach((step, index) => {
|
|
1598
1503
|
const stepEl = createStepElement(step);
|
|
1599
1504
|
progressStepsContainer.appendChild(stepEl);
|
|
1600
|
-
|
|
1601
1505
|
if (index === params.currentProgressStep) {
|
|
1602
1506
|
addClass(stepEl, swalClasses['active-progress-step']);
|
|
1603
1507
|
}
|
|
1604
|
-
|
|
1605
1508
|
if (index !== params.progressSteps.length - 1) {
|
|
1606
1509
|
const lineEl = createLineElement(params);
|
|
1607
1510
|
progressStepsContainer.appendChild(lineEl);
|
|
1608
1511
|
}
|
|
1609
1512
|
});
|
|
1610
1513
|
};
|
|
1514
|
+
|
|
1611
1515
|
/**
|
|
1612
1516
|
* @param {string} step
|
|
1613
1517
|
* @returns {HTMLLIElement}
|
|
1614
1518
|
*/
|
|
1615
|
-
|
|
1616
1519
|
const createStepElement = step => {
|
|
1617
1520
|
const stepEl = document.createElement('li');
|
|
1618
1521
|
addClass(stepEl, swalClasses['progress-step']);
|
|
1619
1522
|
setInnerHtml(stepEl, step);
|
|
1620
1523
|
return stepEl;
|
|
1621
1524
|
};
|
|
1525
|
+
|
|
1622
1526
|
/**
|
|
1623
1527
|
* @param {SweetAlertOptions} params
|
|
1624
1528
|
* @returns {HTMLLIElement}
|
|
1625
1529
|
*/
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
1530
|
const createLineElement = params => {
|
|
1629
1531
|
const lineEl = document.createElement('li');
|
|
1630
1532
|
addClass(lineEl, swalClasses['progress-step-line']);
|
|
1631
|
-
|
|
1632
1533
|
if (params.progressStepsDistance) {
|
|
1633
1534
|
applyNumericalStyle(lineEl, 'width', params.progressStepsDistance);
|
|
1634
1535
|
}
|
|
1635
|
-
|
|
1636
1536
|
return lineEl;
|
|
1637
1537
|
};
|
|
1638
1538
|
|
|
@@ -1640,20 +1540,17 @@
|
|
|
1640
1540
|
* @param {SweetAlert2} instance
|
|
1641
1541
|
* @param {SweetAlertOptions} params
|
|
1642
1542
|
*/
|
|
1643
|
-
|
|
1644
1543
|
const renderTitle = (instance, params) => {
|
|
1645
1544
|
const title = getTitle();
|
|
1646
1545
|
toggle(title, params.title || params.titleText, 'block');
|
|
1647
|
-
|
|
1648
1546
|
if (params.title) {
|
|
1649
1547
|
parseHtmlToContainer(params.title, title);
|
|
1650
1548
|
}
|
|
1651
|
-
|
|
1652
1549
|
if (params.titleText) {
|
|
1653
1550
|
title.innerText = params.titleText;
|
|
1654
|
-
}
|
|
1655
|
-
|
|
1551
|
+
}
|
|
1656
1552
|
|
|
1553
|
+
// Custom class
|
|
1657
1554
|
applyCustomClass(title, params, 'title');
|
|
1658
1555
|
};
|
|
1659
1556
|
|
|
@@ -1661,7 +1558,6 @@
|
|
|
1661
1558
|
* @param {SweetAlert2} instance
|
|
1662
1559
|
* @param {SweetAlertOptions} params
|
|
1663
1560
|
*/
|
|
1664
|
-
|
|
1665
1561
|
const render = (instance, params) => {
|
|
1666
1562
|
renderPopup(instance, params);
|
|
1667
1563
|
renderContainer(instance, params);
|
|
@@ -1673,7 +1569,6 @@
|
|
|
1673
1569
|
renderContent(instance, params);
|
|
1674
1570
|
renderActions(instance, params);
|
|
1675
1571
|
renderFooter(instance, params);
|
|
1676
|
-
|
|
1677
1572
|
if (typeof params.didRender === 'function') {
|
|
1678
1573
|
params.didRender(getPopup());
|
|
1679
1574
|
}
|
|
@@ -1682,18 +1577,14 @@
|
|
|
1682
1577
|
/**
|
|
1683
1578
|
* Hides loader and shows back the button which was hidden by .showLoading()
|
|
1684
1579
|
*/
|
|
1685
|
-
|
|
1686
1580
|
function hideLoading() {
|
|
1687
1581
|
// do nothing if popup is closed
|
|
1688
1582
|
const innerParams = privateProps.innerParams.get(this);
|
|
1689
|
-
|
|
1690
1583
|
if (!innerParams) {
|
|
1691
1584
|
return;
|
|
1692
1585
|
}
|
|
1693
|
-
|
|
1694
1586
|
const domCache = privateProps.domCache.get(this);
|
|
1695
1587
|
hide(domCache.loader);
|
|
1696
|
-
|
|
1697
1588
|
if (isToast()) {
|
|
1698
1589
|
if (innerParams.icon) {
|
|
1699
1590
|
show(getIcon());
|
|
@@ -1701,7 +1592,6 @@
|
|
|
1701
1592
|
} else {
|
|
1702
1593
|
showRelatedButton(domCache);
|
|
1703
1594
|
}
|
|
1704
|
-
|
|
1705
1595
|
removeClass([domCache.popup, domCache.actions], swalClasses.loading);
|
|
1706
1596
|
domCache.popup.removeAttribute('aria-busy');
|
|
1707
1597
|
domCache.popup.removeAttribute('data-loading');
|
|
@@ -1709,10 +1599,8 @@
|
|
|
1709
1599
|
domCache.denyButton.disabled = false;
|
|
1710
1600
|
domCache.cancelButton.disabled = false;
|
|
1711
1601
|
}
|
|
1712
|
-
|
|
1713
1602
|
const showRelatedButton = domCache => {
|
|
1714
1603
|
const buttonToReplace = domCache.popup.getElementsByClassName(domCache.loader.getAttribute('data-button-to-replace'));
|
|
1715
|
-
|
|
1716
1604
|
if (buttonToReplace.length) {
|
|
1717
1605
|
show(buttonToReplace[0], 'inline-block');
|
|
1718
1606
|
} else if (allButtonsAreHidden()) {
|
|
@@ -1724,39 +1612,35 @@
|
|
|
1724
1612
|
* Gets the input DOM node, this method works with input parameter.
|
|
1725
1613
|
* @returns {HTMLElement | null}
|
|
1726
1614
|
*/
|
|
1727
|
-
|
|
1728
1615
|
function getInput$1(instance) {
|
|
1729
1616
|
const innerParams = privateProps.innerParams.get(instance || this);
|
|
1730
1617
|
const domCache = privateProps.domCache.get(instance || this);
|
|
1731
|
-
|
|
1732
1618
|
if (!domCache) {
|
|
1733
1619
|
return null;
|
|
1734
1620
|
}
|
|
1735
|
-
|
|
1736
1621
|
return getInput(domCache.popup, innerParams.input);
|
|
1737
1622
|
}
|
|
1738
1623
|
|
|
1739
1624
|
/*
|
|
1740
1625
|
* Global function to determine if SweetAlert2 popup is shown
|
|
1741
1626
|
*/
|
|
1742
|
-
|
|
1743
1627
|
const isVisible$1 = () => {
|
|
1744
1628
|
return isVisible(getPopup());
|
|
1745
1629
|
};
|
|
1630
|
+
|
|
1746
1631
|
/*
|
|
1747
1632
|
* Global function to click 'Confirm' button
|
|
1748
1633
|
*/
|
|
1749
|
-
|
|
1750
1634
|
const clickConfirm = () => getConfirmButton() && getConfirmButton().click();
|
|
1635
|
+
|
|
1751
1636
|
/*
|
|
1752
1637
|
* Global function to click 'Deny' button
|
|
1753
1638
|
*/
|
|
1754
|
-
|
|
1755
1639
|
const clickDeny = () => getDenyButton() && getDenyButton().click();
|
|
1640
|
+
|
|
1756
1641
|
/*
|
|
1757
1642
|
* Global function to click 'Cancel' button
|
|
1758
1643
|
*/
|
|
1759
|
-
|
|
1760
1644
|
const clickCancel = () => getCancelButton() && getCancelButton().click();
|
|
1761
1645
|
|
|
1762
1646
|
const DismissReason = Object.freeze({
|
|
@@ -1770,7 +1654,6 @@
|
|
|
1770
1654
|
/**
|
|
1771
1655
|
* @param {GlobalState} globalState
|
|
1772
1656
|
*/
|
|
1773
|
-
|
|
1774
1657
|
const removeKeydownHandler = globalState => {
|
|
1775
1658
|
if (globalState.keydownTarget && globalState.keydownHandlerAdded) {
|
|
1776
1659
|
globalState.keydownTarget.removeEventListener('keydown', globalState.keydownHandler, {
|
|
@@ -1779,19 +1662,17 @@
|
|
|
1779
1662
|
globalState.keydownHandlerAdded = false;
|
|
1780
1663
|
}
|
|
1781
1664
|
};
|
|
1665
|
+
|
|
1782
1666
|
/**
|
|
1783
1667
|
* @param {SweetAlert2} instance
|
|
1784
1668
|
* @param {GlobalState} globalState
|
|
1785
1669
|
* @param {SweetAlertOptions} innerParams
|
|
1786
1670
|
* @param {*} dismissWith
|
|
1787
1671
|
*/
|
|
1788
|
-
|
|
1789
1672
|
const addKeydownHandler = (instance, globalState, innerParams, dismissWith) => {
|
|
1790
1673
|
removeKeydownHandler(globalState);
|
|
1791
|
-
|
|
1792
1674
|
if (!innerParams.toast) {
|
|
1793
1675
|
globalState.keydownHandler = e => keydownHandler(instance, e, dismissWith);
|
|
1794
|
-
|
|
1795
1676
|
globalState.keydownTarget = innerParams.keydownListenerCapture ? window : getPopup();
|
|
1796
1677
|
globalState.keydownListenerCapture = innerParams.keydownListenerCapture;
|
|
1797
1678
|
globalState.keydownTarget.addEventListener('keydown', globalState.keydownHandler, {
|
|
@@ -1800,84 +1681,87 @@
|
|
|
1800
1681
|
globalState.keydownHandlerAdded = true;
|
|
1801
1682
|
}
|
|
1802
1683
|
};
|
|
1684
|
+
|
|
1803
1685
|
/**
|
|
1804
1686
|
* @param {SweetAlertOptions} innerParams
|
|
1805
1687
|
* @param {number} index
|
|
1806
1688
|
* @param {number} increment
|
|
1807
1689
|
*/
|
|
1808
|
-
|
|
1809
1690
|
const setFocus = (innerParams, index, increment) => {
|
|
1810
|
-
const focusableElements = getFocusableElements();
|
|
1811
|
-
|
|
1691
|
+
const focusableElements = getFocusableElements();
|
|
1692
|
+
// search for visible elements and select the next possible match
|
|
1812
1693
|
if (focusableElements.length) {
|
|
1813
|
-
index = index + increment;
|
|
1694
|
+
index = index + increment;
|
|
1814
1695
|
|
|
1696
|
+
// rollover to first item
|
|
1815
1697
|
if (index === focusableElements.length) {
|
|
1816
|
-
index = 0;
|
|
1698
|
+
index = 0;
|
|
1699
|
+
|
|
1700
|
+
// go to last item
|
|
1817
1701
|
} else if (index === -1) {
|
|
1818
1702
|
index = focusableElements.length - 1;
|
|
1819
1703
|
}
|
|
1820
|
-
|
|
1821
1704
|
return focusableElements[index].focus();
|
|
1822
|
-
}
|
|
1823
|
-
|
|
1824
|
-
|
|
1705
|
+
}
|
|
1706
|
+
// no visible focusable elements, focus the popup
|
|
1825
1707
|
getPopup().focus();
|
|
1826
1708
|
};
|
|
1827
1709
|
const arrowKeysNextButton = ['ArrowRight', 'ArrowDown'];
|
|
1828
1710
|
const arrowKeysPreviousButton = ['ArrowLeft', 'ArrowUp'];
|
|
1711
|
+
|
|
1829
1712
|
/**
|
|
1830
1713
|
* @param {SweetAlert2} instance
|
|
1831
1714
|
* @param {KeyboardEvent} e
|
|
1832
1715
|
* @param {function} dismissWith
|
|
1833
1716
|
*/
|
|
1834
|
-
|
|
1835
1717
|
const keydownHandler = (instance, e, dismissWith) => {
|
|
1836
1718
|
const innerParams = privateProps.innerParams.get(instance);
|
|
1837
|
-
|
|
1838
1719
|
if (!innerParams) {
|
|
1839
1720
|
return; // This instance has already been destroyed
|
|
1840
|
-
}
|
|
1721
|
+
}
|
|
1722
|
+
|
|
1723
|
+
// Ignore keydown during IME composition
|
|
1841
1724
|
// https://developer.mozilla.org/en-US/docs/Web/API/Document/keydown_event#ignoring_keydown_during_ime_composition
|
|
1842
1725
|
// https://github.com/sweetalert2/sweetalert2/issues/720
|
|
1843
1726
|
// https://github.com/sweetalert2/sweetalert2/issues/2406
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
1727
|
if (e.isComposing || e.keyCode === 229) {
|
|
1847
1728
|
return;
|
|
1848
1729
|
}
|
|
1849
|
-
|
|
1850
1730
|
if (innerParams.stopKeydownPropagation) {
|
|
1851
1731
|
e.stopPropagation();
|
|
1852
|
-
}
|
|
1853
|
-
|
|
1732
|
+
}
|
|
1854
1733
|
|
|
1734
|
+
// ENTER
|
|
1855
1735
|
if (e.key === 'Enter') {
|
|
1856
1736
|
handleEnter(instance, e, innerParams);
|
|
1857
|
-
}
|
|
1737
|
+
}
|
|
1738
|
+
|
|
1739
|
+
// TAB
|
|
1858
1740
|
else if (e.key === 'Tab') {
|
|
1859
1741
|
handleTab(e, innerParams);
|
|
1860
|
-
}
|
|
1742
|
+
}
|
|
1743
|
+
|
|
1744
|
+
// ARROWS - switch focus between buttons
|
|
1861
1745
|
else if ([...arrowKeysNextButton, ...arrowKeysPreviousButton].includes(e.key)) {
|
|
1862
1746
|
handleArrows(e.key);
|
|
1863
|
-
}
|
|
1747
|
+
}
|
|
1748
|
+
|
|
1749
|
+
// ESC
|
|
1864
1750
|
else if (e.key === 'Escape') {
|
|
1865
1751
|
handleEsc(e, innerParams, dismissWith);
|
|
1866
1752
|
}
|
|
1867
1753
|
};
|
|
1754
|
+
|
|
1868
1755
|
/**
|
|
1869
1756
|
* @param {SweetAlert2} instance
|
|
1870
1757
|
* @param {KeyboardEvent} e
|
|
1871
1758
|
* @param {SweetAlertOptions} innerParams
|
|
1872
1759
|
*/
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
1760
|
const handleEnter = (instance, e, innerParams) => {
|
|
1876
1761
|
// https://github.com/sweetalert2/sweetalert2/issues/2386
|
|
1877
1762
|
if (!callIfFunction(innerParams.allowEnterKey)) {
|
|
1878
1763
|
return;
|
|
1879
1764
|
}
|
|
1880
|
-
|
|
1881
1765
|
if (e.target && instance.getInput() && e.target instanceof HTMLElement && e.target.outerHTML === instance.getInput().outerHTML) {
|
|
1882
1766
|
if (['textarea', 'file'].includes(innerParams.input)) {
|
|
1883
1767
|
return; // do not submit
|
|
@@ -1887,75 +1771,66 @@
|
|
|
1887
1771
|
e.preventDefault();
|
|
1888
1772
|
}
|
|
1889
1773
|
};
|
|
1774
|
+
|
|
1890
1775
|
/**
|
|
1891
1776
|
* @param {KeyboardEvent} e
|
|
1892
1777
|
* @param {SweetAlertOptions} innerParams
|
|
1893
1778
|
*/
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
1779
|
const handleTab = (e, innerParams) => {
|
|
1897
1780
|
const targetElement = e.target;
|
|
1898
1781
|
const focusableElements = getFocusableElements();
|
|
1899
1782
|
let btnIndex = -1;
|
|
1900
|
-
|
|
1901
1783
|
for (let i = 0; i < focusableElements.length; i++) {
|
|
1902
1784
|
if (targetElement === focusableElements[i]) {
|
|
1903
1785
|
btnIndex = i;
|
|
1904
1786
|
break;
|
|
1905
1787
|
}
|
|
1906
|
-
}
|
|
1907
|
-
|
|
1788
|
+
}
|
|
1908
1789
|
|
|
1790
|
+
// Cycle to the next button
|
|
1909
1791
|
if (!e.shiftKey) {
|
|
1910
1792
|
setFocus(innerParams, btnIndex, 1);
|
|
1911
|
-
}
|
|
1793
|
+
}
|
|
1794
|
+
|
|
1795
|
+
// Cycle to the prev button
|
|
1912
1796
|
else {
|
|
1913
1797
|
setFocus(innerParams, btnIndex, -1);
|
|
1914
1798
|
}
|
|
1915
|
-
|
|
1916
1799
|
e.stopPropagation();
|
|
1917
1800
|
e.preventDefault();
|
|
1918
1801
|
};
|
|
1802
|
+
|
|
1919
1803
|
/**
|
|
1920
1804
|
* @param {string} key
|
|
1921
1805
|
*/
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
1806
|
const handleArrows = key => {
|
|
1925
1807
|
const confirmButton = getConfirmButton();
|
|
1926
1808
|
const denyButton = getDenyButton();
|
|
1927
1809
|
const cancelButton = getCancelButton();
|
|
1928
|
-
|
|
1929
1810
|
if (document.activeElement instanceof HTMLElement && ![confirmButton, denyButton, cancelButton].includes(document.activeElement)) {
|
|
1930
1811
|
return;
|
|
1931
1812
|
}
|
|
1932
|
-
|
|
1933
1813
|
const sibling = arrowKeysNextButton.includes(key) ? 'nextElementSibling' : 'previousElementSibling';
|
|
1934
1814
|
let buttonToFocus = document.activeElement;
|
|
1935
|
-
|
|
1936
1815
|
for (let i = 0; i < getActions().children.length; i++) {
|
|
1937
1816
|
buttonToFocus = buttonToFocus[sibling];
|
|
1938
|
-
|
|
1939
1817
|
if (!buttonToFocus) {
|
|
1940
1818
|
return;
|
|
1941
1819
|
}
|
|
1942
|
-
|
|
1943
1820
|
if (buttonToFocus instanceof HTMLButtonElement && isVisible(buttonToFocus)) {
|
|
1944
1821
|
break;
|
|
1945
1822
|
}
|
|
1946
1823
|
}
|
|
1947
|
-
|
|
1948
1824
|
if (buttonToFocus instanceof HTMLButtonElement) {
|
|
1949
1825
|
buttonToFocus.focus();
|
|
1950
1826
|
}
|
|
1951
1827
|
};
|
|
1828
|
+
|
|
1952
1829
|
/**
|
|
1953
1830
|
* @param {KeyboardEvent} e
|
|
1954
1831
|
* @param {SweetAlertOptions} innerParams
|
|
1955
1832
|
* @param {function} dismissWith
|
|
1956
1833
|
*/
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
1834
|
const handleEsc = (e, innerParams, dismissWith) => {
|
|
1960
1835
|
if (callIfFunction(innerParams.allowEscapeKey)) {
|
|
1961
1836
|
e.preventDefault();
|
|
@@ -1972,11 +1847,13 @@
|
|
|
1972
1847
|
* Once we have the changes from that PR in Babel, and our core class fits reasonable in *one module*
|
|
1973
1848
|
* then we can use that language feature.
|
|
1974
1849
|
*/
|
|
1850
|
+
|
|
1975
1851
|
var privateMethods = {
|
|
1976
1852
|
swalPromiseResolve: new WeakMap(),
|
|
1977
1853
|
swalPromiseReject: new WeakMap()
|
|
1978
1854
|
};
|
|
1979
1855
|
|
|
1856
|
+
// From https://developer.paciellogroup.com/blog/2018/06/the-current-state-of-modal-dialog-accessibility/
|
|
1980
1857
|
// Adding aria-hidden="true" to elements outside of the active modal dialog ensures that
|
|
1981
1858
|
// elements not within the active modal dialog will not be surfaced if a user opens a screen
|
|
1982
1859
|
// reader’s list of elements (headings, form controls, landmarks, etc.) in the document.
|
|
@@ -1987,11 +1864,9 @@
|
|
|
1987
1864
|
if (el === getContainer() || el.contains(getContainer())) {
|
|
1988
1865
|
return;
|
|
1989
1866
|
}
|
|
1990
|
-
|
|
1991
1867
|
if (el.hasAttribute('aria-hidden')) {
|
|
1992
1868
|
el.setAttribute('data-previous-aria-hidden', el.getAttribute('aria-hidden'));
|
|
1993
1869
|
}
|
|
1994
|
-
|
|
1995
1870
|
el.setAttribute('aria-hidden', 'true');
|
|
1996
1871
|
});
|
|
1997
1872
|
};
|
|
@@ -2009,10 +1884,12 @@
|
|
|
2009
1884
|
|
|
2010
1885
|
/* istanbul ignore file */
|
|
2011
1886
|
|
|
1887
|
+
// Fix iOS scrolling http://stackoverflow.com/q/39626302
|
|
1888
|
+
|
|
2012
1889
|
const iOSfix = () => {
|
|
2013
|
-
const iOS =
|
|
1890
|
+
const iOS =
|
|
1891
|
+
// @ts-ignore
|
|
2014
1892
|
/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream || navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1;
|
|
2015
|
-
|
|
2016
1893
|
if (iOS && !hasClass(document.body, swalClasses.iosfix)) {
|
|
2017
1894
|
const offset = document.body.scrollTop;
|
|
2018
1895
|
document.body.style.top = "".concat(offset * -1, "px");
|
|
@@ -2021,44 +1898,38 @@
|
|
|
2021
1898
|
addBottomPaddingForTallPopups();
|
|
2022
1899
|
}
|
|
2023
1900
|
};
|
|
1901
|
+
|
|
2024
1902
|
/**
|
|
2025
1903
|
* https://github.com/sweetalert2/sweetalert2/issues/1948
|
|
2026
1904
|
*/
|
|
2027
|
-
|
|
2028
1905
|
const addBottomPaddingForTallPopups = () => {
|
|
2029
1906
|
const ua = navigator.userAgent;
|
|
2030
1907
|
const iOS = !!ua.match(/iPad/i) || !!ua.match(/iPhone/i);
|
|
2031
1908
|
const webkit = !!ua.match(/WebKit/i);
|
|
2032
1909
|
const iOSSafari = iOS && webkit && !ua.match(/CriOS/i);
|
|
2033
|
-
|
|
2034
1910
|
if (iOSSafari) {
|
|
2035
1911
|
const bottomPanelHeight = 44;
|
|
2036
|
-
|
|
2037
1912
|
if (getPopup().scrollHeight > window.innerHeight - bottomPanelHeight) {
|
|
2038
1913
|
getContainer().style.paddingBottom = "".concat(bottomPanelHeight, "px");
|
|
2039
1914
|
}
|
|
2040
1915
|
}
|
|
2041
1916
|
};
|
|
1917
|
+
|
|
2042
1918
|
/**
|
|
2043
1919
|
* https://github.com/sweetalert2/sweetalert2/issues/1246
|
|
2044
1920
|
*/
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
1921
|
const lockBodyScroll = () => {
|
|
2048
1922
|
const container = getContainer();
|
|
2049
1923
|
let preventTouchMove;
|
|
2050
1924
|
/**
|
|
2051
1925
|
* @param {TouchEvent} e
|
|
2052
1926
|
*/
|
|
2053
|
-
|
|
2054
1927
|
container.ontouchstart = e => {
|
|
2055
1928
|
preventTouchMove = shouldPreventTouchMove(e);
|
|
2056
1929
|
};
|
|
2057
1930
|
/**
|
|
2058
1931
|
* @param {TouchEvent} e
|
|
2059
1932
|
*/
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
1933
|
container.ontouchmove = e => {
|
|
2063
1934
|
if (preventTouchMove) {
|
|
2064
1935
|
e.preventDefault();
|
|
@@ -2066,56 +1937,51 @@
|
|
|
2066
1937
|
}
|
|
2067
1938
|
};
|
|
2068
1939
|
};
|
|
1940
|
+
|
|
2069
1941
|
/**
|
|
2070
1942
|
* @param {TouchEvent} event
|
|
2071
1943
|
* @returns {boolean}
|
|
2072
1944
|
*/
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
1945
|
const shouldPreventTouchMove = event => {
|
|
2076
1946
|
const target = event.target;
|
|
2077
1947
|
const container = getContainer();
|
|
2078
|
-
|
|
2079
1948
|
if (isStylus(event) || isZoom(event)) {
|
|
2080
1949
|
return false;
|
|
2081
1950
|
}
|
|
2082
|
-
|
|
2083
1951
|
if (target === container) {
|
|
2084
1952
|
return true;
|
|
2085
1953
|
}
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
target.tagName !== 'TEXTAREA' &&
|
|
2089
|
-
|
|
1954
|
+
if (!isScrollable(container) && target instanceof HTMLElement && target.tagName !== 'INPUT' &&
|
|
1955
|
+
// #1603
|
|
1956
|
+
target.tagName !== 'TEXTAREA' &&
|
|
1957
|
+
// #2266
|
|
1958
|
+
!(isScrollable(getHtmlContainer()) &&
|
|
1959
|
+
// #1944
|
|
2090
1960
|
getHtmlContainer().contains(target))) {
|
|
2091
1961
|
return true;
|
|
2092
1962
|
}
|
|
2093
|
-
|
|
2094
1963
|
return false;
|
|
2095
1964
|
};
|
|
1965
|
+
|
|
2096
1966
|
/**
|
|
2097
1967
|
* https://github.com/sweetalert2/sweetalert2/issues/1786
|
|
2098
1968
|
*
|
|
2099
1969
|
* @param {*} event
|
|
2100
1970
|
* @returns {boolean}
|
|
2101
1971
|
*/
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
1972
|
const isStylus = event => {
|
|
2105
1973
|
return event.touches && event.touches.length && event.touches[0].touchType === 'stylus';
|
|
2106
1974
|
};
|
|
1975
|
+
|
|
2107
1976
|
/**
|
|
2108
1977
|
* https://github.com/sweetalert2/sweetalert2/issues/1891
|
|
2109
1978
|
*
|
|
2110
1979
|
* @param {TouchEvent} event
|
|
2111
1980
|
* @returns {boolean}
|
|
2112
1981
|
*/
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
1982
|
const isZoom = event => {
|
|
2116
1983
|
return event.touches && event.touches.length > 1;
|
|
2117
1984
|
};
|
|
2118
|
-
|
|
2119
1985
|
const undoIOSfix = () => {
|
|
2120
1986
|
if (hasClass(document.body, swalClasses.iosfix)) {
|
|
2121
1987
|
const offset = parseInt(document.body.style.top, 10);
|
|
@@ -2129,9 +1995,8 @@
|
|
|
2129
1995
|
// for queues, do not do this more than once
|
|
2130
1996
|
if (states.previousBodyPadding !== null) {
|
|
2131
1997
|
return;
|
|
2132
|
-
}
|
|
2133
|
-
|
|
2134
|
-
|
|
1998
|
+
}
|
|
1999
|
+
// if the body has overflow
|
|
2135
2000
|
if (document.body.scrollHeight > window.innerHeight) {
|
|
2136
2001
|
// add padding so the content doesn't shift after removal of scrollbar
|
|
2137
2002
|
states.previousBodyPadding = parseInt(window.getComputedStyle(document.body).getPropertyValue('padding-right'));
|
|
@@ -2156,10 +2021,9 @@
|
|
|
2156
2021
|
restoreActiveElement(returnFocus).then(() => triggerDidCloseAndDispose(instance, didClose));
|
|
2157
2022
|
removeKeydownHandler(globalState);
|
|
2158
2023
|
}
|
|
2159
|
-
|
|
2160
|
-
|
|
2024
|
+
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
|
|
2025
|
+
// workaround for #2088
|
|
2161
2026
|
// for some reason removing the container in Safari will scroll the document to bottom
|
|
2162
|
-
|
|
2163
2027
|
if (isSafari) {
|
|
2164
2028
|
container.setAttribute('style', 'display:none !important');
|
|
2165
2029
|
container.removeAttribute('class');
|
|
@@ -2167,25 +2031,20 @@
|
|
|
2167
2031
|
} else {
|
|
2168
2032
|
container.remove();
|
|
2169
2033
|
}
|
|
2170
|
-
|
|
2171
2034
|
if (isModal()) {
|
|
2172
2035
|
undoScrollbar();
|
|
2173
2036
|
undoIOSfix();
|
|
2174
2037
|
unsetAriaHidden();
|
|
2175
2038
|
}
|
|
2176
|
-
|
|
2177
2039
|
removeBodyClasses();
|
|
2178
2040
|
}
|
|
2179
|
-
|
|
2180
2041
|
function removeBodyClasses() {
|
|
2181
2042
|
removeClass([document.documentElement, document.body], [swalClasses.shown, swalClasses['height-auto'], swalClasses['no-backdrop'], swalClasses['toast-shown']]);
|
|
2182
2043
|
}
|
|
2183
|
-
|
|
2184
2044
|
function close(resolveValue) {
|
|
2185
2045
|
resolveValue = prepareResolveValue(resolveValue);
|
|
2186
2046
|
const swalPromiseResolve = privateMethods.swalPromiseResolve.get(this);
|
|
2187
2047
|
const didClose = triggerClosePopup(this);
|
|
2188
|
-
|
|
2189
2048
|
if (this.isAwaitingPromise()) {
|
|
2190
2049
|
// A swal awaiting for a promise (after a click on Confirm or Deny) cannot be dismissed anymore #2335
|
|
2191
2050
|
if (!resolveValue.isDismissed) {
|
|
@@ -2200,20 +2059,15 @@
|
|
|
2200
2059
|
function isAwaitingPromise() {
|
|
2201
2060
|
return !!privateProps.awaitingPromise.get(this);
|
|
2202
2061
|
}
|
|
2203
|
-
|
|
2204
2062
|
const triggerClosePopup = instance => {
|
|
2205
2063
|
const popup = getPopup();
|
|
2206
|
-
|
|
2207
2064
|
if (!popup) {
|
|
2208
2065
|
return false;
|
|
2209
2066
|
}
|
|
2210
|
-
|
|
2211
2067
|
const innerParams = privateProps.innerParams.get(instance);
|
|
2212
|
-
|
|
2213
2068
|
if (!innerParams || hasClass(popup, innerParams.hideClass.popup)) {
|
|
2214
2069
|
return false;
|
|
2215
2070
|
}
|
|
2216
|
-
|
|
2217
2071
|
removeClass(popup, innerParams.showClass.popup);
|
|
2218
2072
|
addClass(popup, innerParams.hideClass.popup);
|
|
2219
2073
|
const backdrop = getContainer();
|
|
@@ -2222,11 +2076,9 @@
|
|
|
2222
2076
|
handlePopupAnimation(instance, popup, innerParams);
|
|
2223
2077
|
return true;
|
|
2224
2078
|
};
|
|
2225
|
-
|
|
2226
2079
|
function rejectPromise(error) {
|
|
2227
2080
|
const rejectPromise = privateMethods.swalPromiseReject.get(this);
|
|
2228
2081
|
handleAwaitingPromise(this);
|
|
2229
|
-
|
|
2230
2082
|
if (rejectPromise) {
|
|
2231
2083
|
// Reject Swal promise
|
|
2232
2084
|
rejectPromise(error);
|
|
@@ -2234,14 +2086,13 @@
|
|
|
2234
2086
|
}
|
|
2235
2087
|
const handleAwaitingPromise = instance => {
|
|
2236
2088
|
if (instance.isAwaitingPromise()) {
|
|
2237
|
-
privateProps.awaitingPromise.delete(instance);
|
|
2238
|
-
|
|
2089
|
+
privateProps.awaitingPromise.delete(instance);
|
|
2090
|
+
// The instance might have been previously partly destroyed, we must resume the destroy process in this case #2335
|
|
2239
2091
|
if (!privateProps.innerParams.get(instance)) {
|
|
2240
2092
|
instance._destroy();
|
|
2241
2093
|
}
|
|
2242
2094
|
}
|
|
2243
2095
|
};
|
|
2244
|
-
|
|
2245
2096
|
const prepareResolveValue = resolveValue => {
|
|
2246
2097
|
// When user calls Swal.close()
|
|
2247
2098
|
if (typeof resolveValue === 'undefined') {
|
|
@@ -2251,23 +2102,19 @@
|
|
|
2251
2102
|
isDismissed: true
|
|
2252
2103
|
};
|
|
2253
2104
|
}
|
|
2254
|
-
|
|
2255
2105
|
return Object.assign({
|
|
2256
2106
|
isConfirmed: false,
|
|
2257
2107
|
isDenied: false,
|
|
2258
2108
|
isDismissed: false
|
|
2259
2109
|
}, resolveValue);
|
|
2260
2110
|
};
|
|
2261
|
-
|
|
2262
2111
|
const handlePopupAnimation = (instance, popup, innerParams) => {
|
|
2263
|
-
const container = getContainer();
|
|
2264
|
-
|
|
2112
|
+
const container = getContainer();
|
|
2113
|
+
// If animation is supported, animate
|
|
2265
2114
|
const animationIsSupported = animationEndEvent && hasCssAnimation(popup);
|
|
2266
|
-
|
|
2267
2115
|
if (typeof innerParams.willClose === 'function') {
|
|
2268
2116
|
innerParams.willClose(popup);
|
|
2269
2117
|
}
|
|
2270
|
-
|
|
2271
2118
|
if (animationIsSupported) {
|
|
2272
2119
|
animatePopup(instance, popup, container, innerParams.returnFocus, innerParams.didClose);
|
|
2273
2120
|
} else {
|
|
@@ -2275,7 +2122,6 @@
|
|
|
2275
2122
|
removePopupAndResetState(instance, container, innerParams.returnFocus, innerParams.didClose);
|
|
2276
2123
|
}
|
|
2277
2124
|
};
|
|
2278
|
-
|
|
2279
2125
|
const animatePopup = (instance, popup, container, returnFocus, didClose) => {
|
|
2280
2126
|
globalState.swalCloseEventFinishedCallback = removePopupAndResetState.bind(null, instance, container, returnFocus, didClose);
|
|
2281
2127
|
popup.addEventListener(animationEndEvent, function (e) {
|
|
@@ -2285,13 +2131,11 @@
|
|
|
2285
2131
|
}
|
|
2286
2132
|
});
|
|
2287
2133
|
};
|
|
2288
|
-
|
|
2289
2134
|
const triggerDidCloseAndDispose = (instance, didClose) => {
|
|
2290
2135
|
setTimeout(() => {
|
|
2291
2136
|
if (typeof didClose === 'function') {
|
|
2292
2137
|
didClose.bind(instance.params)();
|
|
2293
2138
|
}
|
|
2294
|
-
|
|
2295
2139
|
instance._destroy();
|
|
2296
2140
|
});
|
|
2297
2141
|
};
|
|
@@ -2301,28 +2145,24 @@
|
|
|
2301
2145
|
* @param {string[]} buttons
|
|
2302
2146
|
* @param {boolean} disabled
|
|
2303
2147
|
*/
|
|
2304
|
-
|
|
2305
2148
|
function setButtonsDisabled(instance, buttons, disabled) {
|
|
2306
2149
|
const domCache = privateProps.domCache.get(instance);
|
|
2307
2150
|
buttons.forEach(button => {
|
|
2308
2151
|
domCache[button].disabled = disabled;
|
|
2309
2152
|
});
|
|
2310
2153
|
}
|
|
2154
|
+
|
|
2311
2155
|
/**
|
|
2312
2156
|
* @param {HTMLInputElement} input
|
|
2313
2157
|
* @param {boolean} disabled
|
|
2314
2158
|
*/
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
2159
|
function setInputDisabled(input, disabled) {
|
|
2318
2160
|
if (!input) {
|
|
2319
2161
|
return;
|
|
2320
2162
|
}
|
|
2321
|
-
|
|
2322
2163
|
if (input.type === 'radio') {
|
|
2323
2164
|
const radiosContainer = input.parentNode.parentNode;
|
|
2324
2165
|
const radios = radiosContainer.querySelectorAll('input');
|
|
2325
|
-
|
|
2326
2166
|
for (let i = 0; i < radios.length; i++) {
|
|
2327
2167
|
radios[i].disabled = disabled;
|
|
2328
2168
|
}
|
|
@@ -2330,7 +2170,6 @@
|
|
|
2330
2170
|
input.disabled = disabled;
|
|
2331
2171
|
}
|
|
2332
2172
|
}
|
|
2333
|
-
|
|
2334
2173
|
function enableButtons() {
|
|
2335
2174
|
setButtonsDisabled(this, ['confirmButton', 'denyButton', 'cancelButton'], false);
|
|
2336
2175
|
}
|
|
@@ -2344,36 +2183,32 @@
|
|
|
2344
2183
|
setInputDisabled(this.getInput(), true);
|
|
2345
2184
|
}
|
|
2346
2185
|
|
|
2186
|
+
// Show block with validation message
|
|
2347
2187
|
function showValidationMessage(error) {
|
|
2348
2188
|
const domCache = privateProps.domCache.get(this);
|
|
2349
2189
|
const params = privateProps.innerParams.get(this);
|
|
2350
2190
|
setInnerHtml(domCache.validationMessage, error);
|
|
2351
2191
|
domCache.validationMessage.className = swalClasses['validation-message'];
|
|
2352
|
-
|
|
2353
2192
|
if (params.customClass && params.customClass.validationMessage) {
|
|
2354
2193
|
addClass(domCache.validationMessage, params.customClass.validationMessage);
|
|
2355
2194
|
}
|
|
2356
|
-
|
|
2357
2195
|
show(domCache.validationMessage);
|
|
2358
2196
|
const input = this.getInput();
|
|
2359
|
-
|
|
2360
2197
|
if (input) {
|
|
2361
2198
|
input.setAttribute('aria-invalid', true);
|
|
2362
2199
|
input.setAttribute('aria-describedby', swalClasses['validation-message']);
|
|
2363
2200
|
focusInput(input);
|
|
2364
2201
|
addClass(input, swalClasses.inputerror);
|
|
2365
2202
|
}
|
|
2366
|
-
}
|
|
2203
|
+
}
|
|
2367
2204
|
|
|
2205
|
+
// Hide block with validation message
|
|
2368
2206
|
function resetValidationMessage$1() {
|
|
2369
2207
|
const domCache = privateProps.domCache.get(this);
|
|
2370
|
-
|
|
2371
2208
|
if (domCache.validationMessage) {
|
|
2372
2209
|
hide(domCache.validationMessage);
|
|
2373
2210
|
}
|
|
2374
|
-
|
|
2375
2211
|
const input = this.getInput();
|
|
2376
|
-
|
|
2377
2212
|
if (input) {
|
|
2378
2213
|
input.removeAttribute('aria-invalid');
|
|
2379
2214
|
input.removeAttribute('aria-describedby');
|
|
@@ -2478,84 +2313,78 @@
|
|
|
2478
2313
|
const updatableParams = ['allowEscapeKey', 'allowOutsideClick', 'background', 'buttonsStyling', 'cancelButtonAriaLabel', 'cancelButtonColor', 'cancelButtonText', 'closeButtonAriaLabel', 'closeButtonHtml', 'color', 'confirmButtonAriaLabel', 'confirmButtonColor', 'confirmButtonText', 'currentProgressStep', 'customClass', 'denyButtonAriaLabel', 'denyButtonColor', 'denyButtonText', 'didClose', 'didDestroy', 'footer', 'hideClass', 'html', 'icon', 'iconColor', 'iconHtml', 'imageAlt', 'imageHeight', 'imageUrl', 'imageWidth', 'preConfirm', 'preDeny', 'progressSteps', 'returnFocus', 'reverseButtons', 'showCancelButton', 'showCloseButton', 'showConfirmButton', 'showDenyButton', 'text', 'title', 'titleText', 'willClose'];
|
|
2479
2314
|
const deprecatedParams = {};
|
|
2480
2315
|
const toastIncompatibleParams = ['allowOutsideClick', 'allowEnterKey', 'backdrop', 'focusConfirm', 'focusDeny', 'focusCancel', 'returnFocus', 'heightAuto', 'keydownListenerCapture'];
|
|
2316
|
+
|
|
2481
2317
|
/**
|
|
2482
2318
|
* Is valid parameter
|
|
2483
2319
|
*
|
|
2484
2320
|
* @param {string} paramName
|
|
2485
2321
|
* @returns {boolean}
|
|
2486
2322
|
*/
|
|
2487
|
-
|
|
2488
2323
|
const isValidParameter = paramName => {
|
|
2489
2324
|
return Object.prototype.hasOwnProperty.call(defaultParams, paramName);
|
|
2490
2325
|
};
|
|
2326
|
+
|
|
2491
2327
|
/**
|
|
2492
2328
|
* Is valid parameter for Swal.update() method
|
|
2493
2329
|
*
|
|
2494
2330
|
* @param {string} paramName
|
|
2495
2331
|
* @returns {boolean}
|
|
2496
2332
|
*/
|
|
2497
|
-
|
|
2498
2333
|
const isUpdatableParameter = paramName => {
|
|
2499
2334
|
return updatableParams.indexOf(paramName) !== -1;
|
|
2500
2335
|
};
|
|
2336
|
+
|
|
2501
2337
|
/**
|
|
2502
2338
|
* Is deprecated parameter
|
|
2503
2339
|
*
|
|
2504
2340
|
* @param {string} paramName
|
|
2505
2341
|
* @returns {string | undefined}
|
|
2506
2342
|
*/
|
|
2507
|
-
|
|
2508
2343
|
const isDeprecatedParameter = paramName => {
|
|
2509
2344
|
return deprecatedParams[paramName];
|
|
2510
2345
|
};
|
|
2346
|
+
|
|
2511
2347
|
/**
|
|
2512
2348
|
* @param {string} param
|
|
2513
2349
|
*/
|
|
2514
|
-
|
|
2515
2350
|
const checkIfParamIsValid = param => {
|
|
2516
2351
|
if (!isValidParameter(param)) {
|
|
2517
2352
|
warn("Unknown parameter \"".concat(param, "\""));
|
|
2518
2353
|
}
|
|
2519
2354
|
};
|
|
2355
|
+
|
|
2520
2356
|
/**
|
|
2521
2357
|
* @param {string} param
|
|
2522
2358
|
*/
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
2359
|
const checkIfToastParamIsValid = param => {
|
|
2526
2360
|
if (toastIncompatibleParams.includes(param)) {
|
|
2527
2361
|
warn("The parameter \"".concat(param, "\" is incompatible with toasts"));
|
|
2528
2362
|
}
|
|
2529
2363
|
};
|
|
2364
|
+
|
|
2530
2365
|
/**
|
|
2531
2366
|
* @param {string} param
|
|
2532
2367
|
*/
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
2368
|
const checkIfParamIsDeprecated = param => {
|
|
2536
2369
|
if (isDeprecatedParameter(param)) {
|
|
2537
2370
|
warnAboutDeprecation(param, isDeprecatedParameter(param));
|
|
2538
2371
|
}
|
|
2539
2372
|
};
|
|
2373
|
+
|
|
2540
2374
|
/**
|
|
2541
2375
|
* Show relevant warnings for given params
|
|
2542
2376
|
*
|
|
2543
2377
|
* @param {SweetAlertOptions} params
|
|
2544
2378
|
*/
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
2379
|
const showWarningsForParams = params => {
|
|
2548
|
-
if (
|
|
2380
|
+
if (params.backdrop === false && params.allowOutsideClick) {
|
|
2549
2381
|
warn('"allowOutsideClick" parameter requires `backdrop` parameter to be set to `true`');
|
|
2550
2382
|
}
|
|
2551
|
-
|
|
2552
2383
|
for (const param in params) {
|
|
2553
2384
|
checkIfParamIsValid(param);
|
|
2554
|
-
|
|
2555
2385
|
if (params.toast) {
|
|
2556
2386
|
checkIfToastParamIsValid(param);
|
|
2557
2387
|
}
|
|
2558
|
-
|
|
2559
2388
|
checkIfParamIsDeprecated(param);
|
|
2560
2389
|
}
|
|
2561
2390
|
};
|
|
@@ -2563,15 +2392,12 @@
|
|
|
2563
2392
|
/**
|
|
2564
2393
|
* Updates popup parameters.
|
|
2565
2394
|
*/
|
|
2566
|
-
|
|
2567
2395
|
function update(params) {
|
|
2568
2396
|
const popup = getPopup();
|
|
2569
2397
|
const innerParams = privateProps.innerParams.get(this);
|
|
2570
|
-
|
|
2571
2398
|
if (!popup || hasClass(popup, innerParams.hideClass.popup)) {
|
|
2572
2399
|
return warn("You're trying to update the closed or closing popup, that won't work. Use the update() method in preConfirm parameter or show a new popup.");
|
|
2573
2400
|
}
|
|
2574
|
-
|
|
2575
2401
|
const validUpdatableParams = filterValidParams(params);
|
|
2576
2402
|
const updatedParams = Object.assign({}, innerParams, validUpdatableParams);
|
|
2577
2403
|
render(this, updatedParams);
|
|
@@ -2584,7 +2410,6 @@
|
|
|
2584
2410
|
}
|
|
2585
2411
|
});
|
|
2586
2412
|
}
|
|
2587
|
-
|
|
2588
2413
|
const filterValidParams = params => {
|
|
2589
2414
|
const validUpdatableParams = {};
|
|
2590
2415
|
Object.keys(params).forEach(param => {
|
|
@@ -2600,45 +2425,40 @@
|
|
|
2600
2425
|
function _destroy() {
|
|
2601
2426
|
const domCache = privateProps.domCache.get(this);
|
|
2602
2427
|
const innerParams = privateProps.innerParams.get(this);
|
|
2603
|
-
|
|
2604
2428
|
if (!innerParams) {
|
|
2605
2429
|
disposeWeakMaps(this); // The WeakMaps might have been partly destroyed, we must recall it to dispose any remaining WeakMaps #2335
|
|
2606
|
-
|
|
2607
2430
|
return; // This instance has already been destroyed
|
|
2608
|
-
}
|
|
2609
|
-
|
|
2431
|
+
}
|
|
2610
2432
|
|
|
2433
|
+
// Check if there is another Swal closing
|
|
2611
2434
|
if (domCache.popup && globalState.swalCloseEventFinishedCallback) {
|
|
2612
2435
|
globalState.swalCloseEventFinishedCallback();
|
|
2613
2436
|
delete globalState.swalCloseEventFinishedCallback;
|
|
2614
2437
|
}
|
|
2615
|
-
|
|
2616
2438
|
if (typeof innerParams.didDestroy === 'function') {
|
|
2617
2439
|
innerParams.didDestroy();
|
|
2618
2440
|
}
|
|
2619
|
-
|
|
2620
2441
|
disposeSwal(this);
|
|
2621
2442
|
}
|
|
2443
|
+
|
|
2622
2444
|
/**
|
|
2623
2445
|
* @param {SweetAlert2} instance
|
|
2624
2446
|
*/
|
|
2625
|
-
|
|
2626
2447
|
const disposeSwal = instance => {
|
|
2627
|
-
disposeWeakMaps(instance);
|
|
2448
|
+
disposeWeakMaps(instance);
|
|
2449
|
+
// Unset this.params so GC will dispose it (#1569)
|
|
2628
2450
|
// @ts-ignore
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2451
|
+
delete instance.params;
|
|
2452
|
+
// Unset globalState props so GC will dispose globalState (#1569)
|
|
2632
2453
|
delete globalState.keydownHandler;
|
|
2633
|
-
delete globalState.keydownTarget;
|
|
2634
|
-
|
|
2454
|
+
delete globalState.keydownTarget;
|
|
2455
|
+
// Unset currentInstance
|
|
2635
2456
|
delete globalState.currentInstance;
|
|
2636
2457
|
};
|
|
2458
|
+
|
|
2637
2459
|
/**
|
|
2638
2460
|
* @param {SweetAlert2} instance
|
|
2639
2461
|
*/
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
2462
|
const disposeWeakMaps = instance => {
|
|
2643
2463
|
// If the current instance is awaiting a promise result, we keep the privateMethods to call them once the promise result is retrieved #2335
|
|
2644
2464
|
// @ts-ignore
|
|
@@ -2650,12 +2470,11 @@
|
|
|
2650
2470
|
unsetWeakMaps(privateProps, instance);
|
|
2651
2471
|
}
|
|
2652
2472
|
};
|
|
2473
|
+
|
|
2653
2474
|
/**
|
|
2654
2475
|
* @param {object} obj
|
|
2655
2476
|
* @param {SweetAlert2} instance
|
|
2656
2477
|
*/
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
2478
|
const unsetWeakMaps = (obj, instance) => {
|
|
2660
2479
|
for (const i in obj) {
|
|
2661
2480
|
obj[i].delete(instance);
|
|
@@ -2690,44 +2509,35 @@
|
|
|
2690
2509
|
* Shows loader (spinner), this is useful with AJAX requests.
|
|
2691
2510
|
* By default the loader be shown instead of the "Confirm" button.
|
|
2692
2511
|
*/
|
|
2693
|
-
|
|
2694
2512
|
const showLoading = buttonToReplace => {
|
|
2695
2513
|
let popup = getPopup();
|
|
2696
|
-
|
|
2697
2514
|
if (!popup) {
|
|
2698
2515
|
new Swal(); // eslint-disable-line no-new
|
|
2699
2516
|
}
|
|
2700
2517
|
|
|
2701
2518
|
popup = getPopup();
|
|
2702
2519
|
const loader = getLoader();
|
|
2703
|
-
|
|
2704
2520
|
if (isToast()) {
|
|
2705
2521
|
hide(getIcon());
|
|
2706
2522
|
} else {
|
|
2707
2523
|
replaceButton(popup, buttonToReplace);
|
|
2708
2524
|
}
|
|
2709
|
-
|
|
2710
2525
|
show(loader);
|
|
2711
2526
|
popup.setAttribute('data-loading', 'true');
|
|
2712
2527
|
popup.setAttribute('aria-busy', 'true');
|
|
2713
2528
|
popup.focus();
|
|
2714
2529
|
};
|
|
2715
|
-
|
|
2716
2530
|
const replaceButton = (popup, buttonToReplace) => {
|
|
2717
2531
|
const actions = getActions();
|
|
2718
2532
|
const loader = getLoader();
|
|
2719
|
-
|
|
2720
2533
|
if (!buttonToReplace && isVisible(getConfirmButton())) {
|
|
2721
2534
|
buttonToReplace = getConfirmButton();
|
|
2722
2535
|
}
|
|
2723
|
-
|
|
2724
2536
|
show(actions);
|
|
2725
|
-
|
|
2726
2537
|
if (buttonToReplace) {
|
|
2727
2538
|
hide(buttonToReplace);
|
|
2728
2539
|
loader.setAttribute('data-button-to-replace', buttonToReplace.className);
|
|
2729
2540
|
}
|
|
2730
|
-
|
|
2731
2541
|
loader.parentNode.insertBefore(loader, buttonToReplace);
|
|
2732
2542
|
addClass([popup, actions], swalClasses.loading);
|
|
2733
2543
|
};
|
|
@@ -2740,7 +2550,6 @@
|
|
|
2740
2550
|
* @param {SweetAlert2} instance
|
|
2741
2551
|
* @param {SweetAlertOptions} params
|
|
2742
2552
|
*/
|
|
2743
|
-
|
|
2744
2553
|
const handleInputOptionsAndValue = (instance, params) => {
|
|
2745
2554
|
if (params.input === 'select' || params.input === 'radio') {
|
|
2746
2555
|
handleInputOptions(instance, params);
|
|
@@ -2749,69 +2558,59 @@
|
|
|
2749
2558
|
handleInputValue(instance, params);
|
|
2750
2559
|
}
|
|
2751
2560
|
};
|
|
2561
|
+
|
|
2752
2562
|
/**
|
|
2753
2563
|
* @param {SweetAlert2} instance
|
|
2754
2564
|
* @param {SweetAlertOptions} innerParams
|
|
2755
2565
|
* @returns {string | number | File | FileList | null}
|
|
2756
2566
|
*/
|
|
2757
|
-
|
|
2758
2567
|
const getInputValue = (instance, innerParams) => {
|
|
2759
2568
|
const input = instance.getInput();
|
|
2760
|
-
|
|
2761
2569
|
if (!input) {
|
|
2762
2570
|
return null;
|
|
2763
2571
|
}
|
|
2764
|
-
|
|
2765
2572
|
switch (innerParams.input) {
|
|
2766
2573
|
case 'checkbox':
|
|
2767
2574
|
return getCheckboxValue(input);
|
|
2768
|
-
|
|
2769
2575
|
case 'radio':
|
|
2770
2576
|
return getRadioValue(input);
|
|
2771
|
-
|
|
2772
2577
|
case 'file':
|
|
2773
2578
|
return getFileValue(input);
|
|
2774
|
-
|
|
2775
2579
|
default:
|
|
2776
2580
|
return innerParams.inputAutoTrim ? input.value.trim() : input.value;
|
|
2777
2581
|
}
|
|
2778
2582
|
};
|
|
2583
|
+
|
|
2779
2584
|
/**
|
|
2780
2585
|
* @param {HTMLInputElement} input
|
|
2781
2586
|
* @returns {number}
|
|
2782
2587
|
*/
|
|
2783
|
-
|
|
2784
2588
|
const getCheckboxValue = input => input.checked ? 1 : 0;
|
|
2589
|
+
|
|
2785
2590
|
/**
|
|
2786
2591
|
* @param {HTMLInputElement} input
|
|
2787
2592
|
* @returns {string | null}
|
|
2788
2593
|
*/
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
2594
|
const getRadioValue = input => input.checked ? input.value : null;
|
|
2595
|
+
|
|
2792
2596
|
/**
|
|
2793
2597
|
* @param {HTMLInputElement} input
|
|
2794
2598
|
* @returns {FileList | File | null}
|
|
2795
2599
|
*/
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
2600
|
const getFileValue = input => input.files.length ? input.getAttribute('multiple') !== null ? input.files : input.files[0] : null;
|
|
2601
|
+
|
|
2799
2602
|
/**
|
|
2800
2603
|
* @param {SweetAlert2} instance
|
|
2801
2604
|
* @param {SweetAlertOptions} params
|
|
2802
2605
|
*/
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
2606
|
const handleInputOptions = (instance, params) => {
|
|
2806
2607
|
const popup = getPopup();
|
|
2807
2608
|
/**
|
|
2808
2609
|
* @param {Record<string, any>} inputOptions
|
|
2809
2610
|
*/
|
|
2810
|
-
|
|
2811
2611
|
const processInputOptions = inputOptions => {
|
|
2812
2612
|
populateInputOptions[params.input](popup, formatInputOptions(inputOptions), params);
|
|
2813
2613
|
};
|
|
2814
|
-
|
|
2815
2614
|
if (hasToPromiseFn(params.inputOptions) || isPromise(params.inputOptions)) {
|
|
2816
2615
|
showLoading(getConfirmButton());
|
|
2817
2616
|
asPromise(params.inputOptions).then(inputOptions => {
|
|
@@ -2824,12 +2623,11 @@
|
|
|
2824
2623
|
error("Unexpected type of inputOptions! Expected object, Map or Promise, got ".concat(typeof params.inputOptions));
|
|
2825
2624
|
}
|
|
2826
2625
|
};
|
|
2626
|
+
|
|
2827
2627
|
/**
|
|
2828
2628
|
* @param {SweetAlert2} instance
|
|
2829
2629
|
* @param {SweetAlertOptions} params
|
|
2830
2630
|
*/
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
2631
|
const handleInputValue = (instance, params) => {
|
|
2834
2632
|
const input = instance.getInput();
|
|
2835
2633
|
hide(input);
|
|
@@ -2846,7 +2644,6 @@
|
|
|
2846
2644
|
instance.hideLoading();
|
|
2847
2645
|
});
|
|
2848
2646
|
};
|
|
2849
|
-
|
|
2850
2647
|
const populateInputOptions = {
|
|
2851
2648
|
/**
|
|
2852
2649
|
* @param {HTMLElement} popup
|
|
@@ -2860,7 +2657,6 @@
|
|
|
2860
2657
|
* @param {string} optionLabel
|
|
2861
2658
|
* @param {string} optionValue
|
|
2862
2659
|
*/
|
|
2863
|
-
|
|
2864
2660
|
const renderOption = (parent, optionLabel, optionValue) => {
|
|
2865
2661
|
const option = document.createElement('option');
|
|
2866
2662
|
option.value = optionValue;
|
|
@@ -2868,20 +2664,18 @@
|
|
|
2868
2664
|
option.selected = isSelected(optionValue, params.inputValue);
|
|
2869
2665
|
parent.appendChild(option);
|
|
2870
2666
|
};
|
|
2871
|
-
|
|
2872
2667
|
inputOptions.forEach(inputOption => {
|
|
2873
2668
|
const optionValue = inputOption[0];
|
|
2874
|
-
const optionLabel = inputOption[1];
|
|
2669
|
+
const optionLabel = inputOption[1];
|
|
2670
|
+
// <optgroup> spec:
|
|
2875
2671
|
// https://www.w3.org/TR/html401/interact/forms.html#h-17.6
|
|
2876
2672
|
// "...all OPTGROUP elements must be specified directly within a SELECT element (i.e., groups may not be nested)..."
|
|
2877
2673
|
// check whether this is a <optgroup>
|
|
2878
|
-
|
|
2879
2674
|
if (Array.isArray(optionLabel)) {
|
|
2880
2675
|
// if it is an array, then it is an <optgroup>
|
|
2881
2676
|
const optgroup = document.createElement('optgroup');
|
|
2882
2677
|
optgroup.label = optionValue;
|
|
2883
2678
|
optgroup.disabled = false; // not configurable for now
|
|
2884
|
-
|
|
2885
2679
|
select.appendChild(optgroup);
|
|
2886
2680
|
optionLabel.forEach(o => renderOption(optgroup, o[1], o[0]));
|
|
2887
2681
|
} else {
|
|
@@ -2891,7 +2685,6 @@
|
|
|
2891
2685
|
});
|
|
2892
2686
|
select.focus();
|
|
2893
2687
|
},
|
|
2894
|
-
|
|
2895
2688
|
/**
|
|
2896
2689
|
* @param {HTMLElement} popup
|
|
2897
2690
|
* @param {Record<string, any>} inputOptions
|
|
@@ -2907,11 +2700,9 @@
|
|
|
2907
2700
|
radioInput.type = 'radio';
|
|
2908
2701
|
radioInput.name = swalClasses.radio;
|
|
2909
2702
|
radioInput.value = radioValue;
|
|
2910
|
-
|
|
2911
2703
|
if (isSelected(radioValue, params.inputValue)) {
|
|
2912
2704
|
radioInput.checked = true;
|
|
2913
2705
|
}
|
|
2914
|
-
|
|
2915
2706
|
const label = document.createElement('span');
|
|
2916
2707
|
setInnerHtml(label, radioLabel);
|
|
2917
2708
|
label.className = swalClasses.label;
|
|
@@ -2920,55 +2711,47 @@
|
|
|
2920
2711
|
radio.appendChild(radioLabelElement);
|
|
2921
2712
|
});
|
|
2922
2713
|
const radios = radio.querySelectorAll('input');
|
|
2923
|
-
|
|
2924
2714
|
if (radios.length) {
|
|
2925
2715
|
radios[0].focus();
|
|
2926
2716
|
}
|
|
2927
2717
|
}
|
|
2928
2718
|
};
|
|
2719
|
+
|
|
2929
2720
|
/**
|
|
2930
2721
|
* Converts `inputOptions` into an array of `[value, label]`s
|
|
2931
2722
|
*
|
|
2932
2723
|
* @param {Record<string, any>} inputOptions
|
|
2933
2724
|
* @returns {Array<Array<string>>}
|
|
2934
2725
|
*/
|
|
2935
|
-
|
|
2936
2726
|
const formatInputOptions = inputOptions => {
|
|
2937
2727
|
const result = [];
|
|
2938
|
-
|
|
2939
2728
|
if (typeof Map !== 'undefined' && inputOptions instanceof Map) {
|
|
2940
2729
|
inputOptions.forEach((value, key) => {
|
|
2941
2730
|
let valueFormatted = value;
|
|
2942
|
-
|
|
2943
2731
|
if (typeof valueFormatted === 'object') {
|
|
2944
2732
|
// case of <optgroup>
|
|
2945
2733
|
valueFormatted = formatInputOptions(valueFormatted);
|
|
2946
2734
|
}
|
|
2947
|
-
|
|
2948
2735
|
result.push([key, valueFormatted]);
|
|
2949
2736
|
});
|
|
2950
2737
|
} else {
|
|
2951
2738
|
Object.keys(inputOptions).forEach(key => {
|
|
2952
2739
|
let valueFormatted = inputOptions[key];
|
|
2953
|
-
|
|
2954
2740
|
if (typeof valueFormatted === 'object') {
|
|
2955
2741
|
// case of <optgroup>
|
|
2956
2742
|
valueFormatted = formatInputOptions(valueFormatted);
|
|
2957
2743
|
}
|
|
2958
|
-
|
|
2959
2744
|
result.push([key, valueFormatted]);
|
|
2960
2745
|
});
|
|
2961
2746
|
}
|
|
2962
|
-
|
|
2963
2747
|
return result;
|
|
2964
2748
|
};
|
|
2749
|
+
|
|
2965
2750
|
/**
|
|
2966
2751
|
* @param {string} optionValue
|
|
2967
2752
|
* @param {InputValue | Promise<InputValue> | { toPromise: () => InputValue }} inputValue
|
|
2968
2753
|
* @returns {boolean}
|
|
2969
2754
|
*/
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
2755
|
const isSelected = (optionValue, inputValue) => {
|
|
2973
2756
|
return inputValue && inputValue.toString() === optionValue.toString();
|
|
2974
2757
|
};
|
|
@@ -2976,55 +2759,49 @@
|
|
|
2976
2759
|
/**
|
|
2977
2760
|
* @param {SweetAlert2} instance
|
|
2978
2761
|
*/
|
|
2979
|
-
|
|
2980
2762
|
const handleConfirmButtonClick = instance => {
|
|
2981
2763
|
const innerParams = privateProps.innerParams.get(instance);
|
|
2982
2764
|
instance.disableButtons();
|
|
2983
|
-
|
|
2984
2765
|
if (innerParams.input) {
|
|
2985
2766
|
handleConfirmOrDenyWithInput(instance, 'confirm');
|
|
2986
2767
|
} else {
|
|
2987
2768
|
confirm(instance, true);
|
|
2988
2769
|
}
|
|
2989
2770
|
};
|
|
2771
|
+
|
|
2990
2772
|
/**
|
|
2991
2773
|
* @param {SweetAlert2} instance
|
|
2992
2774
|
*/
|
|
2993
|
-
|
|
2994
2775
|
const handleDenyButtonClick = instance => {
|
|
2995
2776
|
const innerParams = privateProps.innerParams.get(instance);
|
|
2996
2777
|
instance.disableButtons();
|
|
2997
|
-
|
|
2998
2778
|
if (innerParams.returnInputValueOnDeny) {
|
|
2999
2779
|
handleConfirmOrDenyWithInput(instance, 'deny');
|
|
3000
2780
|
} else {
|
|
3001
2781
|
deny(instance, false);
|
|
3002
2782
|
}
|
|
3003
2783
|
};
|
|
2784
|
+
|
|
3004
2785
|
/**
|
|
3005
2786
|
* @param {SweetAlert2} instance
|
|
3006
2787
|
* @param {Function} dismissWith
|
|
3007
2788
|
*/
|
|
3008
|
-
|
|
3009
2789
|
const handleCancelButtonClick = (instance, dismissWith) => {
|
|
3010
2790
|
instance.disableButtons();
|
|
3011
2791
|
dismissWith(DismissReason.cancel);
|
|
3012
2792
|
};
|
|
2793
|
+
|
|
3013
2794
|
/**
|
|
3014
2795
|
* @param {SweetAlert2} instance
|
|
3015
2796
|
* @param {'confirm' | 'deny'} type
|
|
3016
2797
|
*/
|
|
3017
|
-
|
|
3018
2798
|
const handleConfirmOrDenyWithInput = (instance, type) => {
|
|
3019
2799
|
const innerParams = privateProps.innerParams.get(instance);
|
|
3020
|
-
|
|
3021
2800
|
if (!innerParams.input) {
|
|
3022
2801
|
error("The \"input\" parameter is needed to be set when using returnInputValueOn".concat(capitalizeFirstLetter(type)));
|
|
3023
2802
|
return;
|
|
3024
2803
|
}
|
|
3025
|
-
|
|
3026
2804
|
const inputValue = getInputValue(instance, innerParams);
|
|
3027
|
-
|
|
3028
2805
|
if (innerParams.inputValidator) {
|
|
3029
2806
|
handleInputValidator(instance, inputValue, type);
|
|
3030
2807
|
} else if (!instance.getInput().checkValidity()) {
|
|
@@ -3036,13 +2813,12 @@
|
|
|
3036
2813
|
confirm(instance, inputValue);
|
|
3037
2814
|
}
|
|
3038
2815
|
};
|
|
2816
|
+
|
|
3039
2817
|
/**
|
|
3040
2818
|
* @param {SweetAlert2} instance
|
|
3041
2819
|
* @param {string | number | File | FileList | null} inputValue
|
|
3042
2820
|
* @param {'confirm' | 'deny'} type
|
|
3043
2821
|
*/
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
2822
|
const handleInputValidator = (instance, inputValue, type) => {
|
|
3047
2823
|
const innerParams = privateProps.innerParams.get(instance);
|
|
3048
2824
|
instance.disableInput();
|
|
@@ -3050,7 +2826,6 @@
|
|
|
3050
2826
|
validationPromise.then(validationMessage => {
|
|
3051
2827
|
instance.enableButtons();
|
|
3052
2828
|
instance.enableInput();
|
|
3053
|
-
|
|
3054
2829
|
if (validationMessage) {
|
|
3055
2830
|
instance.showValidationMessage(validationMessage);
|
|
3056
2831
|
} else if (type === 'deny') {
|
|
@@ -3060,22 +2835,18 @@
|
|
|
3060
2835
|
}
|
|
3061
2836
|
});
|
|
3062
2837
|
};
|
|
2838
|
+
|
|
3063
2839
|
/**
|
|
3064
2840
|
* @param {SweetAlert2} instance
|
|
3065
2841
|
* @param {any} value
|
|
3066
2842
|
*/
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
2843
|
const deny = (instance, value) => {
|
|
3070
2844
|
const innerParams = privateProps.innerParams.get(instance || undefined);
|
|
3071
|
-
|
|
3072
2845
|
if (innerParams.showLoaderOnDeny) {
|
|
3073
2846
|
showLoading(getDenyButton());
|
|
3074
2847
|
}
|
|
3075
|
-
|
|
3076
2848
|
if (innerParams.preDeny) {
|
|
3077
2849
|
privateProps.awaitingPromise.set(instance || undefined, true); // Flagging the instance as awaiting a promise so it's own promise's reject/resolve methods doesn't get destroyed until the result from this preDeny's promise is received
|
|
3078
|
-
|
|
3079
2850
|
const preDenyPromise = Promise.resolve().then(() => asPromise(innerParams.preDeny(value, innerParams.validationMessage)));
|
|
3080
2851
|
preDenyPromise.then(preDenyValue => {
|
|
3081
2852
|
if (preDenyValue === false) {
|
|
@@ -3095,47 +2866,41 @@
|
|
|
3095
2866
|
});
|
|
3096
2867
|
}
|
|
3097
2868
|
};
|
|
2869
|
+
|
|
3098
2870
|
/**
|
|
3099
2871
|
* @param {SweetAlert2} instance
|
|
3100
2872
|
* @param {any} value
|
|
3101
2873
|
*/
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
2874
|
const succeedWith = (instance, value) => {
|
|
3105
2875
|
instance.close({
|
|
3106
2876
|
isConfirmed: true,
|
|
3107
2877
|
value
|
|
3108
2878
|
});
|
|
3109
2879
|
};
|
|
2880
|
+
|
|
3110
2881
|
/**
|
|
3111
2882
|
*
|
|
3112
2883
|
* @param {SweetAlert2} instance
|
|
3113
2884
|
* @param {string} error
|
|
3114
2885
|
*/
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
2886
|
const rejectWith = (instance, error$$1) => {
|
|
3118
2887
|
// @ts-ignore
|
|
3119
2888
|
instance.rejectPromise(error$$1);
|
|
3120
2889
|
};
|
|
2890
|
+
|
|
3121
2891
|
/**
|
|
3122
2892
|
*
|
|
3123
2893
|
* @param {SweetAlert2} instance
|
|
3124
2894
|
* @param {any} value
|
|
3125
2895
|
*/
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
2896
|
const confirm = (instance, value) => {
|
|
3129
2897
|
const innerParams = privateProps.innerParams.get(instance || undefined);
|
|
3130
|
-
|
|
3131
2898
|
if (innerParams.showLoaderOnConfirm) {
|
|
3132
2899
|
showLoading();
|
|
3133
2900
|
}
|
|
3134
|
-
|
|
3135
2901
|
if (innerParams.preConfirm) {
|
|
3136
2902
|
instance.resetValidationMessage();
|
|
3137
2903
|
privateProps.awaitingPromise.set(instance || undefined, true); // Flagging the instance as awaiting a promise so it's own promise's reject/resolve methods doesn't get destroyed until the result from this preConfirm's promise is received
|
|
3138
|
-
|
|
3139
2904
|
const preConfirmPromise = Promise.resolve().then(() => asPromise(innerParams.preConfirm(value, innerParams.validationMessage)));
|
|
3140
2905
|
preConfirmPromise.then(preConfirmValue => {
|
|
3141
2906
|
if (isVisible(getValidationMessage()) || preConfirmValue === false) {
|
|
@@ -3152,77 +2917,67 @@
|
|
|
3152
2917
|
|
|
3153
2918
|
const handlePopupClick = (instance, domCache, dismissWith) => {
|
|
3154
2919
|
const innerParams = privateProps.innerParams.get(instance);
|
|
3155
|
-
|
|
3156
2920
|
if (innerParams.toast) {
|
|
3157
2921
|
handleToastClick(instance, domCache, dismissWith);
|
|
3158
2922
|
} else {
|
|
3159
2923
|
// Ignore click events that had mousedown on the popup but mouseup on the container
|
|
3160
2924
|
// This can happen when the user drags a slider
|
|
3161
|
-
handleModalMousedown(domCache);
|
|
2925
|
+
handleModalMousedown(domCache);
|
|
3162
2926
|
|
|
2927
|
+
// Ignore click events that had mousedown on the container but mouseup on the popup
|
|
3163
2928
|
handleContainerMousedown(domCache);
|
|
3164
2929
|
handleModalClick(instance, domCache, dismissWith);
|
|
3165
2930
|
}
|
|
3166
2931
|
};
|
|
3167
|
-
|
|
3168
2932
|
const handleToastClick = (instance, domCache, dismissWith) => {
|
|
3169
2933
|
// Closing toast by internal click
|
|
3170
2934
|
domCache.popup.onclick = () => {
|
|
3171
2935
|
const innerParams = privateProps.innerParams.get(instance);
|
|
3172
|
-
|
|
3173
2936
|
if (innerParams && (isAnyButtonShown(innerParams) || innerParams.timer || innerParams.input)) {
|
|
3174
2937
|
return;
|
|
3175
2938
|
}
|
|
3176
|
-
|
|
3177
2939
|
dismissWith(DismissReason.close);
|
|
3178
2940
|
};
|
|
3179
2941
|
};
|
|
2942
|
+
|
|
3180
2943
|
/**
|
|
3181
2944
|
* @param {*} innerParams
|
|
3182
2945
|
* @returns {boolean}
|
|
3183
2946
|
*/
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
2947
|
const isAnyButtonShown = innerParams => {
|
|
3187
2948
|
return innerParams.showConfirmButton || innerParams.showDenyButton || innerParams.showCancelButton || innerParams.showCloseButton;
|
|
3188
2949
|
};
|
|
3189
|
-
|
|
3190
2950
|
let ignoreOutsideClick = false;
|
|
3191
|
-
|
|
3192
2951
|
const handleModalMousedown = domCache => {
|
|
3193
2952
|
domCache.popup.onmousedown = () => {
|
|
3194
2953
|
domCache.container.onmouseup = function (e) {
|
|
3195
|
-
domCache.container.onmouseup = undefined;
|
|
2954
|
+
domCache.container.onmouseup = undefined;
|
|
2955
|
+
// We only check if the mouseup target is the container because usually it doesn't
|
|
3196
2956
|
// have any other direct children aside of the popup
|
|
3197
|
-
|
|
3198
2957
|
if (e.target === domCache.container) {
|
|
3199
2958
|
ignoreOutsideClick = true;
|
|
3200
2959
|
}
|
|
3201
2960
|
};
|
|
3202
2961
|
};
|
|
3203
2962
|
};
|
|
3204
|
-
|
|
3205
2963
|
const handleContainerMousedown = domCache => {
|
|
3206
2964
|
domCache.container.onmousedown = () => {
|
|
3207
2965
|
domCache.popup.onmouseup = function (e) {
|
|
3208
|
-
domCache.popup.onmouseup = undefined;
|
|
3209
|
-
|
|
2966
|
+
domCache.popup.onmouseup = undefined;
|
|
2967
|
+
// We also need to check if the mouseup target is a child of the popup
|
|
3210
2968
|
if (e.target === domCache.popup || domCache.popup.contains(e.target)) {
|
|
3211
2969
|
ignoreOutsideClick = true;
|
|
3212
2970
|
}
|
|
3213
2971
|
};
|
|
3214
2972
|
};
|
|
3215
2973
|
};
|
|
3216
|
-
|
|
3217
2974
|
const handleModalClick = (instance, domCache, dismissWith) => {
|
|
3218
2975
|
domCache.container.onclick = e => {
|
|
3219
2976
|
const innerParams = privateProps.innerParams.get(instance);
|
|
3220
|
-
|
|
3221
2977
|
if (ignoreOutsideClick) {
|
|
3222
2978
|
ignoreOutsideClick = false;
|
|
3223
2979
|
return;
|
|
3224
2980
|
}
|
|
3225
|
-
|
|
3226
2981
|
if (e.target === domCache.container && callIfFunction(innerParams.allowOutsideClick)) {
|
|
3227
2982
|
dismissWith(DismissReason.backdrop);
|
|
3228
2983
|
}
|
|
@@ -3230,18 +2985,14 @@
|
|
|
3230
2985
|
};
|
|
3231
2986
|
|
|
3232
2987
|
const isJqueryElement = elem => typeof elem === 'object' && elem.jquery;
|
|
3233
|
-
|
|
3234
2988
|
const isElement = elem => elem instanceof Element || isJqueryElement(elem);
|
|
3235
|
-
|
|
3236
2989
|
const argsToParams = args => {
|
|
3237
2990
|
const params = {};
|
|
3238
|
-
|
|
3239
2991
|
if (typeof args[0] === 'object' && !isElement(args[0])) {
|
|
3240
2992
|
Object.assign(params, args[0]);
|
|
3241
2993
|
} else {
|
|
3242
2994
|
['title', 'html', 'icon'].forEach((name, index) => {
|
|
3243
2995
|
const arg = args[index];
|
|
3244
|
-
|
|
3245
2996
|
if (typeof arg === 'string' || isElement(arg)) {
|
|
3246
2997
|
params[name] = arg;
|
|
3247
2998
|
} else if (arg !== undefined) {
|
|
@@ -3249,17 +3000,14 @@
|
|
|
3249
3000
|
}
|
|
3250
3001
|
});
|
|
3251
3002
|
}
|
|
3252
|
-
|
|
3253
3003
|
return params;
|
|
3254
3004
|
};
|
|
3255
3005
|
|
|
3256
3006
|
function fire() {
|
|
3257
3007
|
const Swal = this; // eslint-disable-line @typescript-eslint/no-this-alias
|
|
3258
|
-
|
|
3259
3008
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3260
3009
|
args[_key] = arguments[_key];
|
|
3261
3010
|
}
|
|
3262
|
-
|
|
3263
3011
|
return new Swal(...args);
|
|
3264
3012
|
}
|
|
3265
3013
|
|
|
@@ -3286,36 +3034,39 @@
|
|
|
3286
3034
|
_main(params, priorityMixinParams) {
|
|
3287
3035
|
return super._main(params, Object.assign({}, mixinParams, priorityMixinParams));
|
|
3288
3036
|
}
|
|
3289
|
-
|
|
3290
3037
|
}
|
|
3291
|
-
|
|
3292
3038
|
return MixinSwal;
|
|
3293
3039
|
}
|
|
3294
3040
|
|
|
3295
3041
|
/**
|
|
3296
3042
|
* If `timer` parameter is set, returns number of milliseconds of timer remained.
|
|
3297
3043
|
* Otherwise, returns undefined.
|
|
3044
|
+
*
|
|
3045
|
+
* @returns {number | undefined}
|
|
3298
3046
|
*/
|
|
3299
|
-
|
|
3300
3047
|
const getTimerLeft = () => {
|
|
3301
3048
|
return globalState.timeout && globalState.timeout.getTimerLeft();
|
|
3302
3049
|
};
|
|
3050
|
+
|
|
3303
3051
|
/**
|
|
3304
3052
|
* Stop timer. Returns number of milliseconds of timer remained.
|
|
3305
3053
|
* If `timer` parameter isn't set, returns undefined.
|
|
3054
|
+
*
|
|
3055
|
+
* @returns {number | undefined}
|
|
3306
3056
|
*/
|
|
3307
|
-
|
|
3308
3057
|
const stopTimer = () => {
|
|
3309
3058
|
if (globalState.timeout) {
|
|
3310
3059
|
stopTimerProgressBar();
|
|
3311
3060
|
return globalState.timeout.stop();
|
|
3312
3061
|
}
|
|
3313
3062
|
};
|
|
3063
|
+
|
|
3314
3064
|
/**
|
|
3315
3065
|
* Resume timer. Returns number of milliseconds of timer remained.
|
|
3316
3066
|
* If `timer` parameter isn't set, returns undefined.
|
|
3067
|
+
*
|
|
3068
|
+
* @returns {number | undefined}
|
|
3317
3069
|
*/
|
|
3318
|
-
|
|
3319
3070
|
const resumeTimer = () => {
|
|
3320
3071
|
if (globalState.timeout) {
|
|
3321
3072
|
const remaining = globalState.timeout.start();
|
|
@@ -3323,20 +3074,25 @@
|
|
|
3323
3074
|
return remaining;
|
|
3324
3075
|
}
|
|
3325
3076
|
};
|
|
3077
|
+
|
|
3326
3078
|
/**
|
|
3327
3079
|
* Resume timer. Returns number of milliseconds of timer remained.
|
|
3328
3080
|
* If `timer` parameter isn't set, returns undefined.
|
|
3081
|
+
*
|
|
3082
|
+
* @returns {number | undefined}
|
|
3329
3083
|
*/
|
|
3330
|
-
|
|
3331
3084
|
const toggleTimer = () => {
|
|
3332
3085
|
const timer = globalState.timeout;
|
|
3333
3086
|
return timer && (timer.running ? stopTimer() : resumeTimer());
|
|
3334
3087
|
};
|
|
3088
|
+
|
|
3335
3089
|
/**
|
|
3336
3090
|
* Increase timer. Returns number of milliseconds of an updated timer.
|
|
3337
3091
|
* If `timer` parameter isn't set, returns undefined.
|
|
3092
|
+
*
|
|
3093
|
+
* @param {number} n
|
|
3094
|
+
* @returns {number | undefined}
|
|
3338
3095
|
*/
|
|
3339
|
-
|
|
3340
3096
|
const increaseTimer = n => {
|
|
3341
3097
|
if (globalState.timeout) {
|
|
3342
3098
|
const remaining = globalState.timeout.increase(n);
|
|
@@ -3344,12 +3100,14 @@
|
|
|
3344
3100
|
return remaining;
|
|
3345
3101
|
}
|
|
3346
3102
|
};
|
|
3103
|
+
|
|
3347
3104
|
/**
|
|
3348
3105
|
* Check if timer is running. Returns true if timer is running
|
|
3349
3106
|
* or false if timer is paused or stopped.
|
|
3350
3107
|
* If `timer` parameter isn't set, returns undefined
|
|
3108
|
+
*
|
|
3109
|
+
* @returns {boolean}
|
|
3351
3110
|
*/
|
|
3352
|
-
|
|
3353
3111
|
const isTimerRunning = () => {
|
|
3354
3112
|
return globalState.timeout && globalState.timeout.isRunning();
|
|
3355
3113
|
};
|
|
@@ -3359,18 +3117,15 @@
|
|
|
3359
3117
|
function bindClickHandler() {
|
|
3360
3118
|
let attr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'data-swal-template';
|
|
3361
3119
|
clickHandlers[attr] = this;
|
|
3362
|
-
|
|
3363
3120
|
if (!bodyClickListenerAdded) {
|
|
3364
3121
|
document.body.addEventListener('click', bodyClickListener);
|
|
3365
3122
|
bodyClickListenerAdded = true;
|
|
3366
3123
|
}
|
|
3367
3124
|
}
|
|
3368
|
-
|
|
3369
3125
|
const bodyClickListener = event => {
|
|
3370
3126
|
for (let el = event.target; el && el !== document; el = el.parentNode) {
|
|
3371
3127
|
for (const attr in clickHandlers) {
|
|
3372
3128
|
const template = el.getAttribute(attr);
|
|
3373
|
-
|
|
3374
3129
|
if (template) {
|
|
3375
3130
|
clickHandlers[attr].fire({
|
|
3376
3131
|
template
|
|
@@ -3434,94 +3189,76 @@
|
|
|
3434
3189
|
this.running = false;
|
|
3435
3190
|
this.start();
|
|
3436
3191
|
}
|
|
3437
|
-
|
|
3438
3192
|
start() {
|
|
3439
3193
|
if (!this.running) {
|
|
3440
3194
|
this.running = true;
|
|
3441
3195
|
this.started = new Date();
|
|
3442
3196
|
this.id = setTimeout(this.callback, this.remaining);
|
|
3443
3197
|
}
|
|
3444
|
-
|
|
3445
3198
|
return this.remaining;
|
|
3446
3199
|
}
|
|
3447
|
-
|
|
3448
3200
|
stop() {
|
|
3449
3201
|
if (this.running) {
|
|
3450
3202
|
this.running = false;
|
|
3451
3203
|
clearTimeout(this.id);
|
|
3452
3204
|
this.remaining -= new Date().getTime() - this.started.getTime();
|
|
3453
3205
|
}
|
|
3454
|
-
|
|
3455
3206
|
return this.remaining;
|
|
3456
3207
|
}
|
|
3457
|
-
|
|
3458
3208
|
increase(n) {
|
|
3459
3209
|
const running = this.running;
|
|
3460
|
-
|
|
3461
3210
|
if (running) {
|
|
3462
3211
|
this.stop();
|
|
3463
3212
|
}
|
|
3464
|
-
|
|
3465
3213
|
this.remaining += n;
|
|
3466
|
-
|
|
3467
3214
|
if (running) {
|
|
3468
3215
|
this.start();
|
|
3469
3216
|
}
|
|
3470
|
-
|
|
3471
3217
|
return this.remaining;
|
|
3472
3218
|
}
|
|
3473
|
-
|
|
3474
3219
|
getTimerLeft() {
|
|
3475
3220
|
if (this.running) {
|
|
3476
3221
|
this.stop();
|
|
3477
3222
|
this.start();
|
|
3478
3223
|
}
|
|
3479
|
-
|
|
3480
3224
|
return this.remaining;
|
|
3481
3225
|
}
|
|
3482
|
-
|
|
3483
3226
|
isRunning() {
|
|
3484
3227
|
return this.running;
|
|
3485
3228
|
}
|
|
3486
|
-
|
|
3487
3229
|
}
|
|
3488
3230
|
|
|
3489
3231
|
const swalStringParams = ['swal-title', 'swal-html', 'swal-footer'];
|
|
3232
|
+
|
|
3490
3233
|
/**
|
|
3491
3234
|
* @param {SweetAlertOptions} params
|
|
3492
3235
|
* @returns {SweetAlertOptions}
|
|
3493
3236
|
*/
|
|
3494
|
-
|
|
3495
3237
|
const getTemplateParams = params => {
|
|
3496
3238
|
/** @type {HTMLTemplateElement} */
|
|
3497
3239
|
const template = typeof params.template === 'string' ? document.querySelector(params.template) : params.template;
|
|
3498
|
-
|
|
3499
3240
|
if (!template) {
|
|
3500
3241
|
return {};
|
|
3501
3242
|
}
|
|
3502
3243
|
/** @type {DocumentFragment} */
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
3244
|
const templateContent = template.content;
|
|
3506
3245
|
showWarningsForElements(templateContent);
|
|
3507
3246
|
const result = Object.assign(getSwalParams(templateContent), getSwalFunctionParams(templateContent), getSwalButtons(templateContent), getSwalImage(templateContent), getSwalIcon(templateContent), getSwalInput(templateContent), getSwalStringParams(templateContent, swalStringParams));
|
|
3508
3247
|
return result;
|
|
3509
3248
|
};
|
|
3249
|
+
|
|
3510
3250
|
/**
|
|
3511
3251
|
* @param {DocumentFragment} templateContent
|
|
3512
3252
|
* @returns {SweetAlertOptions}
|
|
3513
3253
|
*/
|
|
3514
|
-
|
|
3515
3254
|
const getSwalParams = templateContent => {
|
|
3516
3255
|
const result = {};
|
|
3517
3256
|
/** @type {HTMLElement[]} */
|
|
3518
|
-
|
|
3519
3257
|
const swalParams = Array.from(templateContent.querySelectorAll('swal-param'));
|
|
3520
3258
|
swalParams.forEach(param => {
|
|
3521
3259
|
showWarningsForAttributes(param, ['name', 'value']);
|
|
3522
3260
|
const paramName = param.getAttribute('name');
|
|
3523
3261
|
const value = param.getAttribute('value');
|
|
3524
|
-
|
|
3525
3262
|
if (typeof defaultParams[paramName] === 'boolean') {
|
|
3526
3263
|
result[paramName] = value !== 'false';
|
|
3527
3264
|
} else if (typeof defaultParams[paramName] === 'object') {
|
|
@@ -3532,16 +3269,14 @@
|
|
|
3532
3269
|
});
|
|
3533
3270
|
return result;
|
|
3534
3271
|
};
|
|
3272
|
+
|
|
3535
3273
|
/**
|
|
3536
3274
|
* @param {DocumentFragment} templateContent
|
|
3537
3275
|
* @returns {SweetAlertOptions}
|
|
3538
3276
|
*/
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
3277
|
const getSwalFunctionParams = templateContent => {
|
|
3542
3278
|
const result = {};
|
|
3543
3279
|
/** @type {HTMLElement[]} */
|
|
3544
|
-
|
|
3545
3280
|
const swalFunctions = Array.from(templateContent.querySelectorAll('swal-function-param'));
|
|
3546
3281
|
swalFunctions.forEach(param => {
|
|
3547
3282
|
const paramName = param.getAttribute('name');
|
|
@@ -3550,133 +3285,104 @@
|
|
|
3550
3285
|
});
|
|
3551
3286
|
return result;
|
|
3552
3287
|
};
|
|
3288
|
+
|
|
3553
3289
|
/**
|
|
3554
3290
|
* @param {DocumentFragment} templateContent
|
|
3555
3291
|
* @returns {SweetAlertOptions}
|
|
3556
3292
|
*/
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
3293
|
const getSwalButtons = templateContent => {
|
|
3560
3294
|
const result = {};
|
|
3561
3295
|
/** @type {HTMLElement[]} */
|
|
3562
|
-
|
|
3563
3296
|
const swalButtons = Array.from(templateContent.querySelectorAll('swal-button'));
|
|
3564
3297
|
swalButtons.forEach(button => {
|
|
3565
3298
|
showWarningsForAttributes(button, ['type', 'color', 'aria-label']);
|
|
3566
3299
|
const type = button.getAttribute('type');
|
|
3567
3300
|
result["".concat(type, "ButtonText")] = button.innerHTML;
|
|
3568
3301
|
result["show".concat(capitalizeFirstLetter(type), "Button")] = true;
|
|
3569
|
-
|
|
3570
3302
|
if (button.hasAttribute('color')) {
|
|
3571
3303
|
result["".concat(type, "ButtonColor")] = button.getAttribute('color');
|
|
3572
3304
|
}
|
|
3573
|
-
|
|
3574
3305
|
if (button.hasAttribute('aria-label')) {
|
|
3575
3306
|
result["".concat(type, "ButtonAriaLabel")] = button.getAttribute('aria-label');
|
|
3576
3307
|
}
|
|
3577
3308
|
});
|
|
3578
3309
|
return result;
|
|
3579
3310
|
};
|
|
3311
|
+
|
|
3580
3312
|
/**
|
|
3581
3313
|
* @param {DocumentFragment} templateContent
|
|
3582
3314
|
* @returns {SweetAlertOptions}
|
|
3583
3315
|
*/
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
3316
|
const getSwalImage = templateContent => {
|
|
3587
3317
|
const result = {};
|
|
3588
3318
|
/** @type {HTMLElement} */
|
|
3589
|
-
|
|
3590
3319
|
const image = templateContent.querySelector('swal-image');
|
|
3591
|
-
|
|
3592
3320
|
if (image) {
|
|
3593
3321
|
showWarningsForAttributes(image, ['src', 'width', 'height', 'alt']);
|
|
3594
|
-
|
|
3595
3322
|
if (image.hasAttribute('src')) {
|
|
3596
3323
|
result.imageUrl = image.getAttribute('src');
|
|
3597
3324
|
}
|
|
3598
|
-
|
|
3599
3325
|
if (image.hasAttribute('width')) {
|
|
3600
3326
|
result.imageWidth = image.getAttribute('width');
|
|
3601
3327
|
}
|
|
3602
|
-
|
|
3603
3328
|
if (image.hasAttribute('height')) {
|
|
3604
3329
|
result.imageHeight = image.getAttribute('height');
|
|
3605
3330
|
}
|
|
3606
|
-
|
|
3607
3331
|
if (image.hasAttribute('alt')) {
|
|
3608
3332
|
result.imageAlt = image.getAttribute('alt');
|
|
3609
3333
|
}
|
|
3610
3334
|
}
|
|
3611
|
-
|
|
3612
3335
|
return result;
|
|
3613
3336
|
};
|
|
3337
|
+
|
|
3614
3338
|
/**
|
|
3615
3339
|
* @param {DocumentFragment} templateContent
|
|
3616
3340
|
* @returns {SweetAlertOptions}
|
|
3617
3341
|
*/
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
3342
|
const getSwalIcon = templateContent => {
|
|
3621
3343
|
const result = {};
|
|
3622
3344
|
/** @type {HTMLElement} */
|
|
3623
|
-
|
|
3624
3345
|
const icon = templateContent.querySelector('swal-icon');
|
|
3625
|
-
|
|
3626
3346
|
if (icon) {
|
|
3627
3347
|
showWarningsForAttributes(icon, ['type', 'color']);
|
|
3628
|
-
|
|
3629
3348
|
if (icon.hasAttribute('type')) {
|
|
3630
3349
|
/** @type {SweetAlertIcon} */
|
|
3631
3350
|
// @ts-ignore
|
|
3632
3351
|
result.icon = icon.getAttribute('type');
|
|
3633
3352
|
}
|
|
3634
|
-
|
|
3635
3353
|
if (icon.hasAttribute('color')) {
|
|
3636
3354
|
result.iconColor = icon.getAttribute('color');
|
|
3637
3355
|
}
|
|
3638
|
-
|
|
3639
3356
|
result.iconHtml = icon.innerHTML;
|
|
3640
3357
|
}
|
|
3641
|
-
|
|
3642
3358
|
return result;
|
|
3643
3359
|
};
|
|
3360
|
+
|
|
3644
3361
|
/**
|
|
3645
3362
|
* @param {DocumentFragment} templateContent
|
|
3646
3363
|
* @returns {SweetAlertOptions}
|
|
3647
3364
|
*/
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
3365
|
const getSwalInput = templateContent => {
|
|
3651
3366
|
const result = {};
|
|
3652
3367
|
/** @type {HTMLElement} */
|
|
3653
|
-
|
|
3654
3368
|
const input = templateContent.querySelector('swal-input');
|
|
3655
|
-
|
|
3656
3369
|
if (input) {
|
|
3657
3370
|
showWarningsForAttributes(input, ['type', 'label', 'placeholder', 'value']);
|
|
3658
3371
|
/** @type {SweetAlertInput} */
|
|
3659
3372
|
// @ts-ignore
|
|
3660
|
-
|
|
3661
3373
|
result.input = input.getAttribute('type') || 'text';
|
|
3662
|
-
|
|
3663
3374
|
if (input.hasAttribute('label')) {
|
|
3664
3375
|
result.inputLabel = input.getAttribute('label');
|
|
3665
3376
|
}
|
|
3666
|
-
|
|
3667
3377
|
if (input.hasAttribute('placeholder')) {
|
|
3668
3378
|
result.inputPlaceholder = input.getAttribute('placeholder');
|
|
3669
3379
|
}
|
|
3670
|
-
|
|
3671
3380
|
if (input.hasAttribute('value')) {
|
|
3672
3381
|
result.inputValue = input.getAttribute('value');
|
|
3673
3382
|
}
|
|
3674
3383
|
}
|
|
3675
3384
|
/** @type {HTMLElement[]} */
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
3385
|
const inputOptions = Array.from(templateContent.querySelectorAll('swal-input-option'));
|
|
3679
|
-
|
|
3680
3386
|
if (inputOptions.length) {
|
|
3681
3387
|
result.inputOptions = {};
|
|
3682
3388
|
inputOptions.forEach(option => {
|
|
@@ -3686,54 +3392,45 @@
|
|
|
3686
3392
|
result.inputOptions[optionValue] = optionName;
|
|
3687
3393
|
});
|
|
3688
3394
|
}
|
|
3689
|
-
|
|
3690
3395
|
return result;
|
|
3691
3396
|
};
|
|
3397
|
+
|
|
3692
3398
|
/**
|
|
3693
3399
|
* @param {DocumentFragment} templateContent
|
|
3694
3400
|
* @param {string[]} paramNames
|
|
3695
3401
|
* @returns {SweetAlertOptions}
|
|
3696
3402
|
*/
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
3403
|
const getSwalStringParams = (templateContent, paramNames) => {
|
|
3700
3404
|
const result = {};
|
|
3701
|
-
|
|
3702
3405
|
for (const i in paramNames) {
|
|
3703
3406
|
const paramName = paramNames[i];
|
|
3704
3407
|
/** @type {HTMLElement} */
|
|
3705
|
-
|
|
3706
3408
|
const tag = templateContent.querySelector(paramName);
|
|
3707
|
-
|
|
3708
3409
|
if (tag) {
|
|
3709
3410
|
showWarningsForAttributes(tag, []);
|
|
3710
3411
|
result[paramName.replace(/^swal-/, '')] = tag.innerHTML.trim();
|
|
3711
3412
|
}
|
|
3712
3413
|
}
|
|
3713
|
-
|
|
3714
3414
|
return result;
|
|
3715
3415
|
};
|
|
3416
|
+
|
|
3716
3417
|
/**
|
|
3717
3418
|
* @param {DocumentFragment} templateContent
|
|
3718
3419
|
*/
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
3420
|
const showWarningsForElements = templateContent => {
|
|
3722
3421
|
const allowedElements = swalStringParams.concat(['swal-param', 'swal-function-param', 'swal-button', 'swal-image', 'swal-icon', 'swal-input', 'swal-input-option']);
|
|
3723
3422
|
Array.from(templateContent.children).forEach(el => {
|
|
3724
3423
|
const tagName = el.tagName.toLowerCase();
|
|
3725
|
-
|
|
3726
3424
|
if (!allowedElements.includes(tagName)) {
|
|
3727
3425
|
warn("Unrecognized element <".concat(tagName, ">"));
|
|
3728
3426
|
}
|
|
3729
3427
|
});
|
|
3730
3428
|
};
|
|
3429
|
+
|
|
3731
3430
|
/**
|
|
3732
3431
|
* @param {HTMLElement} el
|
|
3733
3432
|
* @param {string[]} allowedAttributes
|
|
3734
3433
|
*/
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
3434
|
const showWarningsForAttributes = (el, allowedAttributes) => {
|
|
3738
3435
|
Array.from(el.attributes).forEach(attribute => {
|
|
3739
3436
|
if (allowedAttributes.indexOf(attribute.name) === -1) {
|
|
@@ -3743,64 +3440,56 @@
|
|
|
3743
3440
|
};
|
|
3744
3441
|
|
|
3745
3442
|
const SHOW_CLASS_TIMEOUT = 10;
|
|
3443
|
+
|
|
3746
3444
|
/**
|
|
3747
3445
|
* Open popup, add necessary classes and styles, fix scrollbar
|
|
3748
3446
|
*
|
|
3749
3447
|
* @param {SweetAlertOptions} params
|
|
3750
3448
|
*/
|
|
3751
|
-
|
|
3752
3449
|
const openPopup = params => {
|
|
3753
3450
|
const container = getContainer();
|
|
3754
3451
|
const popup = getPopup();
|
|
3755
|
-
|
|
3756
3452
|
if (typeof params.willOpen === 'function') {
|
|
3757
3453
|
params.willOpen(popup);
|
|
3758
3454
|
}
|
|
3759
|
-
|
|
3760
3455
|
const bodyStyles = window.getComputedStyle(document.body);
|
|
3761
3456
|
const initialBodyOverflow = bodyStyles.overflowY;
|
|
3762
|
-
addClasses$1(container, popup, params);
|
|
3457
|
+
addClasses$1(container, popup, params);
|
|
3763
3458
|
|
|
3459
|
+
// scrolling is 'hidden' until animation is done, after that 'auto'
|
|
3764
3460
|
setTimeout(() => {
|
|
3765
3461
|
setScrollingVisibility(container, popup);
|
|
3766
3462
|
}, SHOW_CLASS_TIMEOUT);
|
|
3767
|
-
|
|
3768
3463
|
if (isModal()) {
|
|
3769
3464
|
fixScrollContainer(container, params.scrollbarPadding, initialBodyOverflow);
|
|
3770
3465
|
setAriaHidden();
|
|
3771
3466
|
}
|
|
3772
|
-
|
|
3773
3467
|
if (!isToast() && !globalState.previousActiveElement) {
|
|
3774
3468
|
globalState.previousActiveElement = document.activeElement;
|
|
3775
3469
|
}
|
|
3776
|
-
|
|
3777
3470
|
if (typeof params.didOpen === 'function') {
|
|
3778
3471
|
setTimeout(() => params.didOpen(popup));
|
|
3779
3472
|
}
|
|
3780
|
-
|
|
3781
3473
|
removeClass(container, swalClasses['no-transition']);
|
|
3782
3474
|
};
|
|
3475
|
+
|
|
3783
3476
|
/**
|
|
3784
3477
|
* @param {AnimationEvent} event
|
|
3785
3478
|
*/
|
|
3786
|
-
|
|
3787
3479
|
const swalOpenAnimationFinished = event => {
|
|
3788
3480
|
const popup = getPopup();
|
|
3789
|
-
|
|
3790
3481
|
if (event.target !== popup) {
|
|
3791
3482
|
return;
|
|
3792
3483
|
}
|
|
3793
|
-
|
|
3794
3484
|
const container = getContainer();
|
|
3795
3485
|
popup.removeEventListener(animationEndEvent, swalOpenAnimationFinished);
|
|
3796
3486
|
container.style.overflowY = 'auto';
|
|
3797
3487
|
};
|
|
3488
|
+
|
|
3798
3489
|
/**
|
|
3799
3490
|
* @param {HTMLElement} container
|
|
3800
3491
|
* @param {HTMLElement} popup
|
|
3801
3492
|
*/
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
3493
|
const setScrollingVisibility = (container, popup) => {
|
|
3805
3494
|
if (animationEndEvent && hasCssAnimation(popup)) {
|
|
3806
3495
|
container.style.overflowY = 'hidden';
|
|
@@ -3809,46 +3498,42 @@
|
|
|
3809
3498
|
container.style.overflowY = 'auto';
|
|
3810
3499
|
}
|
|
3811
3500
|
};
|
|
3501
|
+
|
|
3812
3502
|
/**
|
|
3813
3503
|
* @param {HTMLElement} container
|
|
3814
3504
|
* @param {boolean} scrollbarPadding
|
|
3815
3505
|
* @param {string} initialBodyOverflow
|
|
3816
3506
|
*/
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
3507
|
const fixScrollContainer = (container, scrollbarPadding, initialBodyOverflow) => {
|
|
3820
3508
|
iOSfix();
|
|
3821
|
-
|
|
3822
3509
|
if (scrollbarPadding && initialBodyOverflow !== 'hidden') {
|
|
3823
3510
|
fixScrollbar();
|
|
3824
|
-
}
|
|
3825
|
-
|
|
3511
|
+
}
|
|
3826
3512
|
|
|
3513
|
+
// sweetalert2/issues/1247
|
|
3827
3514
|
setTimeout(() => {
|
|
3828
3515
|
container.scrollTop = 0;
|
|
3829
3516
|
});
|
|
3830
3517
|
};
|
|
3518
|
+
|
|
3831
3519
|
/**
|
|
3832
3520
|
* @param {HTMLElement} container
|
|
3833
3521
|
* @param {HTMLElement} popup
|
|
3834
3522
|
* @param {SweetAlertOptions} params
|
|
3835
3523
|
*/
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
3524
|
const addClasses$1 = (container, popup, params) => {
|
|
3839
|
-
addClass(container, params.showClass.backdrop);
|
|
3840
|
-
|
|
3525
|
+
addClass(container, params.showClass.backdrop);
|
|
3526
|
+
// this workaround with opacity is needed for https://github.com/sweetalert2/sweetalert2/issues/2059
|
|
3841
3527
|
popup.style.setProperty('opacity', '0', 'important');
|
|
3842
3528
|
show(popup, 'grid');
|
|
3843
3529
|
setTimeout(() => {
|
|
3844
3530
|
// Animate popup right after showing it
|
|
3845
|
-
addClass(popup, params.showClass.popup);
|
|
3846
|
-
|
|
3531
|
+
addClass(popup, params.showClass.popup);
|
|
3532
|
+
// and remove the opacity workaround
|
|
3847
3533
|
popup.style.removeProperty('opacity');
|
|
3848
3534
|
}, SHOW_CLASS_TIMEOUT); // 10ms in order to fix #2062
|
|
3849
3535
|
|
|
3850
3536
|
addClass([document.documentElement, document.body], swalClasses.shown);
|
|
3851
|
-
|
|
3852
3537
|
if (params.heightAuto && params.backdrop && !params.toast) {
|
|
3853
3538
|
addClass([document.documentElement, document.body], swalClasses['height-auto']);
|
|
3854
3539
|
}
|
|
@@ -3863,7 +3548,6 @@
|
|
|
3863
3548
|
email: (string, validationMessage) => {
|
|
3864
3549
|
return /^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9-]{2,24}$/.test(string) ? Promise.resolve() : Promise.resolve(validationMessage || 'Invalid email address');
|
|
3865
3550
|
},
|
|
3866
|
-
|
|
3867
3551
|
/**
|
|
3868
3552
|
* @param {string} string
|
|
3869
3553
|
* @param {string} validationMessage
|
|
@@ -3878,7 +3562,6 @@
|
|
|
3878
3562
|
/**
|
|
3879
3563
|
* @param {SweetAlertOptions} params
|
|
3880
3564
|
*/
|
|
3881
|
-
|
|
3882
3565
|
function setDefaultInputValidators(params) {
|
|
3883
3566
|
// Use default `inputValidator` for supported input types if not provided
|
|
3884
3567
|
if (!params.inputValidator) {
|
|
@@ -3889,11 +3572,10 @@
|
|
|
3889
3572
|
});
|
|
3890
3573
|
}
|
|
3891
3574
|
}
|
|
3575
|
+
|
|
3892
3576
|
/**
|
|
3893
3577
|
* @param {SweetAlertOptions} params
|
|
3894
3578
|
*/
|
|
3895
|
-
|
|
3896
|
-
|
|
3897
3579
|
function validateCustomTargetElement(params) {
|
|
3898
3580
|
// Determine if the custom target element is valid
|
|
3899
3581
|
if (!params.target || typeof params.target === 'string' && !document.querySelector(params.target) || typeof params.target !== 'string' && !params.target.appendChild) {
|
|
@@ -3901,44 +3583,41 @@
|
|
|
3901
3583
|
params.target = 'body';
|
|
3902
3584
|
}
|
|
3903
3585
|
}
|
|
3586
|
+
|
|
3904
3587
|
/**
|
|
3905
3588
|
* Set type, text and actions on popup
|
|
3906
3589
|
*
|
|
3907
3590
|
* @param {SweetAlertOptions} params
|
|
3908
3591
|
*/
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
3592
|
function setParameters(params) {
|
|
3912
|
-
setDefaultInputValidators(params);
|
|
3593
|
+
setDefaultInputValidators(params);
|
|
3913
3594
|
|
|
3595
|
+
// showLoaderOnConfirm && preConfirm
|
|
3914
3596
|
if (params.showLoaderOnConfirm && !params.preConfirm) {
|
|
3915
3597
|
warn('showLoaderOnConfirm is set to true, but preConfirm is not defined.\n' + 'showLoaderOnConfirm should be used together with preConfirm, see usage example:\n' + 'https://sweetalert2.github.io/#ajax-request');
|
|
3916
3598
|
}
|
|
3599
|
+
validateCustomTargetElement(params);
|
|
3917
3600
|
|
|
3918
|
-
|
|
3919
|
-
|
|
3601
|
+
// Replace newlines with <br> in title
|
|
3920
3602
|
if (typeof params.title === 'string') {
|
|
3921
3603
|
params.title = params.title.split('\n').join('<br />');
|
|
3922
3604
|
}
|
|
3923
|
-
|
|
3924
3605
|
init(params);
|
|
3925
3606
|
}
|
|
3926
3607
|
|
|
3927
3608
|
let currentInstance;
|
|
3928
|
-
|
|
3929
3609
|
class SweetAlert {
|
|
3930
3610
|
constructor() {
|
|
3931
3611
|
// Prevent run in Node env
|
|
3932
3612
|
if (typeof window === 'undefined') {
|
|
3933
3613
|
return;
|
|
3934
3614
|
}
|
|
3615
|
+
currentInstance = this;
|
|
3935
3616
|
|
|
3936
|
-
|
|
3937
|
-
|
|
3617
|
+
// @ts-ignore
|
|
3938
3618
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3939
3619
|
args[_key] = arguments[_key];
|
|
3940
3620
|
}
|
|
3941
|
-
|
|
3942
3621
|
const outerParams = Object.freeze(this.constructor.argsToParams(args));
|
|
3943
3622
|
Object.defineProperties(this, {
|
|
3944
3623
|
params: {
|
|
@@ -3947,68 +3626,61 @@
|
|
|
3947
3626
|
enumerable: true,
|
|
3948
3627
|
configurable: true
|
|
3949
3628
|
}
|
|
3950
|
-
});
|
|
3629
|
+
});
|
|
3951
3630
|
|
|
3631
|
+
// @ts-ignore
|
|
3952
3632
|
const promise = currentInstance._main(currentInstance.params);
|
|
3953
|
-
|
|
3954
3633
|
privateProps.promise.set(this, promise);
|
|
3955
3634
|
}
|
|
3956
|
-
|
|
3957
3635
|
_main(userParams) {
|
|
3958
3636
|
let mixinParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
3959
3637
|
showWarningsForParams(Object.assign({}, mixinParams, userParams));
|
|
3960
|
-
|
|
3961
3638
|
if (globalState.currentInstance) {
|
|
3962
3639
|
// @ts-ignore
|
|
3963
3640
|
globalState.currentInstance._destroy();
|
|
3964
|
-
|
|
3965
3641
|
if (isModal()) {
|
|
3966
3642
|
unsetAriaHidden();
|
|
3967
3643
|
}
|
|
3968
3644
|
}
|
|
3969
|
-
|
|
3970
3645
|
globalState.currentInstance = currentInstance;
|
|
3971
3646
|
const innerParams = prepareParams(userParams, mixinParams);
|
|
3972
3647
|
setParameters(innerParams);
|
|
3973
|
-
Object.freeze(innerParams);
|
|
3648
|
+
Object.freeze(innerParams);
|
|
3974
3649
|
|
|
3650
|
+
// clear the previous timer
|
|
3975
3651
|
if (globalState.timeout) {
|
|
3976
3652
|
globalState.timeout.stop();
|
|
3977
3653
|
delete globalState.timeout;
|
|
3978
|
-
}
|
|
3979
|
-
|
|
3654
|
+
}
|
|
3980
3655
|
|
|
3656
|
+
// clear the restore focus timeout
|
|
3981
3657
|
clearTimeout(globalState.restoreFocusTimeout);
|
|
3982
3658
|
const domCache = populateDomCache(currentInstance);
|
|
3983
3659
|
render(currentInstance, innerParams);
|
|
3984
3660
|
privateProps.innerParams.set(currentInstance, innerParams);
|
|
3985
3661
|
return swalPromise(currentInstance, domCache, innerParams);
|
|
3986
|
-
}
|
|
3987
|
-
|
|
3662
|
+
}
|
|
3988
3663
|
|
|
3664
|
+
// `catch` cannot be the name of a module export, so we define our thenable methods here instead
|
|
3989
3665
|
then(onFulfilled) {
|
|
3990
3666
|
const promise = privateProps.promise.get(this);
|
|
3991
3667
|
return promise.then(onFulfilled);
|
|
3992
3668
|
}
|
|
3993
|
-
|
|
3994
3669
|
finally(onFinally) {
|
|
3995
3670
|
const promise = privateProps.promise.get(this);
|
|
3996
3671
|
return promise.finally(onFinally);
|
|
3997
3672
|
}
|
|
3998
|
-
|
|
3999
3673
|
}
|
|
3674
|
+
|
|
4000
3675
|
/**
|
|
4001
3676
|
* @param {SweetAlert2} instance
|
|
4002
3677
|
* @param {DomCache} domCache
|
|
4003
3678
|
* @param {SweetAlertOptions} innerParams
|
|
4004
3679
|
* @returns {Promise}
|
|
4005
3680
|
*/
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
3681
|
const swalPromise = (instance, domCache, innerParams) => {
|
|
4009
3682
|
return new Promise((resolve, reject) => {
|
|
4010
3683
|
// functions to handle all closings/dismissals
|
|
4011
|
-
|
|
4012
3684
|
/**
|
|
4013
3685
|
* @param {DismissReason} dismiss
|
|
4014
3686
|
*/
|
|
@@ -4019,60 +3691,52 @@
|
|
|
4019
3691
|
dismiss
|
|
4020
3692
|
});
|
|
4021
3693
|
};
|
|
4022
|
-
|
|
4023
3694
|
privateMethods.swalPromiseResolve.set(instance, resolve);
|
|
4024
3695
|
privateMethods.swalPromiseReject.set(instance, reject);
|
|
4025
|
-
|
|
4026
3696
|
domCache.confirmButton.onclick = () => {
|
|
4027
3697
|
handleConfirmButtonClick(instance);
|
|
4028
3698
|
};
|
|
4029
|
-
|
|
4030
3699
|
domCache.denyButton.onclick = () => {
|
|
4031
3700
|
handleDenyButtonClick(instance);
|
|
4032
3701
|
};
|
|
4033
|
-
|
|
4034
3702
|
domCache.cancelButton.onclick = () => {
|
|
4035
3703
|
handleCancelButtonClick(instance, dismissWith);
|
|
4036
3704
|
};
|
|
4037
|
-
|
|
4038
3705
|
domCache.closeButton.onclick = () => {
|
|
4039
3706
|
// @ts-ignore
|
|
4040
3707
|
dismissWith(DismissReason.close);
|
|
4041
3708
|
};
|
|
4042
|
-
|
|
4043
3709
|
handlePopupClick(instance, domCache, dismissWith);
|
|
4044
3710
|
addKeydownHandler(instance, globalState, innerParams, dismissWith);
|
|
4045
3711
|
handleInputOptionsAndValue(instance, innerParams);
|
|
4046
3712
|
openPopup(innerParams);
|
|
4047
3713
|
setupTimer(globalState, innerParams, dismissWith);
|
|
4048
|
-
initFocus(domCache, innerParams);
|
|
3714
|
+
initFocus(domCache, innerParams);
|
|
4049
3715
|
|
|
3716
|
+
// Scroll container to top on open (#1247, #1946)
|
|
4050
3717
|
setTimeout(() => {
|
|
4051
3718
|
domCache.container.scrollTop = 0;
|
|
4052
3719
|
});
|
|
4053
3720
|
});
|
|
4054
3721
|
};
|
|
3722
|
+
|
|
4055
3723
|
/**
|
|
4056
3724
|
* @param {SweetAlertOptions} userParams
|
|
4057
3725
|
* @param {SweetAlertOptions} mixinParams
|
|
4058
3726
|
* @returns {SweetAlertOptions}
|
|
4059
3727
|
*/
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
3728
|
const prepareParams = (userParams, mixinParams) => {
|
|
4063
3729
|
const templateParams = getTemplateParams(userParams);
|
|
4064
3730
|
const params = Object.assign({}, defaultParams, mixinParams, templateParams, userParams); // precedence is described in #2131
|
|
4065
|
-
|
|
4066
3731
|
params.showClass = Object.assign({}, defaultParams.showClass, params.showClass);
|
|
4067
3732
|
params.hideClass = Object.assign({}, defaultParams.hideClass, params.hideClass);
|
|
4068
3733
|
return params;
|
|
4069
3734
|
};
|
|
3735
|
+
|
|
4070
3736
|
/**
|
|
4071
3737
|
* @param {SweetAlert2} instance
|
|
4072
3738
|
* @returns {DomCache}
|
|
4073
3739
|
*/
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
3740
|
const populateDomCache = instance => {
|
|
4077
3741
|
const domCache = {
|
|
4078
3742
|
popup: getPopup(),
|
|
@@ -4089,23 +3753,20 @@
|
|
|
4089
3753
|
privateProps.domCache.set(instance, domCache);
|
|
4090
3754
|
return domCache;
|
|
4091
3755
|
};
|
|
3756
|
+
|
|
4092
3757
|
/**
|
|
4093
3758
|
* @param {GlobalState} globalState
|
|
4094
3759
|
* @param {SweetAlertOptions} innerParams
|
|
4095
3760
|
* @param {Function} dismissWith
|
|
4096
3761
|
*/
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
3762
|
const setupTimer = (globalState$$1, innerParams, dismissWith) => {
|
|
4100
3763
|
const timerProgressBar = getTimerProgressBar();
|
|
4101
3764
|
hide(timerProgressBar);
|
|
4102
|
-
|
|
4103
3765
|
if (innerParams.timer) {
|
|
4104
3766
|
globalState$$1.timeout = new Timer(() => {
|
|
4105
3767
|
dismissWith('timer');
|
|
4106
3768
|
delete globalState$$1.timeout;
|
|
4107
3769
|
}, innerParams.timer);
|
|
4108
|
-
|
|
4109
3770
|
if (innerParams.timerProgressBar) {
|
|
4110
3771
|
show(timerProgressBar);
|
|
4111
3772
|
applyCustomClass(timerProgressBar, innerParams, 'timerProgressBar');
|
|
@@ -4118,68 +3779,62 @@
|
|
|
4118
3779
|
}
|
|
4119
3780
|
}
|
|
4120
3781
|
};
|
|
3782
|
+
|
|
4121
3783
|
/**
|
|
4122
3784
|
* @param {DomCache} domCache
|
|
4123
3785
|
* @param {SweetAlertOptions} innerParams
|
|
4124
3786
|
*/
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
3787
|
const initFocus = (domCache, innerParams) => {
|
|
4128
3788
|
if (innerParams.toast) {
|
|
4129
3789
|
return;
|
|
4130
3790
|
}
|
|
4131
|
-
|
|
4132
3791
|
if (!callIfFunction(innerParams.allowEnterKey)) {
|
|
4133
3792
|
blurActiveElement();
|
|
4134
3793
|
return;
|
|
4135
3794
|
}
|
|
4136
|
-
|
|
4137
3795
|
if (!focusButton(domCache, innerParams)) {
|
|
4138
3796
|
setFocus(innerParams, -1, 1);
|
|
4139
3797
|
}
|
|
4140
3798
|
};
|
|
3799
|
+
|
|
4141
3800
|
/**
|
|
4142
3801
|
* @param {DomCache} domCache
|
|
4143
3802
|
* @param {SweetAlertOptions} innerParams
|
|
4144
3803
|
* @returns {boolean}
|
|
4145
3804
|
*/
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
3805
|
const focusButton = (domCache, innerParams) => {
|
|
4149
3806
|
if (innerParams.focusDeny && isVisible(domCache.denyButton)) {
|
|
4150
3807
|
domCache.denyButton.focus();
|
|
4151
3808
|
return true;
|
|
4152
3809
|
}
|
|
4153
|
-
|
|
4154
3810
|
if (innerParams.focusCancel && isVisible(domCache.cancelButton)) {
|
|
4155
3811
|
domCache.cancelButton.focus();
|
|
4156
3812
|
return true;
|
|
4157
3813
|
}
|
|
4158
|
-
|
|
4159
3814
|
if (innerParams.focusConfirm && isVisible(domCache.confirmButton)) {
|
|
4160
3815
|
domCache.confirmButton.focus();
|
|
4161
3816
|
return true;
|
|
4162
3817
|
}
|
|
4163
|
-
|
|
4164
3818
|
return false;
|
|
4165
3819
|
};
|
|
4166
|
-
|
|
4167
3820
|
const blurActiveElement = () => {
|
|
4168
3821
|
if (document.activeElement instanceof HTMLElement && typeof document.activeElement.blur === 'function') {
|
|
4169
3822
|
document.activeElement.blur();
|
|
4170
3823
|
}
|
|
4171
|
-
};
|
|
4172
|
-
|
|
3824
|
+
};
|
|
4173
3825
|
|
|
3826
|
+
// Dear russian users visiting russian sites. Let's play a game.
|
|
4174
3827
|
if (typeof window !== 'undefined' && /^ru\b/.test(navigator.language) && location.host.match(/\.(ru|su|xn--p1ai)$/)) {
|
|
4175
3828
|
document.body.style.pointerEvents = 'none';
|
|
4176
|
-
}
|
|
4177
|
-
|
|
3829
|
+
}
|
|
4178
3830
|
|
|
4179
|
-
|
|
3831
|
+
// Assign instance methods from src/instanceMethods/*.js to prototype
|
|
3832
|
+
Object.assign(SweetAlert.prototype, instanceMethods);
|
|
4180
3833
|
|
|
4181
|
-
|
|
3834
|
+
// Assign static methods from src/staticMethods/*.js to constructor
|
|
3835
|
+
Object.assign(SweetAlert, staticMethods);
|
|
4182
3836
|
|
|
3837
|
+
// Proxy to instance methods to constructor, for now, for backwards compatibility
|
|
4183
3838
|
Object.keys(instanceMethods).forEach(key => {
|
|
4184
3839
|
/**
|
|
4185
3840
|
* @param {...any} args
|
|
@@ -4192,10 +3847,10 @@
|
|
|
4192
3847
|
};
|
|
4193
3848
|
});
|
|
4194
3849
|
SweetAlert.DismissReason = DismissReason;
|
|
4195
|
-
SweetAlert.version = '11.5.
|
|
4196
|
-
|
|
4197
|
-
const Swal = SweetAlert; // @ts-ignore
|
|
3850
|
+
SweetAlert.version = '11.5.2';
|
|
4198
3851
|
|
|
3852
|
+
const Swal = SweetAlert;
|
|
3853
|
+
// @ts-ignore
|
|
4199
3854
|
Swal.default = Swal;
|
|
4200
3855
|
|
|
4201
3856
|
return Swal;
|