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