sweetalert2 11.2.1 → 11.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -7
- package/dist/sweetalert2.all.js +1293 -1206
- package/dist/sweetalert2.all.min.js +2 -2
- package/dist/sweetalert2.css +3 -3
- package/dist/sweetalert2.js +1292 -1205
- package/dist/sweetalert2.min.css +1 -1
- package/dist/sweetalert2.min.js +1 -1
- package/package.json +12 -11
- package/src/SweetAlert.js +169 -1
- package/src/{instanceMethods/buttons-handlers.js → buttons-handlers.js} +7 -7
- package/src/instanceMethods/getInput.js +4 -1
- package/src/instanceMethods/update.js +2 -2
- package/src/instanceMethods.js +0 -1
- package/src/{instanceMethods/keydown-handler.js → keydown-handler.js} +6 -6
- package/src/{instanceMethods/popup-click-handler.js → popup-click-handler.js} +15 -11
- package/src/staticMethods/showLoading.js +1 -1
- package/src/sweetalert2.js +1 -0
- package/src/utils/Timer.js +1 -1
- package/src/utils/dom/domUtils.js +59 -8
- package/src/utils/dom/getters.js +8 -3
- package/src/utils/dom/init.js +2 -4
- package/src/utils/dom/renderers/renderInput.js +2 -1
- package/src/utils/dom/renderers/renderPopup.js +5 -0
- package/src/utils/iosFix.js +1 -0
- package/src/utils/params.js +5 -3
- package/src/utils/setParameters.js +0 -1
- package/src/variables.scss +3 -3
- package/sweetalert2.d.ts +8 -1
- package/CHANGELOG.md +0 -2194
- package/src/instanceMethods/_main.js +0 -168
package/dist/sweetalert2.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sweetalert2 v11.2
|
|
2
|
+
* sweetalert2 v11.3.2
|
|
3
3
|
* Released under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
(function (global, factory) {
|
|
@@ -8,14 +8,6 @@
|
|
|
8
8
|
(global = global || self, global.Sweetalert2 = factory());
|
|
9
9
|
}(this, function () { 'use strict';
|
|
10
10
|
|
|
11
|
-
const DismissReason = Object.freeze({
|
|
12
|
-
cancel: 'cancel',
|
|
13
|
-
backdrop: 'backdrop',
|
|
14
|
-
close: 'close',
|
|
15
|
-
esc: 'esc',
|
|
16
|
-
timer: 'timer'
|
|
17
|
-
});
|
|
18
|
-
|
|
19
11
|
const consolePrefix = 'SweetAlert2:';
|
|
20
12
|
/**
|
|
21
13
|
* Filter the unique values into a new array
|
|
@@ -97,28 +89,161 @@
|
|
|
97
89
|
const asPromise = arg => hasToPromiseFn(arg) ? arg.toPromise() : Promise.resolve(arg);
|
|
98
90
|
const isPromise = arg => arg && Promise.resolve(arg) === arg;
|
|
99
91
|
|
|
100
|
-
const
|
|
92
|
+
const defaultParams = {
|
|
93
|
+
title: '',
|
|
94
|
+
titleText: '',
|
|
95
|
+
text: '',
|
|
96
|
+
html: '',
|
|
97
|
+
footer: '',
|
|
98
|
+
icon: undefined,
|
|
99
|
+
iconColor: undefined,
|
|
100
|
+
iconHtml: undefined,
|
|
101
|
+
template: undefined,
|
|
102
|
+
toast: false,
|
|
103
|
+
showClass: {
|
|
104
|
+
popup: 'swal2-show',
|
|
105
|
+
backdrop: 'swal2-backdrop-show',
|
|
106
|
+
icon: 'swal2-icon-show'
|
|
107
|
+
},
|
|
108
|
+
hideClass: {
|
|
109
|
+
popup: 'swal2-hide',
|
|
110
|
+
backdrop: 'swal2-backdrop-hide',
|
|
111
|
+
icon: 'swal2-icon-hide'
|
|
112
|
+
},
|
|
113
|
+
customClass: {},
|
|
114
|
+
target: 'body',
|
|
115
|
+
color: undefined,
|
|
116
|
+
backdrop: true,
|
|
117
|
+
heightAuto: true,
|
|
118
|
+
allowOutsideClick: true,
|
|
119
|
+
allowEscapeKey: true,
|
|
120
|
+
allowEnterKey: true,
|
|
121
|
+
stopKeydownPropagation: true,
|
|
122
|
+
keydownListenerCapture: false,
|
|
123
|
+
showConfirmButton: true,
|
|
124
|
+
showDenyButton: false,
|
|
125
|
+
showCancelButton: false,
|
|
126
|
+
preConfirm: undefined,
|
|
127
|
+
preDeny: undefined,
|
|
128
|
+
confirmButtonText: 'OK',
|
|
129
|
+
confirmButtonAriaLabel: '',
|
|
130
|
+
confirmButtonColor: undefined,
|
|
131
|
+
denyButtonText: 'No',
|
|
132
|
+
denyButtonAriaLabel: '',
|
|
133
|
+
denyButtonColor: undefined,
|
|
134
|
+
cancelButtonText: 'Cancel',
|
|
135
|
+
cancelButtonAriaLabel: '',
|
|
136
|
+
cancelButtonColor: undefined,
|
|
137
|
+
buttonsStyling: true,
|
|
138
|
+
reverseButtons: false,
|
|
139
|
+
focusConfirm: true,
|
|
140
|
+
focusDeny: false,
|
|
141
|
+
focusCancel: false,
|
|
142
|
+
returnFocus: true,
|
|
143
|
+
showCloseButton: false,
|
|
144
|
+
closeButtonHtml: '×',
|
|
145
|
+
closeButtonAriaLabel: 'Close this dialog',
|
|
146
|
+
loaderHtml: '',
|
|
147
|
+
showLoaderOnConfirm: false,
|
|
148
|
+
showLoaderOnDeny: false,
|
|
149
|
+
imageUrl: undefined,
|
|
150
|
+
imageWidth: undefined,
|
|
151
|
+
imageHeight: undefined,
|
|
152
|
+
imageAlt: '',
|
|
153
|
+
timer: undefined,
|
|
154
|
+
timerProgressBar: false,
|
|
155
|
+
width: undefined,
|
|
156
|
+
padding: undefined,
|
|
157
|
+
background: undefined,
|
|
158
|
+
input: undefined,
|
|
159
|
+
inputPlaceholder: '',
|
|
160
|
+
inputLabel: '',
|
|
161
|
+
inputValue: '',
|
|
162
|
+
inputOptions: {},
|
|
163
|
+
inputAutoTrim: true,
|
|
164
|
+
inputAttributes: {},
|
|
165
|
+
inputValidator: undefined,
|
|
166
|
+
returnInputValueOnDeny: false,
|
|
167
|
+
validationMessage: undefined,
|
|
168
|
+
grow: false,
|
|
169
|
+
position: 'center',
|
|
170
|
+
progressSteps: [],
|
|
171
|
+
currentProgressStep: undefined,
|
|
172
|
+
progressStepsDistance: undefined,
|
|
173
|
+
willOpen: undefined,
|
|
174
|
+
didOpen: undefined,
|
|
175
|
+
didRender: undefined,
|
|
176
|
+
willClose: undefined,
|
|
177
|
+
didClose: undefined,
|
|
178
|
+
didDestroy: undefined,
|
|
179
|
+
scrollbarPadding: true
|
|
180
|
+
};
|
|
181
|
+
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'];
|
|
182
|
+
const deprecatedParams = {};
|
|
183
|
+
const toastIncompatibleParams = ['allowOutsideClick', 'allowEnterKey', 'backdrop', 'focusConfirm', 'focusDeny', 'focusCancel', 'returnFocus', 'heightAuto', 'keydownListenerCapture'];
|
|
184
|
+
/**
|
|
185
|
+
* Is valid parameter
|
|
186
|
+
* @param {string} paramName
|
|
187
|
+
*/
|
|
101
188
|
|
|
102
|
-
const
|
|
189
|
+
const isValidParameter = paramName => {
|
|
190
|
+
return Object.prototype.hasOwnProperty.call(defaultParams, paramName);
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* Is valid parameter for Swal.update() method
|
|
194
|
+
* @param {string} paramName
|
|
195
|
+
*/
|
|
103
196
|
|
|
104
|
-
const
|
|
105
|
-
|
|
197
|
+
const isUpdatableParameter = paramName => {
|
|
198
|
+
return updatableParams.indexOf(paramName) !== -1;
|
|
199
|
+
};
|
|
200
|
+
/**
|
|
201
|
+
* Is deprecated parameter
|
|
202
|
+
* @param {string} paramName
|
|
203
|
+
*/
|
|
106
204
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
['title', 'html', 'icon'].forEach((name, index) => {
|
|
111
|
-
const arg = args[index];
|
|
205
|
+
const isDeprecatedParameter = paramName => {
|
|
206
|
+
return deprecatedParams[paramName];
|
|
207
|
+
};
|
|
112
208
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
error("Unexpected type of ".concat(name, "! Expected \"string\" or \"Element\", got ").concat(typeof arg));
|
|
117
|
-
}
|
|
118
|
-
});
|
|
209
|
+
const checkIfParamIsValid = param => {
|
|
210
|
+
if (!isValidParameter(param)) {
|
|
211
|
+
warn("Unknown parameter \"".concat(param, "\""));
|
|
119
212
|
}
|
|
213
|
+
};
|
|
120
214
|
|
|
121
|
-
|
|
215
|
+
const checkIfToastParamIsValid = param => {
|
|
216
|
+
if (toastIncompatibleParams.includes(param)) {
|
|
217
|
+
warn("The parameter \"".concat(param, "\" is incompatible with toasts"));
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const checkIfParamIsDeprecated = param => {
|
|
222
|
+
if (isDeprecatedParameter(param)) {
|
|
223
|
+
warnAboutDeprecation(param, isDeprecatedParameter(param));
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
/**
|
|
227
|
+
* Show relevant warnings for given params
|
|
228
|
+
*
|
|
229
|
+
* @param params
|
|
230
|
+
*/
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
const showWarningsForParams = params => {
|
|
234
|
+
if (!params.backdrop && params.allowOutsideClick) {
|
|
235
|
+
warn('"allowOutsideClick" parameter requires `backdrop` parameter to be set to `true`');
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
for (const param in params) {
|
|
239
|
+
checkIfParamIsValid(param);
|
|
240
|
+
|
|
241
|
+
if (params.toast) {
|
|
242
|
+
checkIfToastParamIsValid(param);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
checkIfParamIsDeprecated(param);
|
|
246
|
+
}
|
|
122
247
|
};
|
|
123
248
|
|
|
124
249
|
const swalPrefix = 'swal2-';
|
|
@@ -134,6 +259,12 @@
|
|
|
134
259
|
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']);
|
|
135
260
|
const iconTypes = prefix(['success', 'warning', 'info', 'question', 'error']);
|
|
136
261
|
|
|
262
|
+
/**
|
|
263
|
+
* Gets the popup container which contains the backdrop and the popup itself.
|
|
264
|
+
*
|
|
265
|
+
* @returns {HTMLElement | null}
|
|
266
|
+
*/
|
|
267
|
+
|
|
137
268
|
const getContainer = () => document.body.querySelector(".".concat(swalClasses.container));
|
|
138
269
|
const elementBySelector = selectorString => {
|
|
139
270
|
const container = getContainer();
|
|
@@ -180,10 +311,10 @@
|
|
|
180
311
|
return uniqueArray(focusableElementsWithTabindex.concat(otherFocusableElements)).filter(el => isVisible(el));
|
|
181
312
|
};
|
|
182
313
|
const isModal = () => {
|
|
183
|
-
return !
|
|
314
|
+
return !hasClass(document.body, swalClasses['toast-shown']) && !hasClass(document.body, swalClasses['no-backdrop']);
|
|
184
315
|
};
|
|
185
316
|
const isToast = () => {
|
|
186
|
-
return
|
|
317
|
+
return getPopup() && hasClass(getPopup(), swalClasses.toast);
|
|
187
318
|
};
|
|
188
319
|
const isLoading = () => {
|
|
189
320
|
return getPopup().hasAttribute('data-loading');
|
|
@@ -192,8 +323,15 @@
|
|
|
192
323
|
const states = {
|
|
193
324
|
previousBodyPadding: null
|
|
194
325
|
};
|
|
326
|
+
/**
|
|
327
|
+
* Securely set innerHTML of an element
|
|
328
|
+
* https://github.com/sweetalert2/sweetalert2/issues/1926
|
|
329
|
+
*
|
|
330
|
+
* @param {HTMLElement} elem
|
|
331
|
+
* @param {string} html
|
|
332
|
+
*/
|
|
333
|
+
|
|
195
334
|
const setInnerHtml = (elem, html) => {
|
|
196
|
-
// #1926
|
|
197
335
|
elem.textContent = '';
|
|
198
336
|
|
|
199
337
|
if (html) {
|
|
@@ -207,6 +345,12 @@
|
|
|
207
345
|
});
|
|
208
346
|
}
|
|
209
347
|
};
|
|
348
|
+
/**
|
|
349
|
+
* @param {HTMLElement} elem
|
|
350
|
+
* @param {string} className
|
|
351
|
+
* @returns {boolean}
|
|
352
|
+
*/
|
|
353
|
+
|
|
210
354
|
const hasClass = (elem, className) => {
|
|
211
355
|
if (!className) {
|
|
212
356
|
return false;
|
|
@@ -242,6 +386,12 @@
|
|
|
242
386
|
addClass(elem, params.customClass[className]);
|
|
243
387
|
}
|
|
244
388
|
};
|
|
389
|
+
/**
|
|
390
|
+
* @param {HTMLElement} popup
|
|
391
|
+
* @param {string} inputType
|
|
392
|
+
* @returns {HTMLInputElement | null}
|
|
393
|
+
*/
|
|
394
|
+
|
|
245
395
|
const getInput = (popup, inputType) => {
|
|
246
396
|
if (!inputType) {
|
|
247
397
|
return null;
|
|
@@ -251,7 +401,7 @@
|
|
|
251
401
|
case 'select':
|
|
252
402
|
case 'textarea':
|
|
253
403
|
case 'file':
|
|
254
|
-
return
|
|
404
|
+
return popup.querySelector(".".concat(swalClasses[inputType]));
|
|
255
405
|
|
|
256
406
|
case 'checkbox':
|
|
257
407
|
return popup.querySelector(".".concat(swalClasses.checkbox, " input"));
|
|
@@ -263,9 +413,13 @@
|
|
|
263
413
|
return popup.querySelector(".".concat(swalClasses.range, " input"));
|
|
264
414
|
|
|
265
415
|
default:
|
|
266
|
-
return
|
|
416
|
+
return popup.querySelector(".".concat(swalClasses.input));
|
|
267
417
|
}
|
|
268
418
|
};
|
|
419
|
+
/**
|
|
420
|
+
* @param {HTMLInputElement} input
|
|
421
|
+
*/
|
|
422
|
+
|
|
269
423
|
const focusInput = input => {
|
|
270
424
|
input.focus(); // place cursor at end of text in text input
|
|
271
425
|
|
|
@@ -276,6 +430,12 @@
|
|
|
276
430
|
input.value = val;
|
|
277
431
|
}
|
|
278
432
|
};
|
|
433
|
+
/**
|
|
434
|
+
* @param {HTMLElement | HTMLElement[] | null} target
|
|
435
|
+
* @param {string | string[]} classList
|
|
436
|
+
* @param {boolean} condition
|
|
437
|
+
*/
|
|
438
|
+
|
|
279
439
|
const toggleClass = (target, classList, condition) => {
|
|
280
440
|
if (!target || !classList) {
|
|
281
441
|
return;
|
|
@@ -286,7 +446,7 @@
|
|
|
286
446
|
}
|
|
287
447
|
|
|
288
448
|
classList.forEach(className => {
|
|
289
|
-
if (target
|
|
449
|
+
if (Array.isArray(target)) {
|
|
290
450
|
target.forEach(elem => {
|
|
291
451
|
condition ? elem.classList.add(className) : elem.classList.remove(className);
|
|
292
452
|
});
|
|
@@ -295,19 +455,43 @@
|
|
|
295
455
|
}
|
|
296
456
|
});
|
|
297
457
|
};
|
|
458
|
+
/**
|
|
459
|
+
* @param {HTMLElement | HTMLElement[] | null} target
|
|
460
|
+
* @param {string | string[]} classList
|
|
461
|
+
*/
|
|
462
|
+
|
|
298
463
|
const addClass = (target, classList) => {
|
|
299
464
|
toggleClass(target, classList, true);
|
|
300
465
|
};
|
|
466
|
+
/**
|
|
467
|
+
* @param {HTMLElement | HTMLElement[] | null} target
|
|
468
|
+
* @param {string | string[]} classList
|
|
469
|
+
*/
|
|
470
|
+
|
|
301
471
|
const removeClass = (target, classList) => {
|
|
302
472
|
toggleClass(target, classList, false);
|
|
303
473
|
};
|
|
474
|
+
/**
|
|
475
|
+
* @param {HTMLElement} elem
|
|
476
|
+
* @param {string} className
|
|
477
|
+
* @returns {HTMLElement | null}
|
|
478
|
+
*/
|
|
479
|
+
|
|
304
480
|
const getChildByClass = (elem, className) => {
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
481
|
+
const childNodes = toArray(elem.childNodes);
|
|
482
|
+
|
|
483
|
+
for (let i = 0; i < childNodes.length; i++) {
|
|
484
|
+
if (hasClass(childNodes[i], className)) {
|
|
485
|
+
return childNodes[i];
|
|
308
486
|
}
|
|
309
487
|
}
|
|
310
488
|
};
|
|
489
|
+
/**
|
|
490
|
+
* @param {HTMLElement} elem
|
|
491
|
+
* @param {string} property
|
|
492
|
+
* @param {*} value
|
|
493
|
+
*/
|
|
494
|
+
|
|
311
495
|
const applyNumericalStyle = (elem, property, value) => {
|
|
312
496
|
if (value === "".concat(parseInt(value))) {
|
|
313
497
|
value = parseInt(value);
|
|
@@ -319,10 +503,19 @@
|
|
|
319
503
|
elem.style.removeProperty(property);
|
|
320
504
|
}
|
|
321
505
|
};
|
|
506
|
+
/**
|
|
507
|
+
* @param {HTMLElement} elem
|
|
508
|
+
* @param {string} display
|
|
509
|
+
*/
|
|
510
|
+
|
|
322
511
|
const show = function (elem) {
|
|
323
512
|
let display = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'flex';
|
|
324
513
|
elem.style.display = display;
|
|
325
514
|
};
|
|
515
|
+
/**
|
|
516
|
+
* @param {HTMLElement} elem
|
|
517
|
+
*/
|
|
518
|
+
|
|
326
519
|
const hide = elem => {
|
|
327
520
|
elem.style.display = 'none';
|
|
328
521
|
};
|
|
@@ -369,7 +562,7 @@
|
|
|
369
562
|
timerProgressBar.style.removeProperty('transition');
|
|
370
563
|
timerProgressBar.style.width = '100%';
|
|
371
564
|
const timerProgressBarFullWidth = parseInt(window.getComputedStyle(timerProgressBar).width);
|
|
372
|
-
const timerProgressBarPercent =
|
|
565
|
+
const timerProgressBarPercent = timerProgressBarWidth / timerProgressBarFullWidth * 100;
|
|
373
566
|
timerProgressBar.style.removeProperty('transition');
|
|
374
567
|
timerProgressBar.style.width = "".concat(timerProgressBarPercent, "%");
|
|
375
568
|
};
|
|
@@ -377,6 +570,37 @@
|
|
|
377
570
|
// Detect Node env
|
|
378
571
|
const isNodeEnv = () => typeof window === 'undefined' || typeof document === 'undefined';
|
|
379
572
|
|
|
573
|
+
const RESTORE_FOCUS_TIMEOUT = 100;
|
|
574
|
+
|
|
575
|
+
const globalState = {};
|
|
576
|
+
|
|
577
|
+
const focusPreviousActiveElement = () => {
|
|
578
|
+
if (globalState.previousActiveElement && globalState.previousActiveElement.focus) {
|
|
579
|
+
globalState.previousActiveElement.focus();
|
|
580
|
+
globalState.previousActiveElement = null;
|
|
581
|
+
} else if (document.body) {
|
|
582
|
+
document.body.focus();
|
|
583
|
+
}
|
|
584
|
+
}; // Restore previous active (focused) element
|
|
585
|
+
|
|
586
|
+
|
|
587
|
+
const restoreActiveElement = returnFocus => {
|
|
588
|
+
return new Promise(resolve => {
|
|
589
|
+
if (!returnFocus) {
|
|
590
|
+
return resolve();
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
const x = window.scrollX;
|
|
594
|
+
const y = window.scrollY;
|
|
595
|
+
globalState.restoreFocusTimeout = setTimeout(() => {
|
|
596
|
+
focusPreviousActiveElement();
|
|
597
|
+
resolve();
|
|
598
|
+
}, RESTORE_FOCUS_TIMEOUT); // issues/900
|
|
599
|
+
|
|
600
|
+
window.scrollTo(x, y);
|
|
601
|
+
});
|
|
602
|
+
};
|
|
603
|
+
|
|
380
604
|
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, '');
|
|
381
605
|
|
|
382
606
|
const resetOldContainer = () => {
|
|
@@ -392,9 +616,7 @@
|
|
|
392
616
|
};
|
|
393
617
|
|
|
394
618
|
const resetValidationMessage = () => {
|
|
395
|
-
|
|
396
|
-
Swal.resetValidationMessage();
|
|
397
|
-
}
|
|
619
|
+
globalState.currentInstance.resetValidationMessage();
|
|
398
620
|
};
|
|
399
621
|
|
|
400
622
|
const addInputChangeListeners = () => {
|
|
@@ -821,8 +1043,9 @@
|
|
|
821
1043
|
};
|
|
822
1044
|
|
|
823
1045
|
renderInputType.checkbox = (checkboxContainer, params) => {
|
|
1046
|
+
/** @type {HTMLInputElement} */
|
|
824
1047
|
const checkbox = getInput(getPopup(), 'checkbox');
|
|
825
|
-
checkbox.value = 1;
|
|
1048
|
+
checkbox.value = '1';
|
|
826
1049
|
checkbox.id = swalClasses.checkbox;
|
|
827
1050
|
checkbox.checked = Boolean(params.inputValue);
|
|
828
1051
|
const label = checkboxContainer.querySelector('span');
|
|
@@ -1087,7 +1310,12 @@
|
|
|
1087
1310
|
} // Padding
|
|
1088
1311
|
|
|
1089
1312
|
|
|
1090
|
-
applyNumericalStyle(popup, 'padding', params.padding); //
|
|
1313
|
+
applyNumericalStyle(popup, 'padding', params.padding); // Color
|
|
1314
|
+
|
|
1315
|
+
if (params.color) {
|
|
1316
|
+
popup.style.color = params.color;
|
|
1317
|
+
} // Background
|
|
1318
|
+
|
|
1091
1319
|
|
|
1092
1320
|
if (params.background) {
|
|
1093
1321
|
popup.style.background = params.background;
|
|
@@ -1139,587 +1367,13 @@
|
|
|
1139
1367
|
}
|
|
1140
1368
|
};
|
|
1141
1369
|
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
};
|
|
1149
|
-
/*
|
|
1150
|
-
* Global function to click 'Confirm' button
|
|
1151
|
-
*/
|
|
1152
|
-
|
|
1153
|
-
const clickConfirm = () => getConfirmButton() && getConfirmButton().click();
|
|
1154
|
-
/*
|
|
1155
|
-
* Global function to click 'Deny' button
|
|
1156
|
-
*/
|
|
1157
|
-
|
|
1158
|
-
const clickDeny = () => getDenyButton() && getDenyButton().click();
|
|
1159
|
-
/*
|
|
1160
|
-
* Global function to click 'Cancel' button
|
|
1161
|
-
*/
|
|
1162
|
-
|
|
1163
|
-
const clickCancel = () => getCancelButton() && getCancelButton().click();
|
|
1164
|
-
|
|
1165
|
-
function fire() {
|
|
1166
|
-
const Swal = this;
|
|
1167
|
-
|
|
1168
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1169
|
-
args[_key] = arguments[_key];
|
|
1170
|
-
}
|
|
1171
|
-
|
|
1172
|
-
return new Swal(...args);
|
|
1173
|
-
}
|
|
1174
|
-
|
|
1175
|
-
/**
|
|
1176
|
-
* Returns an extended version of `Swal` containing `params` as defaults.
|
|
1177
|
-
* Useful for reusing Swal configuration.
|
|
1178
|
-
*
|
|
1179
|
-
* For example:
|
|
1180
|
-
*
|
|
1181
|
-
* Before:
|
|
1182
|
-
* const textPromptOptions = { input: 'text', showCancelButton: true }
|
|
1183
|
-
* const {value: firstName} = await Swal.fire({ ...textPromptOptions, title: 'What is your first name?' })
|
|
1184
|
-
* const {value: lastName} = await Swal.fire({ ...textPromptOptions, title: 'What is your last name?' })
|
|
1185
|
-
*
|
|
1186
|
-
* After:
|
|
1187
|
-
* const TextPrompt = Swal.mixin({ input: 'text', showCancelButton: true })
|
|
1188
|
-
* const {value: firstName} = await TextPrompt('What is your first name?')
|
|
1189
|
-
* const {value: lastName} = await TextPrompt('What is your last name?')
|
|
1190
|
-
*
|
|
1191
|
-
* @param mixinParams
|
|
1192
|
-
*/
|
|
1193
|
-
function mixin(mixinParams) {
|
|
1194
|
-
class MixinSwal extends this {
|
|
1195
|
-
_main(params, priorityMixinParams) {
|
|
1196
|
-
return super._main(params, Object.assign({}, mixinParams, priorityMixinParams));
|
|
1197
|
-
}
|
|
1198
|
-
|
|
1199
|
-
}
|
|
1200
|
-
|
|
1201
|
-
return MixinSwal;
|
|
1202
|
-
}
|
|
1203
|
-
|
|
1204
|
-
/**
|
|
1205
|
-
* Shows loader (spinner), this is useful with AJAX requests.
|
|
1206
|
-
* By default the loader be shown instead of the "Confirm" button.
|
|
1207
|
-
*/
|
|
1208
|
-
|
|
1209
|
-
const showLoading = buttonToReplace => {
|
|
1210
|
-
let popup = getPopup();
|
|
1211
|
-
|
|
1212
|
-
if (!popup) {
|
|
1213
|
-
Swal.fire();
|
|
1214
|
-
}
|
|
1215
|
-
|
|
1216
|
-
popup = getPopup();
|
|
1217
|
-
const loader = getLoader();
|
|
1218
|
-
|
|
1219
|
-
if (isToast()) {
|
|
1220
|
-
hide(getIcon());
|
|
1221
|
-
} else {
|
|
1222
|
-
replaceButton(popup, buttonToReplace);
|
|
1223
|
-
}
|
|
1224
|
-
|
|
1225
|
-
show(loader);
|
|
1226
|
-
popup.setAttribute('data-loading', true);
|
|
1227
|
-
popup.setAttribute('aria-busy', true);
|
|
1228
|
-
popup.focus();
|
|
1229
|
-
};
|
|
1230
|
-
|
|
1231
|
-
const replaceButton = (popup, buttonToReplace) => {
|
|
1232
|
-
const actions = getActions();
|
|
1233
|
-
const loader = getLoader();
|
|
1234
|
-
|
|
1235
|
-
if (!buttonToReplace && isVisible(getConfirmButton())) {
|
|
1236
|
-
buttonToReplace = getConfirmButton();
|
|
1237
|
-
}
|
|
1238
|
-
|
|
1239
|
-
show(actions);
|
|
1240
|
-
|
|
1241
|
-
if (buttonToReplace) {
|
|
1242
|
-
hide(buttonToReplace);
|
|
1243
|
-
loader.setAttribute('data-button-to-replace', buttonToReplace.className);
|
|
1244
|
-
}
|
|
1245
|
-
|
|
1246
|
-
loader.parentNode.insertBefore(loader, buttonToReplace);
|
|
1247
|
-
addClass([popup, actions], swalClasses.loading);
|
|
1248
|
-
};
|
|
1249
|
-
|
|
1250
|
-
const RESTORE_FOCUS_TIMEOUT = 100;
|
|
1251
|
-
|
|
1252
|
-
const globalState = {};
|
|
1253
|
-
|
|
1254
|
-
const focusPreviousActiveElement = () => {
|
|
1255
|
-
if (globalState.previousActiveElement && globalState.previousActiveElement.focus) {
|
|
1256
|
-
globalState.previousActiveElement.focus();
|
|
1257
|
-
globalState.previousActiveElement = null;
|
|
1258
|
-
} else if (document.body) {
|
|
1259
|
-
document.body.focus();
|
|
1260
|
-
}
|
|
1261
|
-
}; // Restore previous active (focused) element
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
const restoreActiveElement = returnFocus => {
|
|
1265
|
-
return new Promise(resolve => {
|
|
1266
|
-
if (!returnFocus) {
|
|
1267
|
-
return resolve();
|
|
1268
|
-
}
|
|
1269
|
-
|
|
1270
|
-
const x = window.scrollX;
|
|
1271
|
-
const y = window.scrollY;
|
|
1272
|
-
globalState.restoreFocusTimeout = setTimeout(() => {
|
|
1273
|
-
focusPreviousActiveElement();
|
|
1274
|
-
resolve();
|
|
1275
|
-
}, RESTORE_FOCUS_TIMEOUT); // issues/900
|
|
1276
|
-
|
|
1277
|
-
window.scrollTo(x, y);
|
|
1278
|
-
});
|
|
1279
|
-
};
|
|
1280
|
-
|
|
1281
|
-
/**
|
|
1282
|
-
* If `timer` parameter is set, returns number of milliseconds of timer remained.
|
|
1283
|
-
* Otherwise, returns undefined.
|
|
1284
|
-
*/
|
|
1285
|
-
|
|
1286
|
-
const getTimerLeft = () => {
|
|
1287
|
-
return globalState.timeout && globalState.timeout.getTimerLeft();
|
|
1288
|
-
};
|
|
1289
|
-
/**
|
|
1290
|
-
* Stop timer. Returns number of milliseconds of timer remained.
|
|
1291
|
-
* If `timer` parameter isn't set, returns undefined.
|
|
1292
|
-
*/
|
|
1293
|
-
|
|
1294
|
-
const stopTimer = () => {
|
|
1295
|
-
if (globalState.timeout) {
|
|
1296
|
-
stopTimerProgressBar();
|
|
1297
|
-
return globalState.timeout.stop();
|
|
1298
|
-
}
|
|
1299
|
-
};
|
|
1300
|
-
/**
|
|
1301
|
-
* Resume timer. Returns number of milliseconds of timer remained.
|
|
1302
|
-
* If `timer` parameter isn't set, returns undefined.
|
|
1303
|
-
*/
|
|
1304
|
-
|
|
1305
|
-
const resumeTimer = () => {
|
|
1306
|
-
if (globalState.timeout) {
|
|
1307
|
-
const remaining = globalState.timeout.start();
|
|
1308
|
-
animateTimerProgressBar(remaining);
|
|
1309
|
-
return remaining;
|
|
1310
|
-
}
|
|
1311
|
-
};
|
|
1312
|
-
/**
|
|
1313
|
-
* Resume timer. Returns number of milliseconds of timer remained.
|
|
1314
|
-
* If `timer` parameter isn't set, returns undefined.
|
|
1315
|
-
*/
|
|
1316
|
-
|
|
1317
|
-
const toggleTimer = () => {
|
|
1318
|
-
const timer = globalState.timeout;
|
|
1319
|
-
return timer && (timer.running ? stopTimer() : resumeTimer());
|
|
1320
|
-
};
|
|
1321
|
-
/**
|
|
1322
|
-
* Increase timer. Returns number of milliseconds of an updated timer.
|
|
1323
|
-
* If `timer` parameter isn't set, returns undefined.
|
|
1324
|
-
*/
|
|
1325
|
-
|
|
1326
|
-
const increaseTimer = n => {
|
|
1327
|
-
if (globalState.timeout) {
|
|
1328
|
-
const remaining = globalState.timeout.increase(n);
|
|
1329
|
-
animateTimerProgressBar(remaining, true);
|
|
1330
|
-
return remaining;
|
|
1331
|
-
}
|
|
1332
|
-
};
|
|
1333
|
-
/**
|
|
1334
|
-
* Check if timer is running. Returns true if timer is running
|
|
1335
|
-
* or false if timer is paused or stopped.
|
|
1336
|
-
* If `timer` parameter isn't set, returns undefined
|
|
1337
|
-
*/
|
|
1338
|
-
|
|
1339
|
-
const isTimerRunning = () => {
|
|
1340
|
-
return globalState.timeout && globalState.timeout.isRunning();
|
|
1341
|
-
};
|
|
1342
|
-
|
|
1343
|
-
let bodyClickListenerAdded = false;
|
|
1344
|
-
const clickHandlers = {};
|
|
1345
|
-
function bindClickHandler() {
|
|
1346
|
-
let attr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'data-swal-template';
|
|
1347
|
-
clickHandlers[attr] = this;
|
|
1348
|
-
|
|
1349
|
-
if (!bodyClickListenerAdded) {
|
|
1350
|
-
document.body.addEventListener('click', bodyClickListener);
|
|
1351
|
-
bodyClickListenerAdded = true;
|
|
1352
|
-
}
|
|
1353
|
-
}
|
|
1354
|
-
|
|
1355
|
-
const bodyClickListener = event => {
|
|
1356
|
-
for (let el = event.target; el && el !== document; el = el.parentNode) {
|
|
1357
|
-
for (const attr in clickHandlers) {
|
|
1358
|
-
const template = el.getAttribute(attr);
|
|
1359
|
-
|
|
1360
|
-
if (template) {
|
|
1361
|
-
clickHandlers[attr].fire({
|
|
1362
|
-
template
|
|
1363
|
-
});
|
|
1364
|
-
return;
|
|
1365
|
-
}
|
|
1366
|
-
}
|
|
1367
|
-
}
|
|
1368
|
-
};
|
|
1369
|
-
|
|
1370
|
-
const defaultParams = {
|
|
1371
|
-
title: '',
|
|
1372
|
-
titleText: '',
|
|
1373
|
-
text: '',
|
|
1374
|
-
html: '',
|
|
1375
|
-
footer: '',
|
|
1376
|
-
icon: undefined,
|
|
1377
|
-
iconColor: undefined,
|
|
1378
|
-
iconHtml: undefined,
|
|
1379
|
-
template: undefined,
|
|
1380
|
-
toast: false,
|
|
1381
|
-
showClass: {
|
|
1382
|
-
popup: 'swal2-show',
|
|
1383
|
-
backdrop: 'swal2-backdrop-show',
|
|
1384
|
-
icon: 'swal2-icon-show'
|
|
1385
|
-
},
|
|
1386
|
-
hideClass: {
|
|
1387
|
-
popup: 'swal2-hide',
|
|
1388
|
-
backdrop: 'swal2-backdrop-hide',
|
|
1389
|
-
icon: 'swal2-icon-hide'
|
|
1390
|
-
},
|
|
1391
|
-
customClass: {},
|
|
1392
|
-
target: 'body',
|
|
1393
|
-
backdrop: true,
|
|
1394
|
-
heightAuto: true,
|
|
1395
|
-
allowOutsideClick: true,
|
|
1396
|
-
allowEscapeKey: true,
|
|
1397
|
-
allowEnterKey: true,
|
|
1398
|
-
stopKeydownPropagation: true,
|
|
1399
|
-
keydownListenerCapture: false,
|
|
1400
|
-
showConfirmButton: true,
|
|
1401
|
-
showDenyButton: false,
|
|
1402
|
-
showCancelButton: false,
|
|
1403
|
-
preConfirm: undefined,
|
|
1404
|
-
preDeny: undefined,
|
|
1405
|
-
confirmButtonText: 'OK',
|
|
1406
|
-
confirmButtonAriaLabel: '',
|
|
1407
|
-
confirmButtonColor: undefined,
|
|
1408
|
-
denyButtonText: 'No',
|
|
1409
|
-
denyButtonAriaLabel: '',
|
|
1410
|
-
denyButtonColor: undefined,
|
|
1411
|
-
cancelButtonText: 'Cancel',
|
|
1412
|
-
cancelButtonAriaLabel: '',
|
|
1413
|
-
cancelButtonColor: undefined,
|
|
1414
|
-
buttonsStyling: true,
|
|
1415
|
-
reverseButtons: false,
|
|
1416
|
-
focusConfirm: true,
|
|
1417
|
-
focusDeny: false,
|
|
1418
|
-
focusCancel: false,
|
|
1419
|
-
returnFocus: true,
|
|
1420
|
-
showCloseButton: false,
|
|
1421
|
-
closeButtonHtml: '×',
|
|
1422
|
-
closeButtonAriaLabel: 'Close this dialog',
|
|
1423
|
-
loaderHtml: '',
|
|
1424
|
-
showLoaderOnConfirm: false,
|
|
1425
|
-
showLoaderOnDeny: false,
|
|
1426
|
-
imageUrl: undefined,
|
|
1427
|
-
imageWidth: undefined,
|
|
1428
|
-
imageHeight: undefined,
|
|
1429
|
-
imageAlt: '',
|
|
1430
|
-
timer: undefined,
|
|
1431
|
-
timerProgressBar: false,
|
|
1432
|
-
width: undefined,
|
|
1433
|
-
padding: undefined,
|
|
1434
|
-
background: undefined,
|
|
1435
|
-
input: undefined,
|
|
1436
|
-
inputPlaceholder: '',
|
|
1437
|
-
inputLabel: '',
|
|
1438
|
-
inputValue: '',
|
|
1439
|
-
inputOptions: {},
|
|
1440
|
-
inputAutoTrim: true,
|
|
1441
|
-
inputAttributes: {},
|
|
1442
|
-
inputValidator: undefined,
|
|
1443
|
-
returnInputValueOnDeny: false,
|
|
1444
|
-
validationMessage: undefined,
|
|
1445
|
-
grow: false,
|
|
1446
|
-
position: 'center',
|
|
1447
|
-
progressSteps: [],
|
|
1448
|
-
currentProgressStep: undefined,
|
|
1449
|
-
progressStepsDistance: undefined,
|
|
1450
|
-
willOpen: undefined,
|
|
1451
|
-
didOpen: undefined,
|
|
1452
|
-
didRender: undefined,
|
|
1453
|
-
willClose: undefined,
|
|
1454
|
-
didClose: undefined,
|
|
1455
|
-
didDestroy: undefined,
|
|
1456
|
-
scrollbarPadding: true
|
|
1457
|
-
};
|
|
1458
|
-
const updatableParams = ['allowEscapeKey', 'allowOutsideClick', 'background', 'buttonsStyling', 'cancelButtonAriaLabel', 'cancelButtonColor', 'cancelButtonText', 'closeButtonAriaLabel', 'closeButtonHtml', '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'];
|
|
1459
|
-
const deprecatedParams = {};
|
|
1460
|
-
const toastIncompatibleParams = ['allowOutsideClick', 'allowEnterKey', 'backdrop', 'focusConfirm', 'focusDeny', 'focusCancel', 'returnFocus', 'heightAuto', 'keydownListenerCapture'];
|
|
1461
|
-
/**
|
|
1462
|
-
* Is valid parameter
|
|
1463
|
-
* @param {String} paramName
|
|
1464
|
-
*/
|
|
1465
|
-
|
|
1466
|
-
const isValidParameter = paramName => {
|
|
1467
|
-
return Object.prototype.hasOwnProperty.call(defaultParams, paramName);
|
|
1468
|
-
};
|
|
1469
|
-
/**
|
|
1470
|
-
* Is valid parameter for Swal.update() method
|
|
1471
|
-
* @param {String} paramName
|
|
1472
|
-
*/
|
|
1473
|
-
|
|
1474
|
-
const isUpdatableParameter = paramName => {
|
|
1475
|
-
return updatableParams.indexOf(paramName) !== -1;
|
|
1476
|
-
};
|
|
1477
|
-
/**
|
|
1478
|
-
* Is deprecated parameter
|
|
1479
|
-
* @param {String} paramName
|
|
1480
|
-
*/
|
|
1481
|
-
|
|
1482
|
-
const isDeprecatedParameter = paramName => {
|
|
1483
|
-
return deprecatedParams[paramName];
|
|
1484
|
-
};
|
|
1485
|
-
|
|
1486
|
-
const checkIfParamIsValid = param => {
|
|
1487
|
-
if (!isValidParameter(param)) {
|
|
1488
|
-
warn("Unknown parameter \"".concat(param, "\""));
|
|
1489
|
-
}
|
|
1490
|
-
};
|
|
1491
|
-
|
|
1492
|
-
const checkIfToastParamIsValid = param => {
|
|
1493
|
-
if (toastIncompatibleParams.includes(param)) {
|
|
1494
|
-
warn("The parameter \"".concat(param, "\" is incompatible with toasts"));
|
|
1495
|
-
}
|
|
1496
|
-
};
|
|
1497
|
-
|
|
1498
|
-
const checkIfParamIsDeprecated = param => {
|
|
1499
|
-
if (isDeprecatedParameter(param)) {
|
|
1500
|
-
warnAboutDeprecation(param, isDeprecatedParameter(param));
|
|
1501
|
-
}
|
|
1502
|
-
};
|
|
1503
|
-
/**
|
|
1504
|
-
* Show relevant warnings for given params
|
|
1505
|
-
*
|
|
1506
|
-
* @param params
|
|
1507
|
-
*/
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
const showWarningsForParams = params => {
|
|
1511
|
-
if (!params.backdrop && params.allowOutsideClick) {
|
|
1512
|
-
warn('"allowOutsideClick" parameter requires `backdrop` parameter to be set to `true`');
|
|
1513
|
-
}
|
|
1514
|
-
|
|
1515
|
-
for (const param in params) {
|
|
1516
|
-
checkIfParamIsValid(param);
|
|
1517
|
-
|
|
1518
|
-
if (params.toast) {
|
|
1519
|
-
checkIfToastParamIsValid(param);
|
|
1520
|
-
}
|
|
1521
|
-
|
|
1522
|
-
checkIfParamIsDeprecated(param);
|
|
1523
|
-
}
|
|
1524
|
-
};
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
var staticMethods = /*#__PURE__*/Object.freeze({
|
|
1529
|
-
isValidParameter: isValidParameter,
|
|
1530
|
-
isUpdatableParameter: isUpdatableParameter,
|
|
1531
|
-
isDeprecatedParameter: isDeprecatedParameter,
|
|
1532
|
-
argsToParams: argsToParams,
|
|
1533
|
-
isVisible: isVisible$1,
|
|
1534
|
-
clickConfirm: clickConfirm,
|
|
1535
|
-
clickDeny: clickDeny,
|
|
1536
|
-
clickCancel: clickCancel,
|
|
1537
|
-
getContainer: getContainer,
|
|
1538
|
-
getPopup: getPopup,
|
|
1539
|
-
getTitle: getTitle,
|
|
1540
|
-
getHtmlContainer: getHtmlContainer,
|
|
1541
|
-
getImage: getImage,
|
|
1542
|
-
getIcon: getIcon,
|
|
1543
|
-
getInputLabel: getInputLabel,
|
|
1544
|
-
getCloseButton: getCloseButton,
|
|
1545
|
-
getActions: getActions,
|
|
1546
|
-
getConfirmButton: getConfirmButton,
|
|
1547
|
-
getDenyButton: getDenyButton,
|
|
1548
|
-
getCancelButton: getCancelButton,
|
|
1549
|
-
getLoader: getLoader,
|
|
1550
|
-
getFooter: getFooter,
|
|
1551
|
-
getTimerProgressBar: getTimerProgressBar,
|
|
1552
|
-
getFocusableElements: getFocusableElements,
|
|
1553
|
-
getValidationMessage: getValidationMessage,
|
|
1554
|
-
isLoading: isLoading,
|
|
1555
|
-
fire: fire,
|
|
1556
|
-
mixin: mixin,
|
|
1557
|
-
showLoading: showLoading,
|
|
1558
|
-
enableLoading: showLoading,
|
|
1559
|
-
getTimerLeft: getTimerLeft,
|
|
1560
|
-
stopTimer: stopTimer,
|
|
1561
|
-
resumeTimer: resumeTimer,
|
|
1562
|
-
toggleTimer: toggleTimer,
|
|
1563
|
-
increaseTimer: increaseTimer,
|
|
1564
|
-
isTimerRunning: isTimerRunning,
|
|
1565
|
-
bindClickHandler: bindClickHandler
|
|
1566
|
-
});
|
|
1567
|
-
|
|
1568
|
-
/**
|
|
1569
|
-
* Hides loader and shows back the button which was hidden by .showLoading()
|
|
1570
|
-
*/
|
|
1571
|
-
|
|
1572
|
-
function hideLoading() {
|
|
1573
|
-
// do nothing if popup is closed
|
|
1574
|
-
const innerParams = privateProps.innerParams.get(this);
|
|
1575
|
-
|
|
1576
|
-
if (!innerParams) {
|
|
1577
|
-
return;
|
|
1578
|
-
}
|
|
1579
|
-
|
|
1580
|
-
const domCache = privateProps.domCache.get(this);
|
|
1581
|
-
hide(domCache.loader);
|
|
1582
|
-
|
|
1583
|
-
if (isToast()) {
|
|
1584
|
-
if (innerParams.icon) {
|
|
1585
|
-
show(getIcon());
|
|
1586
|
-
}
|
|
1587
|
-
} else {
|
|
1588
|
-
showRelatedButton(domCache);
|
|
1589
|
-
}
|
|
1590
|
-
|
|
1591
|
-
removeClass([domCache.popup, domCache.actions], swalClasses.loading);
|
|
1592
|
-
domCache.popup.removeAttribute('aria-busy');
|
|
1593
|
-
domCache.popup.removeAttribute('data-loading');
|
|
1594
|
-
domCache.confirmButton.disabled = false;
|
|
1595
|
-
domCache.denyButton.disabled = false;
|
|
1596
|
-
domCache.cancelButton.disabled = false;
|
|
1597
|
-
}
|
|
1598
|
-
|
|
1599
|
-
const showRelatedButton = domCache => {
|
|
1600
|
-
const buttonToReplace = domCache.popup.getElementsByClassName(domCache.loader.getAttribute('data-button-to-replace'));
|
|
1601
|
-
|
|
1602
|
-
if (buttonToReplace.length) {
|
|
1603
|
-
show(buttonToReplace[0], 'inline-block');
|
|
1604
|
-
} else if (allButtonsAreHidden()) {
|
|
1605
|
-
hide(domCache.actions);
|
|
1606
|
-
}
|
|
1607
|
-
};
|
|
1608
|
-
|
|
1609
|
-
function getInput$1(instance) {
|
|
1610
|
-
const innerParams = privateProps.innerParams.get(instance || this);
|
|
1611
|
-
const domCache = privateProps.domCache.get(instance || this);
|
|
1612
|
-
|
|
1613
|
-
if (!domCache) {
|
|
1614
|
-
return null;
|
|
1615
|
-
}
|
|
1616
|
-
|
|
1617
|
-
return getInput(domCache.popup, innerParams.input);
|
|
1618
|
-
}
|
|
1619
|
-
|
|
1620
|
-
const fixScrollbar = () => {
|
|
1621
|
-
// for queues, do not do this more than once
|
|
1622
|
-
if (states.previousBodyPadding !== null) {
|
|
1623
|
-
return;
|
|
1624
|
-
} // if the body has overflow
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
if (document.body.scrollHeight > window.innerHeight) {
|
|
1628
|
-
// add padding so the content doesn't shift after removal of scrollbar
|
|
1629
|
-
states.previousBodyPadding = parseInt(window.getComputedStyle(document.body).getPropertyValue('padding-right'));
|
|
1630
|
-
document.body.style.paddingRight = "".concat(states.previousBodyPadding + measureScrollbar(), "px");
|
|
1631
|
-
}
|
|
1632
|
-
};
|
|
1633
|
-
const undoScrollbar = () => {
|
|
1634
|
-
if (states.previousBodyPadding !== null) {
|
|
1635
|
-
document.body.style.paddingRight = "".concat(states.previousBodyPadding, "px");
|
|
1636
|
-
states.previousBodyPadding = null;
|
|
1637
|
-
}
|
|
1638
|
-
};
|
|
1639
|
-
|
|
1640
|
-
/* istanbul ignore file */
|
|
1641
|
-
|
|
1642
|
-
const iOSfix = () => {
|
|
1643
|
-
const iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream || navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1;
|
|
1644
|
-
|
|
1645
|
-
if (iOS && !hasClass(document.body, swalClasses.iosfix)) {
|
|
1646
|
-
const offset = document.body.scrollTop;
|
|
1647
|
-
document.body.style.top = "".concat(offset * -1, "px");
|
|
1648
|
-
addClass(document.body, swalClasses.iosfix);
|
|
1649
|
-
lockBodyScroll();
|
|
1650
|
-
addBottomPaddingForTallPopups(); // #1948
|
|
1651
|
-
}
|
|
1652
|
-
};
|
|
1653
|
-
|
|
1654
|
-
const addBottomPaddingForTallPopups = () => {
|
|
1655
|
-
const safari = !navigator.userAgent.match(/(CriOS|FxiOS|EdgiOS|YaBrowser|UCBrowser)/i);
|
|
1656
|
-
|
|
1657
|
-
if (safari) {
|
|
1658
|
-
const bottomPanelHeight = 44;
|
|
1659
|
-
|
|
1660
|
-
if (getPopup().scrollHeight > window.innerHeight - bottomPanelHeight) {
|
|
1661
|
-
getContainer().style.paddingBottom = "".concat(bottomPanelHeight, "px");
|
|
1662
|
-
}
|
|
1663
|
-
}
|
|
1664
|
-
};
|
|
1665
|
-
|
|
1666
|
-
const lockBodyScroll = () => {
|
|
1667
|
-
// #1246
|
|
1668
|
-
const container = getContainer();
|
|
1669
|
-
let preventTouchMove;
|
|
1670
|
-
|
|
1671
|
-
container.ontouchstart = e => {
|
|
1672
|
-
preventTouchMove = shouldPreventTouchMove(e);
|
|
1673
|
-
};
|
|
1674
|
-
|
|
1675
|
-
container.ontouchmove = e => {
|
|
1676
|
-
if (preventTouchMove) {
|
|
1677
|
-
e.preventDefault();
|
|
1678
|
-
e.stopPropagation();
|
|
1679
|
-
}
|
|
1680
|
-
};
|
|
1681
|
-
};
|
|
1682
|
-
|
|
1683
|
-
const shouldPreventTouchMove = event => {
|
|
1684
|
-
const target = event.target;
|
|
1685
|
-
const container = getContainer();
|
|
1686
|
-
|
|
1687
|
-
if (isStylys(event) || isZoom(event)) {
|
|
1688
|
-
return false;
|
|
1689
|
-
}
|
|
1690
|
-
|
|
1691
|
-
if (target === container) {
|
|
1692
|
-
return true;
|
|
1693
|
-
}
|
|
1694
|
-
|
|
1695
|
-
if (!isScrollable(container) && target.tagName !== 'INPUT' && // #1603
|
|
1696
|
-
target.tagName !== 'TEXTAREA' && // #2266
|
|
1697
|
-
!(isScrollable(getHtmlContainer()) && // #1944
|
|
1698
|
-
getHtmlContainer().contains(target))) {
|
|
1699
|
-
return true;
|
|
1700
|
-
}
|
|
1701
|
-
|
|
1702
|
-
return false;
|
|
1703
|
-
};
|
|
1704
|
-
|
|
1705
|
-
const isStylys = event => {
|
|
1706
|
-
// #1786
|
|
1707
|
-
return event.touches && event.touches.length && event.touches[0].touchType === 'stylus';
|
|
1708
|
-
};
|
|
1709
|
-
|
|
1710
|
-
const isZoom = event => {
|
|
1711
|
-
// #1891
|
|
1712
|
-
return event.touches && event.touches.length > 1;
|
|
1713
|
-
};
|
|
1714
|
-
|
|
1715
|
-
const undoIOSfix = () => {
|
|
1716
|
-
if (hasClass(document.body, swalClasses.iosfix)) {
|
|
1717
|
-
const offset = parseInt(document.body.style.top, 10);
|
|
1718
|
-
removeClass(document.body, swalClasses.iosfix);
|
|
1719
|
-
document.body.style.top = '';
|
|
1720
|
-
document.body.scrollTop = offset * -1;
|
|
1721
|
-
}
|
|
1722
|
-
};
|
|
1370
|
+
const DismissReason = Object.freeze({
|
|
1371
|
+
cancel: 'cancel',
|
|
1372
|
+
backdrop: 'backdrop',
|
|
1373
|
+
close: 'close',
|
|
1374
|
+
esc: 'esc',
|
|
1375
|
+
timer: 'timer'
|
|
1376
|
+
});
|
|
1723
1377
|
|
|
1724
1378
|
// Adding aria-hidden="true" to elements outside of the active modal dialog ensures that
|
|
1725
1379
|
// elements not within the active modal dialog will not be surfaced if a user opens a screen
|
|
@@ -1751,312 +1405,177 @@
|
|
|
1751
1405
|
});
|
|
1752
1406
|
};
|
|
1753
1407
|
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
* This is the approach that Babel will probably take to implement private methods/fields
|
|
1758
|
-
* https://github.com/tc39/proposal-private-methods
|
|
1759
|
-
* https://github.com/babel/babel/pull/7555
|
|
1760
|
-
* Once we have the changes from that PR in Babel, and our core class fits reasonable in *one module*
|
|
1761
|
-
* then we can use that language feature.
|
|
1762
|
-
*/
|
|
1763
|
-
var privateMethods = {
|
|
1764
|
-
swalPromiseResolve: new WeakMap(),
|
|
1765
|
-
swalPromiseReject: new WeakMap()
|
|
1766
|
-
};
|
|
1767
|
-
|
|
1768
|
-
/*
|
|
1769
|
-
* Instance method to close sweetAlert
|
|
1770
|
-
*/
|
|
1771
|
-
|
|
1772
|
-
function removePopupAndResetState(instance, container, returnFocus, didClose) {
|
|
1773
|
-
if (isToast()) {
|
|
1774
|
-
triggerDidCloseAndDispose(instance, didClose);
|
|
1775
|
-
} else {
|
|
1776
|
-
restoreActiveElement(returnFocus).then(() => triggerDidCloseAndDispose(instance, didClose));
|
|
1777
|
-
globalState.keydownTarget.removeEventListener('keydown', globalState.keydownHandler, {
|
|
1778
|
-
capture: globalState.keydownListenerCapture
|
|
1779
|
-
});
|
|
1780
|
-
globalState.keydownHandlerAdded = false;
|
|
1781
|
-
}
|
|
1782
|
-
|
|
1783
|
-
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent); // workaround for #2088
|
|
1784
|
-
// for some reason removing the container in Safari will scroll the document to bottom
|
|
1785
|
-
|
|
1786
|
-
if (isSafari) {
|
|
1787
|
-
container.setAttribute('style', 'display:none !important');
|
|
1788
|
-
container.removeAttribute('class');
|
|
1789
|
-
container.innerHTML = '';
|
|
1790
|
-
} else {
|
|
1791
|
-
container.remove();
|
|
1792
|
-
}
|
|
1793
|
-
|
|
1794
|
-
if (isModal()) {
|
|
1795
|
-
undoScrollbar();
|
|
1796
|
-
undoIOSfix();
|
|
1797
|
-
unsetAriaHidden();
|
|
1798
|
-
}
|
|
1799
|
-
|
|
1800
|
-
removeBodyClasses();
|
|
1801
|
-
}
|
|
1802
|
-
|
|
1803
|
-
function removeBodyClasses() {
|
|
1804
|
-
removeClass([document.documentElement, document.body], [swalClasses.shown, swalClasses['height-auto'], swalClasses['no-backdrop'], swalClasses['toast-shown']]);
|
|
1805
|
-
}
|
|
1806
|
-
|
|
1807
|
-
function close(resolveValue) {
|
|
1808
|
-
resolveValue = prepareResolveValue(resolveValue);
|
|
1809
|
-
const swalPromiseResolve = privateMethods.swalPromiseResolve.get(this);
|
|
1810
|
-
const didClose = triggerClosePopup(this);
|
|
1811
|
-
|
|
1812
|
-
if (this.isAwaitingPromise()) {
|
|
1813
|
-
// A swal awaiting for a promise (after a click on Confirm or Deny) cannot be dismissed anymore #2335
|
|
1814
|
-
if (!resolveValue.isDismissed) {
|
|
1815
|
-
handleAwaitingPromise(this);
|
|
1816
|
-
swalPromiseResolve(resolveValue);
|
|
1817
|
-
}
|
|
1818
|
-
} else if (didClose) {
|
|
1819
|
-
// Resolve Swal promise
|
|
1820
|
-
swalPromiseResolve(resolveValue);
|
|
1821
|
-
}
|
|
1822
|
-
}
|
|
1823
|
-
function isAwaitingPromise() {
|
|
1824
|
-
return !!privateProps.awaitingPromise.get(this);
|
|
1825
|
-
}
|
|
1826
|
-
|
|
1827
|
-
const triggerClosePopup = instance => {
|
|
1828
|
-
const popup = getPopup();
|
|
1829
|
-
|
|
1830
|
-
if (!popup) {
|
|
1831
|
-
return false;
|
|
1832
|
-
}
|
|
1833
|
-
|
|
1834
|
-
const innerParams = privateProps.innerParams.get(instance);
|
|
1408
|
+
const swalStringParams = ['swal-title', 'swal-html', 'swal-footer'];
|
|
1409
|
+
const getTemplateParams = params => {
|
|
1410
|
+
const template = typeof params.template === 'string' ? document.querySelector(params.template) : params.template;
|
|
1835
1411
|
|
|
1836
|
-
if (!
|
|
1837
|
-
return
|
|
1412
|
+
if (!template) {
|
|
1413
|
+
return {};
|
|
1838
1414
|
}
|
|
1839
1415
|
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
const
|
|
1843
|
-
|
|
1844
|
-
addClass(backdrop, innerParams.hideClass.backdrop);
|
|
1845
|
-
handlePopupAnimation(instance, popup, innerParams);
|
|
1846
|
-
return true;
|
|
1416
|
+
const templateContent = template.content;
|
|
1417
|
+
showWarningsForElements(templateContent);
|
|
1418
|
+
const result = Object.assign(getSwalParams(templateContent), getSwalButtons(templateContent), getSwalImage(templateContent), getSwalIcon(templateContent), getSwalInput(templateContent), getSwalStringParams(templateContent, swalStringParams));
|
|
1419
|
+
return result;
|
|
1847
1420
|
};
|
|
1848
1421
|
|
|
1849
|
-
|
|
1850
|
-
const
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
rejectPromise(error);
|
|
1856
|
-
}
|
|
1857
|
-
}
|
|
1858
|
-
|
|
1859
|
-
const handleAwaitingPromise = instance => {
|
|
1860
|
-
if (instance.isAwaitingPromise()) {
|
|
1861
|
-
privateProps.awaitingPromise.delete(instance); // The instance might have been previously partly destroyed, we must resume the destroy process in this case #2335
|
|
1422
|
+
const getSwalParams = templateContent => {
|
|
1423
|
+
const result = {};
|
|
1424
|
+
toArray(templateContent.querySelectorAll('swal-param')).forEach(param => {
|
|
1425
|
+
showWarningsForAttributes(param, ['name', 'value']);
|
|
1426
|
+
const paramName = param.getAttribute('name');
|
|
1427
|
+
let value = param.getAttribute('value');
|
|
1862
1428
|
|
|
1863
|
-
if (
|
|
1864
|
-
|
|
1429
|
+
if (typeof defaultParams[paramName] === 'boolean' && value === 'false') {
|
|
1430
|
+
value = false;
|
|
1865
1431
|
}
|
|
1866
|
-
}
|
|
1867
|
-
};
|
|
1868
1432
|
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
return {
|
|
1873
|
-
isConfirmed: false,
|
|
1874
|
-
isDenied: false,
|
|
1875
|
-
isDismissed: true
|
|
1876
|
-
};
|
|
1877
|
-
}
|
|
1433
|
+
if (typeof defaultParams[paramName] === 'object') {
|
|
1434
|
+
value = JSON.parse(value);
|
|
1435
|
+
}
|
|
1878
1436
|
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
isDismissed: false
|
|
1883
|
-
}, resolveValue);
|
|
1437
|
+
result[paramName] = value;
|
|
1438
|
+
});
|
|
1439
|
+
return result;
|
|
1884
1440
|
};
|
|
1885
1441
|
|
|
1886
|
-
const
|
|
1887
|
-
const
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
}
|
|
1894
|
-
|
|
1895
|
-
if (animationIsSupported) {
|
|
1896
|
-
animatePopup(instance, popup, container, innerParams.returnFocus, innerParams.didClose);
|
|
1897
|
-
} else {
|
|
1898
|
-
// Otherwise, remove immediately
|
|
1899
|
-
removePopupAndResetState(instance, container, innerParams.returnFocus, innerParams.didClose);
|
|
1900
|
-
}
|
|
1901
|
-
};
|
|
1442
|
+
const getSwalButtons = templateContent => {
|
|
1443
|
+
const result = {};
|
|
1444
|
+
toArray(templateContent.querySelectorAll('swal-button')).forEach(button => {
|
|
1445
|
+
showWarningsForAttributes(button, ['type', 'color', 'aria-label']);
|
|
1446
|
+
const type = button.getAttribute('type');
|
|
1447
|
+
result["".concat(type, "ButtonText")] = button.innerHTML;
|
|
1448
|
+
result["show".concat(capitalizeFirstLetter(type), "Button")] = true;
|
|
1902
1449
|
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
popup.addEventListener(animationEndEvent, function (e) {
|
|
1906
|
-
if (e.target === popup) {
|
|
1907
|
-
globalState.swalCloseEventFinishedCallback();
|
|
1908
|
-
delete globalState.swalCloseEventFinishedCallback;
|
|
1450
|
+
if (button.hasAttribute('color')) {
|
|
1451
|
+
result["".concat(type, "ButtonColor")] = button.getAttribute('color');
|
|
1909
1452
|
}
|
|
1910
|
-
});
|
|
1911
|
-
};
|
|
1912
1453
|
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
if (typeof didClose === 'function') {
|
|
1916
|
-
didClose.bind(instance.params)();
|
|
1454
|
+
if (button.hasAttribute('aria-label')) {
|
|
1455
|
+
result["".concat(type, "ButtonAriaLabel")] = button.getAttribute('aria-label');
|
|
1917
1456
|
}
|
|
1918
|
-
|
|
1919
|
-
instance._destroy();
|
|
1920
1457
|
});
|
|
1458
|
+
return result;
|
|
1921
1459
|
};
|
|
1922
1460
|
|
|
1923
|
-
|
|
1924
|
-
const
|
|
1925
|
-
|
|
1926
|
-
domCache[button].disabled = disabled;
|
|
1927
|
-
});
|
|
1928
|
-
}
|
|
1929
|
-
|
|
1930
|
-
function setInputDisabled(input, disabled) {
|
|
1931
|
-
if (!input) {
|
|
1932
|
-
return false;
|
|
1933
|
-
}
|
|
1461
|
+
const getSwalImage = templateContent => {
|
|
1462
|
+
const result = {};
|
|
1463
|
+
const image = templateContent.querySelector('swal-image');
|
|
1934
1464
|
|
|
1935
|
-
if (
|
|
1936
|
-
|
|
1937
|
-
const radios = radiosContainer.querySelectorAll('input');
|
|
1465
|
+
if (image) {
|
|
1466
|
+
showWarningsForAttributes(image, ['src', 'width', 'height', 'alt']);
|
|
1938
1467
|
|
|
1939
|
-
|
|
1940
|
-
|
|
1468
|
+
if (image.hasAttribute('src')) {
|
|
1469
|
+
result.imageUrl = image.getAttribute('src');
|
|
1941
1470
|
}
|
|
1942
|
-
} else {
|
|
1943
|
-
input.disabled = disabled;
|
|
1944
|
-
}
|
|
1945
|
-
}
|
|
1946
1471
|
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
function disableButtons() {
|
|
1951
|
-
setButtonsDisabled(this, ['confirmButton', 'denyButton', 'cancelButton'], true);
|
|
1952
|
-
}
|
|
1953
|
-
function enableInput() {
|
|
1954
|
-
return setInputDisabled(this.getInput(), false);
|
|
1955
|
-
}
|
|
1956
|
-
function disableInput() {
|
|
1957
|
-
return setInputDisabled(this.getInput(), true);
|
|
1958
|
-
}
|
|
1472
|
+
if (image.hasAttribute('width')) {
|
|
1473
|
+
result.imageWidth = image.getAttribute('width');
|
|
1474
|
+
}
|
|
1959
1475
|
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
setInnerHtml(domCache.validationMessage, error);
|
|
1964
|
-
domCache.validationMessage.className = swalClasses['validation-message'];
|
|
1476
|
+
if (image.hasAttribute('height')) {
|
|
1477
|
+
result.imageHeight = image.getAttribute('height');
|
|
1478
|
+
}
|
|
1965
1479
|
|
|
1966
|
-
|
|
1967
|
-
|
|
1480
|
+
if (image.hasAttribute('alt')) {
|
|
1481
|
+
result.imageAlt = image.getAttribute('alt');
|
|
1482
|
+
}
|
|
1968
1483
|
}
|
|
1969
1484
|
|
|
1970
|
-
|
|
1971
|
-
|
|
1485
|
+
return result;
|
|
1486
|
+
};
|
|
1972
1487
|
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
focusInput(input);
|
|
1977
|
-
addClass(input, swalClasses.inputerror);
|
|
1978
|
-
}
|
|
1979
|
-
} // Hide block with validation message
|
|
1488
|
+
const getSwalIcon = templateContent => {
|
|
1489
|
+
const result = {};
|
|
1490
|
+
const icon = templateContent.querySelector('swal-icon');
|
|
1980
1491
|
|
|
1981
|
-
|
|
1982
|
-
|
|
1492
|
+
if (icon) {
|
|
1493
|
+
showWarningsForAttributes(icon, ['type', 'color']);
|
|
1983
1494
|
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1495
|
+
if (icon.hasAttribute('type')) {
|
|
1496
|
+
result.icon = icon.getAttribute('type');
|
|
1497
|
+
}
|
|
1987
1498
|
|
|
1988
|
-
|
|
1499
|
+
if (icon.hasAttribute('color')) {
|
|
1500
|
+
result.iconColor = icon.getAttribute('color');
|
|
1501
|
+
}
|
|
1989
1502
|
|
|
1990
|
-
|
|
1991
|
-
input.removeAttribute('aria-invalid');
|
|
1992
|
-
input.removeAttribute('aria-describedby');
|
|
1993
|
-
removeClass(input, swalClasses.inputerror);
|
|
1503
|
+
result.iconHtml = icon.innerHTML;
|
|
1994
1504
|
}
|
|
1995
|
-
}
|
|
1996
1505
|
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
return domCache.progressSteps;
|
|
2000
|
-
}
|
|
1506
|
+
return result;
|
|
1507
|
+
};
|
|
2001
1508
|
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
this.remaining = delay;
|
|
2006
|
-
this.running = false;
|
|
2007
|
-
this.start();
|
|
2008
|
-
}
|
|
1509
|
+
const getSwalInput = templateContent => {
|
|
1510
|
+
const result = {};
|
|
1511
|
+
const input = templateContent.querySelector('swal-input');
|
|
2009
1512
|
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
1513
|
+
if (input) {
|
|
1514
|
+
showWarningsForAttributes(input, ['type', 'label', 'placeholder', 'value']);
|
|
1515
|
+
result.input = input.getAttribute('type') || 'text';
|
|
1516
|
+
|
|
1517
|
+
if (input.hasAttribute('label')) {
|
|
1518
|
+
result.inputLabel = input.getAttribute('label');
|
|
2015
1519
|
}
|
|
2016
1520
|
|
|
2017
|
-
|
|
2018
|
-
|
|
1521
|
+
if (input.hasAttribute('placeholder')) {
|
|
1522
|
+
result.inputPlaceholder = input.getAttribute('placeholder');
|
|
1523
|
+
}
|
|
2019
1524
|
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
this.running = false;
|
|
2023
|
-
clearTimeout(this.id);
|
|
2024
|
-
this.remaining -= new Date() - this.started;
|
|
1525
|
+
if (input.hasAttribute('value')) {
|
|
1526
|
+
result.inputValue = input.getAttribute('value');
|
|
2025
1527
|
}
|
|
1528
|
+
}
|
|
2026
1529
|
|
|
2027
|
-
|
|
1530
|
+
const inputOptions = templateContent.querySelectorAll('swal-input-option');
|
|
1531
|
+
|
|
1532
|
+
if (inputOptions.length) {
|
|
1533
|
+
result.inputOptions = {};
|
|
1534
|
+
toArray(inputOptions).forEach(option => {
|
|
1535
|
+
showWarningsForAttributes(option, ['value']);
|
|
1536
|
+
const optionValue = option.getAttribute('value');
|
|
1537
|
+
const optionName = option.innerHTML;
|
|
1538
|
+
result.inputOptions[optionValue] = optionName;
|
|
1539
|
+
});
|
|
2028
1540
|
}
|
|
2029
1541
|
|
|
2030
|
-
|
|
2031
|
-
|
|
1542
|
+
return result;
|
|
1543
|
+
};
|
|
2032
1544
|
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
}
|
|
1545
|
+
const getSwalStringParams = (templateContent, paramNames) => {
|
|
1546
|
+
const result = {};
|
|
2036
1547
|
|
|
2037
|
-
|
|
1548
|
+
for (const i in paramNames) {
|
|
1549
|
+
const paramName = paramNames[i];
|
|
1550
|
+
const tag = templateContent.querySelector(paramName);
|
|
2038
1551
|
|
|
2039
|
-
if (
|
|
2040
|
-
|
|
1552
|
+
if (tag) {
|
|
1553
|
+
showWarningsForAttributes(tag, []);
|
|
1554
|
+
result[paramName.replace(/^swal-/, '')] = tag.innerHTML.trim();
|
|
2041
1555
|
}
|
|
2042
|
-
|
|
2043
|
-
return this.remaining;
|
|
2044
1556
|
}
|
|
2045
1557
|
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
this.stop();
|
|
2049
|
-
this.start();
|
|
2050
|
-
}
|
|
1558
|
+
return result;
|
|
1559
|
+
};
|
|
2051
1560
|
|
|
2052
|
-
|
|
2053
|
-
|
|
1561
|
+
const showWarningsForElements = template => {
|
|
1562
|
+
const allowedElements = swalStringParams.concat(['swal-param', 'swal-button', 'swal-image', 'swal-icon', 'swal-input', 'swal-input-option']);
|
|
1563
|
+
toArray(template.children).forEach(el => {
|
|
1564
|
+
const tagName = el.tagName.toLowerCase();
|
|
2054
1565
|
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
1566
|
+
if (allowedElements.indexOf(tagName) === -1) {
|
|
1567
|
+
warn("Unrecognized element <".concat(tagName, ">"));
|
|
1568
|
+
}
|
|
1569
|
+
});
|
|
1570
|
+
};
|
|
2058
1571
|
|
|
2059
|
-
|
|
1572
|
+
const showWarningsForAttributes = (el, allowedAttributes) => {
|
|
1573
|
+
toArray(el.attributes).forEach(attribute => {
|
|
1574
|
+
if (allowedAttributes.indexOf(attribute.name) === -1) {
|
|
1575
|
+
warn(["Unrecognized attribute \"".concat(attribute.name, "\" on <").concat(el.tagName.toLowerCase(), ">."), "".concat(allowedAttributes.length ? "Allowed attributes are: ".concat(allowedAttributes.join(', ')) : 'To set the value, use HTML within the element.')]);
|
|
1576
|
+
}
|
|
1577
|
+
});
|
|
1578
|
+
};
|
|
2060
1579
|
|
|
2061
1580
|
var defaultInputValidators = {
|
|
2062
1581
|
email: (string, validationMessage) => {
|
|
@@ -2090,7 +1609,6 @@
|
|
|
2090
1609
|
* Set type, text and actions on popup
|
|
2091
1610
|
*
|
|
2092
1611
|
* @param params
|
|
2093
|
-
* @returns {boolean}
|
|
2094
1612
|
*/
|
|
2095
1613
|
|
|
2096
1614
|
|
|
@@ -2110,176 +1628,168 @@
|
|
|
2110
1628
|
init(params);
|
|
2111
1629
|
}
|
|
2112
1630
|
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
1631
|
+
class Timer {
|
|
1632
|
+
constructor(callback, delay) {
|
|
1633
|
+
this.callback = callback;
|
|
1634
|
+
this.remaining = delay;
|
|
1635
|
+
this.running = false;
|
|
1636
|
+
this.start();
|
|
2119
1637
|
}
|
|
2120
1638
|
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
1639
|
+
start() {
|
|
1640
|
+
if (!this.running) {
|
|
1641
|
+
this.running = true;
|
|
1642
|
+
this.started = new Date();
|
|
1643
|
+
this.id = setTimeout(this.callback, this.remaining);
|
|
1644
|
+
}
|
|
2126
1645
|
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
toArray(templateContent.querySelectorAll('swal-param')).forEach(param => {
|
|
2130
|
-
showWarningsForAttributes(param, ['name', 'value']);
|
|
2131
|
-
const paramName = param.getAttribute('name');
|
|
2132
|
-
let value = param.getAttribute('value');
|
|
1646
|
+
return this.remaining;
|
|
1647
|
+
}
|
|
2133
1648
|
|
|
2134
|
-
|
|
2135
|
-
|
|
1649
|
+
stop() {
|
|
1650
|
+
if (this.running) {
|
|
1651
|
+
this.running = false;
|
|
1652
|
+
clearTimeout(this.id);
|
|
1653
|
+
this.remaining -= new Date().getTime() - this.started.getTime();
|
|
2136
1654
|
}
|
|
2137
1655
|
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
}
|
|
1656
|
+
return this.remaining;
|
|
1657
|
+
}
|
|
2141
1658
|
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
return result;
|
|
2145
|
-
};
|
|
1659
|
+
increase(n) {
|
|
1660
|
+
const running = this.running;
|
|
2146
1661
|
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
showWarningsForAttributes(button, ['type', 'color', 'aria-label']);
|
|
2151
|
-
const type = button.getAttribute('type');
|
|
2152
|
-
result["".concat(type, "ButtonText")] = button.innerHTML;
|
|
2153
|
-
result["show".concat(capitalizeFirstLetter(type), "Button")] = true;
|
|
1662
|
+
if (running) {
|
|
1663
|
+
this.stop();
|
|
1664
|
+
}
|
|
2154
1665
|
|
|
2155
|
-
|
|
2156
|
-
|
|
1666
|
+
this.remaining += n;
|
|
1667
|
+
|
|
1668
|
+
if (running) {
|
|
1669
|
+
this.start();
|
|
2157
1670
|
}
|
|
2158
1671
|
|
|
2159
|
-
|
|
2160
|
-
|
|
1672
|
+
return this.remaining;
|
|
1673
|
+
}
|
|
1674
|
+
|
|
1675
|
+
getTimerLeft() {
|
|
1676
|
+
if (this.running) {
|
|
1677
|
+
this.stop();
|
|
1678
|
+
this.start();
|
|
2161
1679
|
}
|
|
2162
|
-
});
|
|
2163
|
-
return result;
|
|
2164
|
-
};
|
|
2165
1680
|
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
const image = templateContent.querySelector('swal-image');
|
|
1681
|
+
return this.remaining;
|
|
1682
|
+
}
|
|
2169
1683
|
|
|
2170
|
-
|
|
2171
|
-
|
|
1684
|
+
isRunning() {
|
|
1685
|
+
return this.running;
|
|
1686
|
+
}
|
|
2172
1687
|
|
|
2173
|
-
|
|
2174
|
-
result.imageUrl = image.getAttribute('src');
|
|
2175
|
-
}
|
|
1688
|
+
}
|
|
2176
1689
|
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
1690
|
+
const fixScrollbar = () => {
|
|
1691
|
+
// for queues, do not do this more than once
|
|
1692
|
+
if (states.previousBodyPadding !== null) {
|
|
1693
|
+
return;
|
|
1694
|
+
} // if the body has overflow
|
|
2180
1695
|
|
|
2181
|
-
if (image.hasAttribute('height')) {
|
|
2182
|
-
result.imageHeight = image.getAttribute('height');
|
|
2183
|
-
}
|
|
2184
1696
|
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
1697
|
+
if (document.body.scrollHeight > window.innerHeight) {
|
|
1698
|
+
// add padding so the content doesn't shift after removal of scrollbar
|
|
1699
|
+
states.previousBodyPadding = parseInt(window.getComputedStyle(document.body).getPropertyValue('padding-right'));
|
|
1700
|
+
document.body.style.paddingRight = "".concat(states.previousBodyPadding + measureScrollbar(), "px");
|
|
1701
|
+
}
|
|
1702
|
+
};
|
|
1703
|
+
const undoScrollbar = () => {
|
|
1704
|
+
if (states.previousBodyPadding !== null) {
|
|
1705
|
+
document.body.style.paddingRight = "".concat(states.previousBodyPadding, "px");
|
|
1706
|
+
states.previousBodyPadding = null;
|
|
2188
1707
|
}
|
|
2189
|
-
|
|
2190
|
-
return result;
|
|
2191
1708
|
};
|
|
2192
1709
|
|
|
2193
|
-
|
|
2194
|
-
const result = {};
|
|
2195
|
-
const icon = templateContent.querySelector('swal-icon');
|
|
1710
|
+
/* istanbul ignore file */
|
|
2196
1711
|
|
|
2197
|
-
|
|
2198
|
-
|
|
1712
|
+
const iOSfix = () => {
|
|
1713
|
+
// @ts-ignore
|
|
1714
|
+
const iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream || navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1;
|
|
1715
|
+
|
|
1716
|
+
if (iOS && !hasClass(document.body, swalClasses.iosfix)) {
|
|
1717
|
+
const offset = document.body.scrollTop;
|
|
1718
|
+
document.body.style.top = "".concat(offset * -1, "px");
|
|
1719
|
+
addClass(document.body, swalClasses.iosfix);
|
|
1720
|
+
lockBodyScroll();
|
|
1721
|
+
addBottomPaddingForTallPopups(); // #1948
|
|
1722
|
+
}
|
|
1723
|
+
};
|
|
1724
|
+
|
|
1725
|
+
const addBottomPaddingForTallPopups = () => {
|
|
1726
|
+
const safari = !navigator.userAgent.match(/(CriOS|FxiOS|EdgiOS|YaBrowser|UCBrowser)/i);
|
|
2199
1727
|
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
}
|
|
1728
|
+
if (safari) {
|
|
1729
|
+
const bottomPanelHeight = 44;
|
|
2203
1730
|
|
|
2204
|
-
if (
|
|
2205
|
-
|
|
1731
|
+
if (getPopup().scrollHeight > window.innerHeight - bottomPanelHeight) {
|
|
1732
|
+
getContainer().style.paddingBottom = "".concat(bottomPanelHeight, "px");
|
|
2206
1733
|
}
|
|
2207
|
-
|
|
2208
|
-
result.iconHtml = icon.innerHTML;
|
|
2209
1734
|
}
|
|
2210
|
-
|
|
2211
|
-
return result;
|
|
2212
1735
|
};
|
|
2213
1736
|
|
|
2214
|
-
const
|
|
2215
|
-
|
|
2216
|
-
const
|
|
1737
|
+
const lockBodyScroll = () => {
|
|
1738
|
+
// #1246
|
|
1739
|
+
const container = getContainer();
|
|
1740
|
+
let preventTouchMove;
|
|
2217
1741
|
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
1742
|
+
container.ontouchstart = e => {
|
|
1743
|
+
preventTouchMove = shouldPreventTouchMove(e);
|
|
1744
|
+
};
|
|
2221
1745
|
|
|
2222
|
-
|
|
2223
|
-
|
|
1746
|
+
container.ontouchmove = e => {
|
|
1747
|
+
if (preventTouchMove) {
|
|
1748
|
+
e.preventDefault();
|
|
1749
|
+
e.stopPropagation();
|
|
2224
1750
|
}
|
|
1751
|
+
};
|
|
1752
|
+
};
|
|
2225
1753
|
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
1754
|
+
const shouldPreventTouchMove = event => {
|
|
1755
|
+
const target = event.target;
|
|
1756
|
+
const container = getContainer();
|
|
2229
1757
|
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
}
|
|
1758
|
+
if (isStylys(event) || isZoom(event)) {
|
|
1759
|
+
return false;
|
|
2233
1760
|
}
|
|
2234
1761
|
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
if (inputOptions.length) {
|
|
2238
|
-
result.inputOptions = {};
|
|
2239
|
-
toArray(inputOptions).forEach(option => {
|
|
2240
|
-
showWarningsForAttributes(option, ['value']);
|
|
2241
|
-
const optionValue = option.getAttribute('value');
|
|
2242
|
-
const optionName = option.innerHTML;
|
|
2243
|
-
result.inputOptions[optionValue] = optionName;
|
|
2244
|
-
});
|
|
1762
|
+
if (target === container) {
|
|
1763
|
+
return true;
|
|
2245
1764
|
}
|
|
2246
1765
|
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
for (const i in paramNames) {
|
|
2254
|
-
const paramName = paramNames[i];
|
|
2255
|
-
const tag = templateContent.querySelector(paramName);
|
|
2256
|
-
|
|
2257
|
-
if (tag) {
|
|
2258
|
-
showWarningsForAttributes(tag, []);
|
|
2259
|
-
result[paramName.replace(/^swal-/, '')] = tag.innerHTML.trim();
|
|
2260
|
-
}
|
|
1766
|
+
if (!isScrollable(container) && target.tagName !== 'INPUT' && // #1603
|
|
1767
|
+
target.tagName !== 'TEXTAREA' && // #2266
|
|
1768
|
+
!(isScrollable(getHtmlContainer()) && // #1944
|
|
1769
|
+
getHtmlContainer().contains(target))) {
|
|
1770
|
+
return true;
|
|
2261
1771
|
}
|
|
2262
1772
|
|
|
2263
|
-
return
|
|
1773
|
+
return false;
|
|
2264
1774
|
};
|
|
2265
1775
|
|
|
2266
|
-
const
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
1776
|
+
const isStylys = event => {
|
|
1777
|
+
// #1786
|
|
1778
|
+
return event.touches && event.touches.length && event.touches[0].touchType === 'stylus';
|
|
1779
|
+
};
|
|
2270
1780
|
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
});
|
|
1781
|
+
const isZoom = event => {
|
|
1782
|
+
// #1891
|
|
1783
|
+
return event.touches && event.touches.length > 1;
|
|
2275
1784
|
};
|
|
2276
1785
|
|
|
2277
|
-
const
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
1786
|
+
const undoIOSfix = () => {
|
|
1787
|
+
if (hasClass(document.body, swalClasses.iosfix)) {
|
|
1788
|
+
const offset = parseInt(document.body.style.top, 10);
|
|
1789
|
+
removeClass(document.body, swalClasses.iosfix);
|
|
1790
|
+
document.body.style.top = '';
|
|
1791
|
+
document.body.scrollTop = offset * -1;
|
|
1792
|
+
}
|
|
2283
1793
|
};
|
|
2284
1794
|
|
|
2285
1795
|
const SHOW_CLASS_TIMEOUT = 10;
|
|
@@ -2374,6 +1884,52 @@
|
|
|
2374
1884
|
}
|
|
2375
1885
|
};
|
|
2376
1886
|
|
|
1887
|
+
/**
|
|
1888
|
+
* Shows loader (spinner), this is useful with AJAX requests.
|
|
1889
|
+
* By default the loader be shown instead of the "Confirm" button.
|
|
1890
|
+
*/
|
|
1891
|
+
|
|
1892
|
+
const showLoading = buttonToReplace => {
|
|
1893
|
+
let popup = getPopup();
|
|
1894
|
+
|
|
1895
|
+
if (!popup) {
|
|
1896
|
+
new Swal(); // eslint-disable-line no-new
|
|
1897
|
+
}
|
|
1898
|
+
|
|
1899
|
+
popup = getPopup();
|
|
1900
|
+
const loader = getLoader();
|
|
1901
|
+
|
|
1902
|
+
if (isToast()) {
|
|
1903
|
+
hide(getIcon());
|
|
1904
|
+
} else {
|
|
1905
|
+
replaceButton(popup, buttonToReplace);
|
|
1906
|
+
}
|
|
1907
|
+
|
|
1908
|
+
show(loader);
|
|
1909
|
+
popup.setAttribute('data-loading', true);
|
|
1910
|
+
popup.setAttribute('aria-busy', true);
|
|
1911
|
+
popup.focus();
|
|
1912
|
+
};
|
|
1913
|
+
|
|
1914
|
+
const replaceButton = (popup, buttonToReplace) => {
|
|
1915
|
+
const actions = getActions();
|
|
1916
|
+
const loader = getLoader();
|
|
1917
|
+
|
|
1918
|
+
if (!buttonToReplace && isVisible(getConfirmButton())) {
|
|
1919
|
+
buttonToReplace = getConfirmButton();
|
|
1920
|
+
}
|
|
1921
|
+
|
|
1922
|
+
show(actions);
|
|
1923
|
+
|
|
1924
|
+
if (buttonToReplace) {
|
|
1925
|
+
hide(buttonToReplace);
|
|
1926
|
+
loader.setAttribute('data-button-to-replace', buttonToReplace.className);
|
|
1927
|
+
}
|
|
1928
|
+
|
|
1929
|
+
loader.parentNode.insertBefore(loader, buttonToReplace);
|
|
1930
|
+
addClass([popup, actions], swalClasses.loading);
|
|
1931
|
+
};
|
|
1932
|
+
|
|
2377
1933
|
const handleInputOptionsAndValue = (instance, params) => {
|
|
2378
1934
|
if (params.input === 'select' || params.input === 'radio') {
|
|
2379
1935
|
handleInputOptions(instance, params);
|
|
@@ -2653,26 +2209,128 @@
|
|
|
2653
2209
|
const confirm = (instance, value) => {
|
|
2654
2210
|
const innerParams = privateProps.innerParams.get(instance || undefined);
|
|
2655
2211
|
|
|
2656
|
-
if (innerParams.showLoaderOnConfirm) {
|
|
2657
|
-
showLoading();
|
|
2658
|
-
}
|
|
2212
|
+
if (innerParams.showLoaderOnConfirm) {
|
|
2213
|
+
showLoading();
|
|
2214
|
+
}
|
|
2215
|
+
|
|
2216
|
+
if (innerParams.preConfirm) {
|
|
2217
|
+
instance.resetValidationMessage();
|
|
2218
|
+
privateProps.awaitingPromise.set(instance || undefined, true); // Flagging the instance as awaiting a promise so it's own promise's reject/resolve methods doesnt get destroyed until the result from this preConfirm's promise is received
|
|
2219
|
+
|
|
2220
|
+
const preConfirmPromise = Promise.resolve().then(() => asPromise(innerParams.preConfirm(value, innerParams.validationMessage)));
|
|
2221
|
+
preConfirmPromise.then(preConfirmValue => {
|
|
2222
|
+
if (isVisible(getValidationMessage()) || preConfirmValue === false) {
|
|
2223
|
+
instance.hideLoading();
|
|
2224
|
+
} else {
|
|
2225
|
+
succeedWith(instance, typeof preConfirmValue === 'undefined' ? value : preConfirmValue);
|
|
2226
|
+
}
|
|
2227
|
+
}).catch(error$$1 => rejectWith(instance || undefined, error$$1));
|
|
2228
|
+
} else {
|
|
2229
|
+
succeedWith(instance, value);
|
|
2230
|
+
}
|
|
2231
|
+
};
|
|
2232
|
+
|
|
2233
|
+
const handlePopupClick = (instance, domCache, dismissWith) => {
|
|
2234
|
+
const innerParams = privateProps.innerParams.get(instance);
|
|
2235
|
+
|
|
2236
|
+
if (innerParams.toast) {
|
|
2237
|
+
handleToastClick(instance, domCache, dismissWith);
|
|
2238
|
+
} else {
|
|
2239
|
+
// Ignore click events that had mousedown on the popup but mouseup on the container
|
|
2240
|
+
// This can happen when the user drags a slider
|
|
2241
|
+
handleModalMousedown(domCache); // Ignore click events that had mousedown on the container but mouseup on the popup
|
|
2242
|
+
|
|
2243
|
+
handleContainerMousedown(domCache);
|
|
2244
|
+
handleModalClick(instance, domCache, dismissWith);
|
|
2245
|
+
}
|
|
2246
|
+
};
|
|
2247
|
+
|
|
2248
|
+
const handleToastClick = (instance, domCache, dismissWith) => {
|
|
2249
|
+
// Closing toast by internal click
|
|
2250
|
+
domCache.popup.onclick = () => {
|
|
2251
|
+
const innerParams = privateProps.innerParams.get(instance);
|
|
2252
|
+
|
|
2253
|
+
if (innerParams && (isAnyButtonShown(innerParams) || innerParams.timer || innerParams.input)) {
|
|
2254
|
+
return;
|
|
2255
|
+
}
|
|
2256
|
+
|
|
2257
|
+
dismissWith(DismissReason.close);
|
|
2258
|
+
};
|
|
2259
|
+
};
|
|
2260
|
+
/**
|
|
2261
|
+
* @param {*} innerParams
|
|
2262
|
+
* @returns {boolean}
|
|
2263
|
+
*/
|
|
2264
|
+
|
|
2265
|
+
|
|
2266
|
+
const isAnyButtonShown = innerParams => {
|
|
2267
|
+
return innerParams.showConfirmButton || innerParams.showDenyButton || innerParams.showCancelButton || innerParams.showCloseButton;
|
|
2268
|
+
};
|
|
2269
|
+
|
|
2270
|
+
let ignoreOutsideClick = false;
|
|
2271
|
+
|
|
2272
|
+
const handleModalMousedown = domCache => {
|
|
2273
|
+
domCache.popup.onmousedown = () => {
|
|
2274
|
+
domCache.container.onmouseup = function (e) {
|
|
2275
|
+
domCache.container.onmouseup = undefined; // We only check if the mouseup target is the container because usually it doesn't
|
|
2276
|
+
// have any other direct children aside of the popup
|
|
2277
|
+
|
|
2278
|
+
if (e.target === domCache.container) {
|
|
2279
|
+
ignoreOutsideClick = true;
|
|
2280
|
+
}
|
|
2281
|
+
};
|
|
2282
|
+
};
|
|
2283
|
+
};
|
|
2284
|
+
|
|
2285
|
+
const handleContainerMousedown = domCache => {
|
|
2286
|
+
domCache.container.onmousedown = () => {
|
|
2287
|
+
domCache.popup.onmouseup = function (e) {
|
|
2288
|
+
domCache.popup.onmouseup = undefined; // We also need to check if the mouseup target is a child of the popup
|
|
2289
|
+
|
|
2290
|
+
if (e.target === domCache.popup || domCache.popup.contains(e.target)) {
|
|
2291
|
+
ignoreOutsideClick = true;
|
|
2292
|
+
}
|
|
2293
|
+
};
|
|
2294
|
+
};
|
|
2295
|
+
};
|
|
2296
|
+
|
|
2297
|
+
const handleModalClick = (instance, domCache, dismissWith) => {
|
|
2298
|
+
domCache.container.onclick = e => {
|
|
2299
|
+
const innerParams = privateProps.innerParams.get(instance);
|
|
2300
|
+
|
|
2301
|
+
if (ignoreOutsideClick) {
|
|
2302
|
+
ignoreOutsideClick = false;
|
|
2303
|
+
return;
|
|
2304
|
+
}
|
|
2305
|
+
|
|
2306
|
+
if (e.target === domCache.container && callIfFunction(innerParams.allowOutsideClick)) {
|
|
2307
|
+
dismissWith(DismissReason.backdrop);
|
|
2308
|
+
}
|
|
2309
|
+
};
|
|
2310
|
+
};
|
|
2311
|
+
|
|
2312
|
+
/*
|
|
2313
|
+
* Global function to determine if SweetAlert2 popup is shown
|
|
2314
|
+
*/
|
|
2315
|
+
|
|
2316
|
+
const isVisible$1 = () => {
|
|
2317
|
+
return isVisible(getPopup());
|
|
2318
|
+
};
|
|
2319
|
+
/*
|
|
2320
|
+
* Global function to click 'Confirm' button
|
|
2321
|
+
*/
|
|
2322
|
+
|
|
2323
|
+
const clickConfirm = () => getConfirmButton() && getConfirmButton().click();
|
|
2324
|
+
/*
|
|
2325
|
+
* Global function to click 'Deny' button
|
|
2326
|
+
*/
|
|
2659
2327
|
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2328
|
+
const clickDeny = () => getDenyButton() && getDenyButton().click();
|
|
2329
|
+
/*
|
|
2330
|
+
* Global function to click 'Cancel' button
|
|
2331
|
+
*/
|
|
2663
2332
|
|
|
2664
|
-
|
|
2665
|
-
preConfirmPromise.then(preConfirmValue => {
|
|
2666
|
-
if (isVisible(getValidationMessage()) || preConfirmValue === false) {
|
|
2667
|
-
instance.hideLoading();
|
|
2668
|
-
} else {
|
|
2669
|
-
succeedWith(instance, typeof preConfirmValue === 'undefined' ? value : preConfirmValue);
|
|
2670
|
-
}
|
|
2671
|
-
}).catch(error$$1 => rejectWith(instance || undefined, error$$1));
|
|
2672
|
-
} else {
|
|
2673
|
-
succeedWith(instance, value);
|
|
2674
|
-
}
|
|
2675
|
-
};
|
|
2333
|
+
const clickCancel = () => getCancelButton() && getCancelButton().click();
|
|
2676
2334
|
|
|
2677
2335
|
const addKeydownHandler = (instance, globalState, innerParams, dismissWith) => {
|
|
2678
2336
|
if (globalState.keydownTarget && globalState.keydownHandlerAdded) {
|
|
@@ -2783,245 +2441,523 @@
|
|
|
2783
2441
|
const denyButton = getDenyButton();
|
|
2784
2442
|
const cancelButton = getCancelButton();
|
|
2785
2443
|
|
|
2786
|
-
if (![confirmButton, denyButton, cancelButton].includes(document.activeElement)) {
|
|
2787
|
-
return;
|
|
2444
|
+
if (![confirmButton, denyButton, cancelButton].includes(document.activeElement)) {
|
|
2445
|
+
return;
|
|
2446
|
+
}
|
|
2447
|
+
|
|
2448
|
+
const sibling = arrowKeysNextButton.includes(key) ? 'nextElementSibling' : 'previousElementSibling';
|
|
2449
|
+
const buttonToFocus = document.activeElement[sibling];
|
|
2450
|
+
|
|
2451
|
+
if (buttonToFocus instanceof HTMLElement) {
|
|
2452
|
+
buttonToFocus.focus();
|
|
2453
|
+
}
|
|
2454
|
+
};
|
|
2455
|
+
|
|
2456
|
+
const handleEsc = (e, innerParams, dismissWith) => {
|
|
2457
|
+
if (callIfFunction(innerParams.allowEscapeKey)) {
|
|
2458
|
+
e.preventDefault();
|
|
2459
|
+
dismissWith(DismissReason.esc);
|
|
2460
|
+
}
|
|
2461
|
+
};
|
|
2462
|
+
|
|
2463
|
+
const isJqueryElement = elem => typeof elem === 'object' && elem.jquery;
|
|
2464
|
+
|
|
2465
|
+
const isElement = elem => elem instanceof Element || isJqueryElement(elem);
|
|
2466
|
+
|
|
2467
|
+
const argsToParams = args => {
|
|
2468
|
+
const params = {};
|
|
2469
|
+
|
|
2470
|
+
if (typeof args[0] === 'object' && !isElement(args[0])) {
|
|
2471
|
+
Object.assign(params, args[0]);
|
|
2472
|
+
} else {
|
|
2473
|
+
['title', 'html', 'icon'].forEach((name, index) => {
|
|
2474
|
+
const arg = args[index];
|
|
2475
|
+
|
|
2476
|
+
if (typeof arg === 'string' || isElement(arg)) {
|
|
2477
|
+
params[name] = arg;
|
|
2478
|
+
} else if (arg !== undefined) {
|
|
2479
|
+
error("Unexpected type of ".concat(name, "! Expected \"string\" or \"Element\", got ").concat(typeof arg));
|
|
2480
|
+
}
|
|
2481
|
+
});
|
|
2482
|
+
}
|
|
2483
|
+
|
|
2484
|
+
return params;
|
|
2485
|
+
};
|
|
2486
|
+
|
|
2487
|
+
function fire() {
|
|
2488
|
+
const Swal = this;
|
|
2489
|
+
|
|
2490
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2491
|
+
args[_key] = arguments[_key];
|
|
2492
|
+
}
|
|
2493
|
+
|
|
2494
|
+
return new Swal(...args);
|
|
2495
|
+
}
|
|
2496
|
+
|
|
2497
|
+
/**
|
|
2498
|
+
* Returns an extended version of `Swal` containing `params` as defaults.
|
|
2499
|
+
* Useful for reusing Swal configuration.
|
|
2500
|
+
*
|
|
2501
|
+
* For example:
|
|
2502
|
+
*
|
|
2503
|
+
* Before:
|
|
2504
|
+
* const textPromptOptions = { input: 'text', showCancelButton: true }
|
|
2505
|
+
* const {value: firstName} = await Swal.fire({ ...textPromptOptions, title: 'What is your first name?' })
|
|
2506
|
+
* const {value: lastName} = await Swal.fire({ ...textPromptOptions, title: 'What is your last name?' })
|
|
2507
|
+
*
|
|
2508
|
+
* After:
|
|
2509
|
+
* const TextPrompt = Swal.mixin({ input: 'text', showCancelButton: true })
|
|
2510
|
+
* const {value: firstName} = await TextPrompt('What is your first name?')
|
|
2511
|
+
* const {value: lastName} = await TextPrompt('What is your last name?')
|
|
2512
|
+
*
|
|
2513
|
+
* @param mixinParams
|
|
2514
|
+
*/
|
|
2515
|
+
function mixin(mixinParams) {
|
|
2516
|
+
class MixinSwal extends this {
|
|
2517
|
+
_main(params, priorityMixinParams) {
|
|
2518
|
+
return super._main(params, Object.assign({}, mixinParams, priorityMixinParams));
|
|
2519
|
+
}
|
|
2520
|
+
|
|
2521
|
+
}
|
|
2522
|
+
|
|
2523
|
+
return MixinSwal;
|
|
2524
|
+
}
|
|
2525
|
+
|
|
2526
|
+
/**
|
|
2527
|
+
* If `timer` parameter is set, returns number of milliseconds of timer remained.
|
|
2528
|
+
* Otherwise, returns undefined.
|
|
2529
|
+
*/
|
|
2530
|
+
|
|
2531
|
+
const getTimerLeft = () => {
|
|
2532
|
+
return globalState.timeout && globalState.timeout.getTimerLeft();
|
|
2533
|
+
};
|
|
2534
|
+
/**
|
|
2535
|
+
* Stop timer. Returns number of milliseconds of timer remained.
|
|
2536
|
+
* If `timer` parameter isn't set, returns undefined.
|
|
2537
|
+
*/
|
|
2538
|
+
|
|
2539
|
+
const stopTimer = () => {
|
|
2540
|
+
if (globalState.timeout) {
|
|
2541
|
+
stopTimerProgressBar();
|
|
2542
|
+
return globalState.timeout.stop();
|
|
2543
|
+
}
|
|
2544
|
+
};
|
|
2545
|
+
/**
|
|
2546
|
+
* Resume timer. Returns number of milliseconds of timer remained.
|
|
2547
|
+
* If `timer` parameter isn't set, returns undefined.
|
|
2548
|
+
*/
|
|
2549
|
+
|
|
2550
|
+
const resumeTimer = () => {
|
|
2551
|
+
if (globalState.timeout) {
|
|
2552
|
+
const remaining = globalState.timeout.start();
|
|
2553
|
+
animateTimerProgressBar(remaining);
|
|
2554
|
+
return remaining;
|
|
2555
|
+
}
|
|
2556
|
+
};
|
|
2557
|
+
/**
|
|
2558
|
+
* Resume timer. Returns number of milliseconds of timer remained.
|
|
2559
|
+
* If `timer` parameter isn't set, returns undefined.
|
|
2560
|
+
*/
|
|
2561
|
+
|
|
2562
|
+
const toggleTimer = () => {
|
|
2563
|
+
const timer = globalState.timeout;
|
|
2564
|
+
return timer && (timer.running ? stopTimer() : resumeTimer());
|
|
2565
|
+
};
|
|
2566
|
+
/**
|
|
2567
|
+
* Increase timer. Returns number of milliseconds of an updated timer.
|
|
2568
|
+
* If `timer` parameter isn't set, returns undefined.
|
|
2569
|
+
*/
|
|
2570
|
+
|
|
2571
|
+
const increaseTimer = n => {
|
|
2572
|
+
if (globalState.timeout) {
|
|
2573
|
+
const remaining = globalState.timeout.increase(n);
|
|
2574
|
+
animateTimerProgressBar(remaining, true);
|
|
2575
|
+
return remaining;
|
|
2576
|
+
}
|
|
2577
|
+
};
|
|
2578
|
+
/**
|
|
2579
|
+
* Check if timer is running. Returns true if timer is running
|
|
2580
|
+
* or false if timer is paused or stopped.
|
|
2581
|
+
* If `timer` parameter isn't set, returns undefined
|
|
2582
|
+
*/
|
|
2583
|
+
|
|
2584
|
+
const isTimerRunning = () => {
|
|
2585
|
+
return globalState.timeout && globalState.timeout.isRunning();
|
|
2586
|
+
};
|
|
2587
|
+
|
|
2588
|
+
let bodyClickListenerAdded = false;
|
|
2589
|
+
const clickHandlers = {};
|
|
2590
|
+
function bindClickHandler() {
|
|
2591
|
+
let attr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'data-swal-template';
|
|
2592
|
+
clickHandlers[attr] = this;
|
|
2593
|
+
|
|
2594
|
+
if (!bodyClickListenerAdded) {
|
|
2595
|
+
document.body.addEventListener('click', bodyClickListener);
|
|
2596
|
+
bodyClickListenerAdded = true;
|
|
2597
|
+
}
|
|
2598
|
+
}
|
|
2599
|
+
|
|
2600
|
+
const bodyClickListener = event => {
|
|
2601
|
+
for (let el = event.target; el && el !== document; el = el.parentNode) {
|
|
2602
|
+
for (const attr in clickHandlers) {
|
|
2603
|
+
const template = el.getAttribute(attr);
|
|
2604
|
+
|
|
2605
|
+
if (template) {
|
|
2606
|
+
clickHandlers[attr].fire({
|
|
2607
|
+
template
|
|
2608
|
+
});
|
|
2609
|
+
return;
|
|
2610
|
+
}
|
|
2611
|
+
}
|
|
2612
|
+
}
|
|
2613
|
+
};
|
|
2614
|
+
|
|
2615
|
+
|
|
2616
|
+
|
|
2617
|
+
var staticMethods = /*#__PURE__*/Object.freeze({
|
|
2618
|
+
isValidParameter: isValidParameter,
|
|
2619
|
+
isUpdatableParameter: isUpdatableParameter,
|
|
2620
|
+
isDeprecatedParameter: isDeprecatedParameter,
|
|
2621
|
+
argsToParams: argsToParams,
|
|
2622
|
+
isVisible: isVisible$1,
|
|
2623
|
+
clickConfirm: clickConfirm,
|
|
2624
|
+
clickDeny: clickDeny,
|
|
2625
|
+
clickCancel: clickCancel,
|
|
2626
|
+
getContainer: getContainer,
|
|
2627
|
+
getPopup: getPopup,
|
|
2628
|
+
getTitle: getTitle,
|
|
2629
|
+
getHtmlContainer: getHtmlContainer,
|
|
2630
|
+
getImage: getImage,
|
|
2631
|
+
getIcon: getIcon,
|
|
2632
|
+
getInputLabel: getInputLabel,
|
|
2633
|
+
getCloseButton: getCloseButton,
|
|
2634
|
+
getActions: getActions,
|
|
2635
|
+
getConfirmButton: getConfirmButton,
|
|
2636
|
+
getDenyButton: getDenyButton,
|
|
2637
|
+
getCancelButton: getCancelButton,
|
|
2638
|
+
getLoader: getLoader,
|
|
2639
|
+
getFooter: getFooter,
|
|
2640
|
+
getTimerProgressBar: getTimerProgressBar,
|
|
2641
|
+
getFocusableElements: getFocusableElements,
|
|
2642
|
+
getValidationMessage: getValidationMessage,
|
|
2643
|
+
isLoading: isLoading,
|
|
2644
|
+
fire: fire,
|
|
2645
|
+
mixin: mixin,
|
|
2646
|
+
showLoading: showLoading,
|
|
2647
|
+
enableLoading: showLoading,
|
|
2648
|
+
getTimerLeft: getTimerLeft,
|
|
2649
|
+
stopTimer: stopTimer,
|
|
2650
|
+
resumeTimer: resumeTimer,
|
|
2651
|
+
toggleTimer: toggleTimer,
|
|
2652
|
+
increaseTimer: increaseTimer,
|
|
2653
|
+
isTimerRunning: isTimerRunning,
|
|
2654
|
+
bindClickHandler: bindClickHandler
|
|
2655
|
+
});
|
|
2656
|
+
|
|
2657
|
+
/**
|
|
2658
|
+
* Hides loader and shows back the button which was hidden by .showLoading()
|
|
2659
|
+
*/
|
|
2660
|
+
|
|
2661
|
+
function hideLoading() {
|
|
2662
|
+
// do nothing if popup is closed
|
|
2663
|
+
const innerParams = privateProps.innerParams.get(this);
|
|
2664
|
+
|
|
2665
|
+
if (!innerParams) {
|
|
2666
|
+
return;
|
|
2667
|
+
}
|
|
2668
|
+
|
|
2669
|
+
const domCache = privateProps.domCache.get(this);
|
|
2670
|
+
hide(domCache.loader);
|
|
2671
|
+
|
|
2672
|
+
if (isToast()) {
|
|
2673
|
+
if (innerParams.icon) {
|
|
2674
|
+
show(getIcon());
|
|
2675
|
+
}
|
|
2676
|
+
} else {
|
|
2677
|
+
showRelatedButton(domCache);
|
|
2788
2678
|
}
|
|
2789
2679
|
|
|
2790
|
-
|
|
2791
|
-
|
|
2680
|
+
removeClass([domCache.popup, domCache.actions], swalClasses.loading);
|
|
2681
|
+
domCache.popup.removeAttribute('aria-busy');
|
|
2682
|
+
domCache.popup.removeAttribute('data-loading');
|
|
2683
|
+
domCache.confirmButton.disabled = false;
|
|
2684
|
+
domCache.denyButton.disabled = false;
|
|
2685
|
+
domCache.cancelButton.disabled = false;
|
|
2686
|
+
}
|
|
2792
2687
|
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
}
|
|
2796
|
-
};
|
|
2688
|
+
const showRelatedButton = domCache => {
|
|
2689
|
+
const buttonToReplace = domCache.popup.getElementsByClassName(domCache.loader.getAttribute('data-button-to-replace'));
|
|
2797
2690
|
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2691
|
+
if (buttonToReplace.length) {
|
|
2692
|
+
show(buttonToReplace[0], 'inline-block');
|
|
2693
|
+
} else if (allButtonsAreHidden()) {
|
|
2694
|
+
hide(domCache.actions);
|
|
2802
2695
|
}
|
|
2803
2696
|
};
|
|
2804
2697
|
|
|
2805
|
-
|
|
2806
|
-
|
|
2698
|
+
/**
|
|
2699
|
+
* Gets the input DOM node, this method works with input parameter.
|
|
2700
|
+
* @returns {HTMLElement | null}
|
|
2701
|
+
*/
|
|
2807
2702
|
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
// Ignore click events that had mousedown on the popup but mouseup on the container
|
|
2812
|
-
// This can happen when the user drags a slider
|
|
2813
|
-
handleModalMousedown(domCache); // Ignore click events that had mousedown on the container but mouseup on the popup
|
|
2703
|
+
function getInput$1(instance) {
|
|
2704
|
+
const innerParams = privateProps.innerParams.get(instance || this);
|
|
2705
|
+
const domCache = privateProps.domCache.get(instance || this);
|
|
2814
2706
|
|
|
2815
|
-
|
|
2816
|
-
|
|
2707
|
+
if (!domCache) {
|
|
2708
|
+
return null;
|
|
2817
2709
|
}
|
|
2818
|
-
};
|
|
2819
2710
|
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
domCache.popup.onclick = () => {
|
|
2823
|
-
const innerParams = privateProps.innerParams.get(instance);
|
|
2824
|
-
|
|
2825
|
-
if (innerParams.showConfirmButton || innerParams.showDenyButton || innerParams.showCancelButton || innerParams.showCloseButton || innerParams.timer || innerParams.input) {
|
|
2826
|
-
return;
|
|
2827
|
-
}
|
|
2711
|
+
return getInput(domCache.popup, innerParams.input);
|
|
2712
|
+
}
|
|
2828
2713
|
|
|
2829
|
-
|
|
2830
|
-
|
|
2714
|
+
/**
|
|
2715
|
+
* This module contains `WeakMap`s for each effectively-"private property" that a `Swal` has.
|
|
2716
|
+
* For example, to set the private property "foo" of `this` to "bar", you can `privateProps.foo.set(this, 'bar')`
|
|
2717
|
+
* This is the approach that Babel will probably take to implement private methods/fields
|
|
2718
|
+
* https://github.com/tc39/proposal-private-methods
|
|
2719
|
+
* https://github.com/babel/babel/pull/7555
|
|
2720
|
+
* Once we have the changes from that PR in Babel, and our core class fits reasonable in *one module*
|
|
2721
|
+
* then we can use that language feature.
|
|
2722
|
+
*/
|
|
2723
|
+
var privateMethods = {
|
|
2724
|
+
swalPromiseResolve: new WeakMap(),
|
|
2725
|
+
swalPromiseReject: new WeakMap()
|
|
2831
2726
|
};
|
|
2832
2727
|
|
|
2833
|
-
|
|
2728
|
+
/*
|
|
2729
|
+
* Instance method to close sweetAlert
|
|
2730
|
+
*/
|
|
2834
2731
|
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2732
|
+
function removePopupAndResetState(instance, container, returnFocus, didClose) {
|
|
2733
|
+
if (isToast()) {
|
|
2734
|
+
triggerDidCloseAndDispose(instance, didClose);
|
|
2735
|
+
} else {
|
|
2736
|
+
restoreActiveElement(returnFocus).then(() => triggerDidCloseAndDispose(instance, didClose));
|
|
2737
|
+
globalState.keydownTarget.removeEventListener('keydown', globalState.keydownHandler, {
|
|
2738
|
+
capture: globalState.keydownListenerCapture
|
|
2739
|
+
});
|
|
2740
|
+
globalState.keydownHandlerAdded = false;
|
|
2741
|
+
}
|
|
2840
2742
|
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
}
|
|
2844
|
-
};
|
|
2845
|
-
};
|
|
2846
|
-
};
|
|
2743
|
+
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent); // workaround for #2088
|
|
2744
|
+
// for some reason removing the container in Safari will scroll the document to bottom
|
|
2847
2745
|
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2746
|
+
if (isSafari) {
|
|
2747
|
+
container.setAttribute('style', 'display:none !important');
|
|
2748
|
+
container.removeAttribute('class');
|
|
2749
|
+
container.innerHTML = '';
|
|
2750
|
+
} else {
|
|
2751
|
+
container.remove();
|
|
2752
|
+
}
|
|
2852
2753
|
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
}
|
|
2858
|
-
};
|
|
2754
|
+
if (isModal()) {
|
|
2755
|
+
undoScrollbar();
|
|
2756
|
+
undoIOSfix();
|
|
2757
|
+
unsetAriaHidden();
|
|
2758
|
+
}
|
|
2859
2759
|
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
const innerParams = privateProps.innerParams.get(instance);
|
|
2760
|
+
removeBodyClasses();
|
|
2761
|
+
}
|
|
2863
2762
|
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
}
|
|
2763
|
+
function removeBodyClasses() {
|
|
2764
|
+
removeClass([document.documentElement, document.body], [swalClasses.shown, swalClasses['height-auto'], swalClasses['no-backdrop'], swalClasses['toast-shown']]);
|
|
2765
|
+
}
|
|
2868
2766
|
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
};
|
|
2767
|
+
function close(resolveValue) {
|
|
2768
|
+
resolveValue = prepareResolveValue(resolveValue);
|
|
2769
|
+
const swalPromiseResolve = privateMethods.swalPromiseResolve.get(this);
|
|
2770
|
+
const didClose = triggerClosePopup(this);
|
|
2874
2771
|
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2772
|
+
if (this.isAwaitingPromise()) {
|
|
2773
|
+
// A swal awaiting for a promise (after a click on Confirm or Deny) cannot be dismissed anymore #2335
|
|
2774
|
+
if (!resolveValue.isDismissed) {
|
|
2775
|
+
handleAwaitingPromise(this);
|
|
2776
|
+
swalPromiseResolve(resolveValue);
|
|
2777
|
+
}
|
|
2778
|
+
} else if (didClose) {
|
|
2779
|
+
// Resolve Swal promise
|
|
2780
|
+
swalPromiseResolve(resolveValue);
|
|
2781
|
+
}
|
|
2782
|
+
}
|
|
2783
|
+
function isAwaitingPromise() {
|
|
2784
|
+
return !!privateProps.awaitingPromise.get(this);
|
|
2785
|
+
}
|
|
2878
2786
|
|
|
2879
|
-
|
|
2880
|
-
|
|
2787
|
+
const triggerClosePopup = instance => {
|
|
2788
|
+
const popup = getPopup();
|
|
2881
2789
|
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
}
|
|
2790
|
+
if (!popup) {
|
|
2791
|
+
return false;
|
|
2885
2792
|
}
|
|
2886
2793
|
|
|
2887
|
-
|
|
2888
|
-
const innerParams = prepareParams(userParams, mixinParams);
|
|
2889
|
-
setParameters(innerParams);
|
|
2890
|
-
Object.freeze(innerParams); // clear the previous timer
|
|
2794
|
+
const innerParams = privateProps.innerParams.get(instance);
|
|
2891
2795
|
|
|
2892
|
-
if (
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2796
|
+
if (!innerParams || hasClass(popup, innerParams.hideClass.popup)) {
|
|
2797
|
+
return false;
|
|
2798
|
+
}
|
|
2799
|
+
|
|
2800
|
+
removeClass(popup, innerParams.showClass.popup);
|
|
2801
|
+
addClass(popup, innerParams.hideClass.popup);
|
|
2802
|
+
const backdrop = getContainer();
|
|
2803
|
+
removeClass(backdrop, innerParams.showClass.backdrop);
|
|
2804
|
+
addClass(backdrop, innerParams.hideClass.backdrop);
|
|
2805
|
+
handlePopupAnimation(instance, popup, innerParams);
|
|
2806
|
+
return true;
|
|
2807
|
+
};
|
|
2896
2808
|
|
|
2809
|
+
function rejectPromise(error) {
|
|
2810
|
+
const rejectPromise = privateMethods.swalPromiseReject.get(this);
|
|
2811
|
+
handleAwaitingPromise(this);
|
|
2897
2812
|
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
return swalPromise(this, domCache, innerParams);
|
|
2813
|
+
if (rejectPromise) {
|
|
2814
|
+
// Reject Swal promise
|
|
2815
|
+
rejectPromise(error);
|
|
2816
|
+
}
|
|
2903
2817
|
}
|
|
2904
2818
|
|
|
2905
|
-
const
|
|
2906
|
-
|
|
2907
|
-
|
|
2819
|
+
const handleAwaitingPromise = instance => {
|
|
2820
|
+
if (instance.isAwaitingPromise()) {
|
|
2821
|
+
privateProps.awaitingPromise.delete(instance); // The instance might have been previously partly destroyed, we must resume the destroy process in this case #2335
|
|
2908
2822
|
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2823
|
+
if (!privateProps.innerParams.get(instance)) {
|
|
2824
|
+
instance._destroy();
|
|
2825
|
+
}
|
|
2826
|
+
}
|
|
2912
2827
|
};
|
|
2913
2828
|
|
|
2914
|
-
const
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
});
|
|
2829
|
+
const prepareResolveValue = resolveValue => {
|
|
2830
|
+
// When user calls Swal.close()
|
|
2831
|
+
if (typeof resolveValue === 'undefined') {
|
|
2832
|
+
return {
|
|
2833
|
+
isConfirmed: false,
|
|
2834
|
+
isDenied: false,
|
|
2835
|
+
isDismissed: true
|
|
2922
2836
|
};
|
|
2837
|
+
}
|
|
2923
2838
|
|
|
2924
|
-
|
|
2925
|
-
|
|
2839
|
+
return Object.assign({
|
|
2840
|
+
isConfirmed: false,
|
|
2841
|
+
isDenied: false,
|
|
2842
|
+
isDismissed: false
|
|
2843
|
+
}, resolveValue);
|
|
2844
|
+
};
|
|
2926
2845
|
|
|
2927
|
-
|
|
2846
|
+
const handlePopupAnimation = (instance, popup, innerParams) => {
|
|
2847
|
+
const container = getContainer(); // If animation is supported, animate
|
|
2928
2848
|
|
|
2929
|
-
|
|
2849
|
+
const animationIsSupported = animationEndEvent && hasCssAnimation(popup);
|
|
2930
2850
|
|
|
2931
|
-
|
|
2851
|
+
if (typeof innerParams.willClose === 'function') {
|
|
2852
|
+
innerParams.willClose(popup);
|
|
2853
|
+
}
|
|
2932
2854
|
|
|
2933
|
-
|
|
2855
|
+
if (animationIsSupported) {
|
|
2856
|
+
animatePopup(instance, popup, container, innerParams.returnFocus, innerParams.didClose);
|
|
2857
|
+
} else {
|
|
2858
|
+
// Otherwise, remove immediately
|
|
2859
|
+
removePopupAndResetState(instance, container, innerParams.returnFocus, innerParams.didClose);
|
|
2860
|
+
}
|
|
2861
|
+
};
|
|
2934
2862
|
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2863
|
+
const animatePopup = (instance, popup, container, returnFocus, didClose) => {
|
|
2864
|
+
globalState.swalCloseEventFinishedCallback = removePopupAndResetState.bind(null, instance, container, returnFocus, didClose);
|
|
2865
|
+
popup.addEventListener(animationEndEvent, function (e) {
|
|
2866
|
+
if (e.target === popup) {
|
|
2867
|
+
globalState.swalCloseEventFinishedCallback();
|
|
2868
|
+
delete globalState.swalCloseEventFinishedCallback;
|
|
2869
|
+
}
|
|
2870
|
+
});
|
|
2871
|
+
};
|
|
2872
|
+
|
|
2873
|
+
const triggerDidCloseAndDispose = (instance, didClose) => {
|
|
2874
|
+
setTimeout(() => {
|
|
2875
|
+
if (typeof didClose === 'function') {
|
|
2876
|
+
didClose.bind(instance.params)();
|
|
2877
|
+
}
|
|
2941
2878
|
|
|
2942
|
-
|
|
2943
|
-
domCache.container.scrollTop = 0;
|
|
2944
|
-
});
|
|
2879
|
+
instance._destroy();
|
|
2945
2880
|
});
|
|
2946
2881
|
};
|
|
2947
2882
|
|
|
2948
|
-
|
|
2949
|
-
const domCache =
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
denyButton: getDenyButton(),
|
|
2955
|
-
cancelButton: getCancelButton(),
|
|
2956
|
-
loader: getLoader(),
|
|
2957
|
-
closeButton: getCloseButton(),
|
|
2958
|
-
validationMessage: getValidationMessage(),
|
|
2959
|
-
progressSteps: getProgressSteps()
|
|
2960
|
-
};
|
|
2961
|
-
privateProps.domCache.set(instance, domCache);
|
|
2962
|
-
return domCache;
|
|
2963
|
-
};
|
|
2883
|
+
function setButtonsDisabled(instance, buttons, disabled) {
|
|
2884
|
+
const domCache = privateProps.domCache.get(instance);
|
|
2885
|
+
buttons.forEach(button => {
|
|
2886
|
+
domCache[button].disabled = disabled;
|
|
2887
|
+
});
|
|
2888
|
+
}
|
|
2964
2889
|
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2890
|
+
function setInputDisabled(input, disabled) {
|
|
2891
|
+
if (!input) {
|
|
2892
|
+
return false;
|
|
2893
|
+
}
|
|
2968
2894
|
|
|
2969
|
-
if (
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
delete globalState$$1.timeout;
|
|
2973
|
-
}, innerParams.timer);
|
|
2895
|
+
if (input.type === 'radio') {
|
|
2896
|
+
const radiosContainer = input.parentNode.parentNode;
|
|
2897
|
+
const radios = radiosContainer.querySelectorAll('input');
|
|
2974
2898
|
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
setTimeout(() => {
|
|
2978
|
-
if (globalState$$1.timeout && globalState$$1.timeout.running) {
|
|
2979
|
-
// timer can be already stopped or unset at this point
|
|
2980
|
-
animateTimerProgressBar(innerParams.timer);
|
|
2981
|
-
}
|
|
2982
|
-
});
|
|
2899
|
+
for (let i = 0; i < radios.length; i++) {
|
|
2900
|
+
radios[i].disabled = disabled;
|
|
2983
2901
|
}
|
|
2902
|
+
} else {
|
|
2903
|
+
input.disabled = disabled;
|
|
2984
2904
|
}
|
|
2985
|
-
}
|
|
2905
|
+
}
|
|
2986
2906
|
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2907
|
+
function enableButtons() {
|
|
2908
|
+
setButtonsDisabled(this, ['confirmButton', 'denyButton', 'cancelButton'], false);
|
|
2909
|
+
}
|
|
2910
|
+
function disableButtons() {
|
|
2911
|
+
setButtonsDisabled(this, ['confirmButton', 'denyButton', 'cancelButton'], true);
|
|
2912
|
+
}
|
|
2913
|
+
function enableInput() {
|
|
2914
|
+
return setInputDisabled(this.getInput(), false);
|
|
2915
|
+
}
|
|
2916
|
+
function disableInput() {
|
|
2917
|
+
return setInputDisabled(this.getInput(), true);
|
|
2918
|
+
}
|
|
2991
2919
|
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2920
|
+
function showValidationMessage(error) {
|
|
2921
|
+
const domCache = privateProps.domCache.get(this);
|
|
2922
|
+
const params = privateProps.innerParams.get(this);
|
|
2923
|
+
setInnerHtml(domCache.validationMessage, error);
|
|
2924
|
+
domCache.validationMessage.className = swalClasses['validation-message'];
|
|
2995
2925
|
|
|
2996
|
-
if (
|
|
2997
|
-
|
|
2926
|
+
if (params.customClass && params.customClass.validationMessage) {
|
|
2927
|
+
addClass(domCache.validationMessage, params.customClass.validationMessage);
|
|
2998
2928
|
}
|
|
2999
|
-
};
|
|
3000
2929
|
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
domCache.denyButton.focus();
|
|
3004
|
-
return true;
|
|
3005
|
-
}
|
|
2930
|
+
show(domCache.validationMessage);
|
|
2931
|
+
const input = this.getInput();
|
|
3006
2932
|
|
|
3007
|
-
if (
|
|
3008
|
-
|
|
3009
|
-
|
|
2933
|
+
if (input) {
|
|
2934
|
+
input.setAttribute('aria-invalid', true);
|
|
2935
|
+
input.setAttribute('aria-describedby', swalClasses['validation-message']);
|
|
2936
|
+
focusInput(input);
|
|
2937
|
+
addClass(input, swalClasses.inputerror);
|
|
3010
2938
|
}
|
|
2939
|
+
} // Hide block with validation message
|
|
3011
2940
|
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
2941
|
+
function resetValidationMessage$1() {
|
|
2942
|
+
const domCache = privateProps.domCache.get(this);
|
|
2943
|
+
|
|
2944
|
+
if (domCache.validationMessage) {
|
|
2945
|
+
hide(domCache.validationMessage);
|
|
3015
2946
|
}
|
|
3016
2947
|
|
|
3017
|
-
|
|
3018
|
-
};
|
|
2948
|
+
const input = this.getInput();
|
|
3019
2949
|
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
2950
|
+
if (input) {
|
|
2951
|
+
input.removeAttribute('aria-invalid');
|
|
2952
|
+
input.removeAttribute('aria-describedby');
|
|
2953
|
+
removeClass(input, swalClasses.inputerror);
|
|
3023
2954
|
}
|
|
3024
|
-
}
|
|
2955
|
+
}
|
|
2956
|
+
|
|
2957
|
+
function getProgressSteps$1() {
|
|
2958
|
+
const domCache = privateProps.domCache.get(this);
|
|
2959
|
+
return domCache.progressSteps;
|
|
2960
|
+
}
|
|
3025
2961
|
|
|
3026
2962
|
/**
|
|
3027
2963
|
* Updates popup parameters.
|
|
@@ -3038,7 +2974,7 @@
|
|
|
3038
2974
|
const validUpdatableParams = {}; // assign valid params from `params` to `defaults`
|
|
3039
2975
|
|
|
3040
2976
|
Object.keys(params).forEach(param => {
|
|
3041
|
-
if (
|
|
2977
|
+
if (isUpdatableParameter(param)) {
|
|
3042
2978
|
validUpdatableParams[param] = params[param];
|
|
3043
2979
|
} else {
|
|
3044
2980
|
warn("Invalid parameter to update: \"".concat(param, "\". Updatable params are listed here: https://github.com/sweetalert2/sweetalert2/blob/master/src/utils/params.js\n\nIf you think this parameter should be updatable, request it here: https://github.com/sweetalert2/sweetalert2/issues/new?template=02_feature_request.md"));
|
|
@@ -3132,7 +3068,6 @@
|
|
|
3132
3068
|
showValidationMessage: showValidationMessage,
|
|
3133
3069
|
resetValidationMessage: resetValidationMessage$1,
|
|
3134
3070
|
getProgressSteps: getProgressSteps$1,
|
|
3135
|
-
_main: _main,
|
|
3136
3071
|
update: update,
|
|
3137
3072
|
_destroy: _destroy
|
|
3138
3073
|
});
|
|
@@ -3146,7 +3081,7 @@
|
|
|
3146
3081
|
return;
|
|
3147
3082
|
}
|
|
3148
3083
|
|
|
3149
|
-
currentInstance = this;
|
|
3084
|
+
currentInstance = this; // @ts-ignore
|
|
3150
3085
|
|
|
3151
3086
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3152
3087
|
args[_key] = arguments[_key];
|
|
@@ -3160,11 +3095,41 @@
|
|
|
3160
3095
|
enumerable: true,
|
|
3161
3096
|
configurable: true
|
|
3162
3097
|
}
|
|
3163
|
-
});
|
|
3098
|
+
}); // @ts-ignore
|
|
3164
3099
|
|
|
3165
3100
|
const promise = this._main(this.params);
|
|
3166
3101
|
|
|
3167
3102
|
privateProps.promise.set(this, promise);
|
|
3103
|
+
}
|
|
3104
|
+
|
|
3105
|
+
_main(userParams) {
|
|
3106
|
+
let mixinParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
3107
|
+
showWarningsForParams(Object.assign({}, mixinParams, userParams));
|
|
3108
|
+
|
|
3109
|
+
if (globalState.currentInstance) {
|
|
3110
|
+
globalState.currentInstance._destroy();
|
|
3111
|
+
|
|
3112
|
+
if (isModal()) {
|
|
3113
|
+
unsetAriaHidden();
|
|
3114
|
+
}
|
|
3115
|
+
}
|
|
3116
|
+
|
|
3117
|
+
globalState.currentInstance = this;
|
|
3118
|
+
const innerParams = prepareParams(userParams, mixinParams);
|
|
3119
|
+
setParameters(innerParams);
|
|
3120
|
+
Object.freeze(innerParams); // clear the previous timer
|
|
3121
|
+
|
|
3122
|
+
if (globalState.timeout) {
|
|
3123
|
+
globalState.timeout.stop();
|
|
3124
|
+
delete globalState.timeout;
|
|
3125
|
+
} // clear the restore focus timeout
|
|
3126
|
+
|
|
3127
|
+
|
|
3128
|
+
clearTimeout(globalState.restoreFocusTimeout);
|
|
3129
|
+
const domCache = populateDomCache(this);
|
|
3130
|
+
render(this, innerParams);
|
|
3131
|
+
privateProps.innerParams.set(this, innerParams);
|
|
3132
|
+
return swalPromise(this, domCache, innerParams);
|
|
3168
3133
|
} // `catch` cannot be the name of a module export, so we define our thenable methods here instead
|
|
3169
3134
|
|
|
3170
3135
|
|
|
@@ -3178,7 +3143,128 @@
|
|
|
3178
3143
|
return promise.finally(onFinally);
|
|
3179
3144
|
}
|
|
3180
3145
|
|
|
3181
|
-
}
|
|
3146
|
+
}
|
|
3147
|
+
|
|
3148
|
+
const swalPromise = (instance, domCache, innerParams) => {
|
|
3149
|
+
return new Promise((resolve, reject) => {
|
|
3150
|
+
// functions to handle all closings/dismissals
|
|
3151
|
+
const dismissWith = dismiss => {
|
|
3152
|
+
instance.closePopup({
|
|
3153
|
+
isDismissed: true,
|
|
3154
|
+
dismiss
|
|
3155
|
+
});
|
|
3156
|
+
};
|
|
3157
|
+
|
|
3158
|
+
privateMethods.swalPromiseResolve.set(instance, resolve);
|
|
3159
|
+
privateMethods.swalPromiseReject.set(instance, reject);
|
|
3160
|
+
|
|
3161
|
+
domCache.confirmButton.onclick = () => handleConfirmButtonClick(instance);
|
|
3162
|
+
|
|
3163
|
+
domCache.denyButton.onclick = () => handleDenyButtonClick(instance);
|
|
3164
|
+
|
|
3165
|
+
domCache.cancelButton.onclick = () => handleCancelButtonClick(instance, dismissWith);
|
|
3166
|
+
|
|
3167
|
+
domCache.closeButton.onclick = () => dismissWith(DismissReason.close);
|
|
3168
|
+
|
|
3169
|
+
handlePopupClick(instance, domCache, dismissWith);
|
|
3170
|
+
addKeydownHandler(instance, globalState, innerParams, dismissWith);
|
|
3171
|
+
handleInputOptionsAndValue(instance, innerParams);
|
|
3172
|
+
openPopup(innerParams);
|
|
3173
|
+
setupTimer(globalState, innerParams, dismissWith);
|
|
3174
|
+
initFocus(domCache, innerParams); // Scroll container to top on open (#1247, #1946)
|
|
3175
|
+
|
|
3176
|
+
setTimeout(() => {
|
|
3177
|
+
domCache.container.scrollTop = 0;
|
|
3178
|
+
});
|
|
3179
|
+
});
|
|
3180
|
+
};
|
|
3181
|
+
|
|
3182
|
+
const prepareParams = (userParams, mixinParams) => {
|
|
3183
|
+
const templateParams = getTemplateParams(userParams);
|
|
3184
|
+
const params = Object.assign({}, defaultParams, mixinParams, templateParams, userParams); // precedence is described in #2131
|
|
3185
|
+
|
|
3186
|
+
params.showClass = Object.assign({}, defaultParams.showClass, params.showClass);
|
|
3187
|
+
params.hideClass = Object.assign({}, defaultParams.hideClass, params.hideClass);
|
|
3188
|
+
return params;
|
|
3189
|
+
};
|
|
3190
|
+
|
|
3191
|
+
const populateDomCache = instance => {
|
|
3192
|
+
const domCache = {
|
|
3193
|
+
popup: getPopup(),
|
|
3194
|
+
container: getContainer(),
|
|
3195
|
+
actions: getActions(),
|
|
3196
|
+
confirmButton: getConfirmButton(),
|
|
3197
|
+
denyButton: getDenyButton(),
|
|
3198
|
+
cancelButton: getCancelButton(),
|
|
3199
|
+
loader: getLoader(),
|
|
3200
|
+
closeButton: getCloseButton(),
|
|
3201
|
+
validationMessage: getValidationMessage(),
|
|
3202
|
+
progressSteps: getProgressSteps()
|
|
3203
|
+
};
|
|
3204
|
+
privateProps.domCache.set(instance, domCache);
|
|
3205
|
+
return domCache;
|
|
3206
|
+
};
|
|
3207
|
+
|
|
3208
|
+
const setupTimer = (globalState$$1, innerParams, dismissWith) => {
|
|
3209
|
+
const timerProgressBar = getTimerProgressBar();
|
|
3210
|
+
hide(timerProgressBar);
|
|
3211
|
+
|
|
3212
|
+
if (innerParams.timer) {
|
|
3213
|
+
globalState$$1.timeout = new Timer(() => {
|
|
3214
|
+
dismissWith('timer');
|
|
3215
|
+
delete globalState$$1.timeout;
|
|
3216
|
+
}, innerParams.timer);
|
|
3217
|
+
|
|
3218
|
+
if (innerParams.timerProgressBar) {
|
|
3219
|
+
show(timerProgressBar);
|
|
3220
|
+
setTimeout(() => {
|
|
3221
|
+
if (globalState$$1.timeout && globalState$$1.timeout.running) {
|
|
3222
|
+
// timer can be already stopped or unset at this point
|
|
3223
|
+
animateTimerProgressBar(innerParams.timer);
|
|
3224
|
+
}
|
|
3225
|
+
});
|
|
3226
|
+
}
|
|
3227
|
+
}
|
|
3228
|
+
};
|
|
3229
|
+
|
|
3230
|
+
const initFocus = (domCache, innerParams) => {
|
|
3231
|
+
if (innerParams.toast) {
|
|
3232
|
+
return;
|
|
3233
|
+
}
|
|
3234
|
+
|
|
3235
|
+
if (!callIfFunction(innerParams.allowEnterKey)) {
|
|
3236
|
+
return blurActiveElement();
|
|
3237
|
+
}
|
|
3238
|
+
|
|
3239
|
+
if (!focusButton(domCache, innerParams)) {
|
|
3240
|
+
setFocus(innerParams, -1, 1);
|
|
3241
|
+
}
|
|
3242
|
+
};
|
|
3243
|
+
|
|
3244
|
+
const focusButton = (domCache, innerParams) => {
|
|
3245
|
+
if (innerParams.focusDeny && isVisible(domCache.denyButton)) {
|
|
3246
|
+
domCache.denyButton.focus();
|
|
3247
|
+
return true;
|
|
3248
|
+
}
|
|
3249
|
+
|
|
3250
|
+
if (innerParams.focusCancel && isVisible(domCache.cancelButton)) {
|
|
3251
|
+
domCache.cancelButton.focus();
|
|
3252
|
+
return true;
|
|
3253
|
+
}
|
|
3254
|
+
|
|
3255
|
+
if (innerParams.focusConfirm && isVisible(domCache.confirmButton)) {
|
|
3256
|
+
domCache.confirmButton.focus();
|
|
3257
|
+
return true;
|
|
3258
|
+
}
|
|
3259
|
+
|
|
3260
|
+
return false;
|
|
3261
|
+
};
|
|
3262
|
+
|
|
3263
|
+
const blurActiveElement = () => {
|
|
3264
|
+
if (document.activeElement instanceof HTMLElement && typeof document.activeElement.blur === 'function') {
|
|
3265
|
+
document.activeElement.blur();
|
|
3266
|
+
}
|
|
3267
|
+
}; // Assign instance methods from src/instanceMethods/*.js to prototype
|
|
3182
3268
|
|
|
3183
3269
|
|
|
3184
3270
|
Object.assign(SweetAlert.prototype, instanceMethods); // Assign static methods from src/staticMethods/*.js to constructor
|
|
@@ -3193,9 +3279,10 @@
|
|
|
3193
3279
|
};
|
|
3194
3280
|
});
|
|
3195
3281
|
SweetAlert.DismissReason = DismissReason;
|
|
3196
|
-
SweetAlert.version = '11.2
|
|
3282
|
+
SweetAlert.version = '11.3.2';
|
|
3283
|
+
|
|
3284
|
+
const Swal = SweetAlert; // @ts-ignore
|
|
3197
3285
|
|
|
3198
|
-
const Swal = SweetAlert;
|
|
3199
3286
|
Swal.default = Swal;
|
|
3200
3287
|
|
|
3201
3288
|
return Swal;
|