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