clipboard.min.js
3 days ago
fapi.dev.js
3 days ago
fapi.dist.js
3 days ago
polyfill.min.js
3 days ago
sweetalert2.js
3 days ago
sweetalert2.min.css
3 days ago
sweetalert2.js
3638 lines
| 1 | /*! |
| 2 | * sweetalert2 v10.16.9 |
| 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', '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 | warnAboutDeprecation('Swal.queue()', "async/await"); |
| 1299 | var Swal = this; |
| 1300 | currentSteps = steps; |
| 1301 | |
| 1302 | var resetAndResolve = function resetAndResolve(resolve, value) { |
| 1303 | currentSteps = []; |
| 1304 | resolve(value); |
| 1305 | }; |
| 1306 | |
| 1307 | var queueResult = []; |
| 1308 | return new Promise(function (resolve) { |
| 1309 | (function step(i, callback) { |
| 1310 | if (i < currentSteps.length) { |
| 1311 | document.body.setAttribute('data-swal2-queue-step', i); |
| 1312 | Swal.fire(currentSteps[i]).then(function (result) { |
| 1313 | if (typeof result.value !== 'undefined') { |
| 1314 | queueResult.push(result.value); |
| 1315 | step(i + 1, callback); |
| 1316 | } else { |
| 1317 | resetAndResolve(resolve, { |
| 1318 | dismiss: result.dismiss |
| 1319 | }); |
| 1320 | } |
| 1321 | }); |
| 1322 | } else { |
| 1323 | resetAndResolve(resolve, { |
| 1324 | value: queueResult |
| 1325 | }); |
| 1326 | } |
| 1327 | })(0); |
| 1328 | }); |
| 1329 | }; |
| 1330 | /* |
| 1331 | * Global function for getting the index of current popup in queue |
| 1332 | */ |
| 1333 | |
| 1334 | var getQueueStep = function getQueueStep() { |
| 1335 | return getContainer() && getContainer().getAttribute('data-queue-step'); |
| 1336 | }; |
| 1337 | /* |
| 1338 | * Global function for inserting a popup to the queue |
| 1339 | */ |
| 1340 | |
| 1341 | var insertQueueStep = function insertQueueStep(step, index) { |
| 1342 | if (index && index < currentSteps.length) { |
| 1343 | return currentSteps.splice(index, 0, step); |
| 1344 | } |
| 1345 | |
| 1346 | return currentSteps.push(step); |
| 1347 | }; |
| 1348 | /* |
| 1349 | * Global function for deleting a popup from the queue |
| 1350 | */ |
| 1351 | |
| 1352 | var deleteQueueStep = function deleteQueueStep(index) { |
| 1353 | if (typeof currentSteps[index] !== 'undefined') { |
| 1354 | currentSteps.splice(index, 1); |
| 1355 | } |
| 1356 | }; |
| 1357 | |
| 1358 | var createStepElement = function createStepElement(step) { |
| 1359 | var stepEl = document.createElement('li'); |
| 1360 | addClass(stepEl, swalClasses['progress-step']); |
| 1361 | setInnerHtml(stepEl, step); |
| 1362 | return stepEl; |
| 1363 | }; |
| 1364 | |
| 1365 | var createLineElement = function createLineElement(params) { |
| 1366 | var lineEl = document.createElement('li'); |
| 1367 | addClass(lineEl, swalClasses['progress-step-line']); |
| 1368 | |
| 1369 | if (params.progressStepsDistance) { |
| 1370 | lineEl.style.width = params.progressStepsDistance; |
| 1371 | } |
| 1372 | |
| 1373 | return lineEl; |
| 1374 | }; |
| 1375 | |
| 1376 | var renderProgressSteps = function renderProgressSteps(instance, params) { |
| 1377 | var progressStepsContainer = getProgressSteps(); |
| 1378 | |
| 1379 | if (!params.progressSteps || params.progressSteps.length === 0) { |
| 1380 | return hide(progressStepsContainer); |
| 1381 | } |
| 1382 | |
| 1383 | show(progressStepsContainer); |
| 1384 | progressStepsContainer.textContent = ''; |
| 1385 | var currentProgressStep = parseInt(params.currentProgressStep === undefined ? getQueueStep() : params.currentProgressStep); |
| 1386 | |
| 1387 | if (currentProgressStep >= params.progressSteps.length) { |
| 1388 | warn('Invalid currentProgressStep parameter, it should be less than progressSteps.length ' + '(currentProgressStep like JS arrays starts from 0)'); |
| 1389 | } |
| 1390 | |
| 1391 | params.progressSteps.forEach(function (step, index) { |
| 1392 | var stepEl = createStepElement(step); |
| 1393 | progressStepsContainer.appendChild(stepEl); |
| 1394 | |
| 1395 | if (index === currentProgressStep) { |
| 1396 | addClass(stepEl, swalClasses['active-progress-step']); |
| 1397 | } |
| 1398 | |
| 1399 | if (index !== params.progressSteps.length - 1) { |
| 1400 | var lineEl = createLineElement(params); |
| 1401 | progressStepsContainer.appendChild(lineEl); |
| 1402 | } |
| 1403 | }); |
| 1404 | }; |
| 1405 | |
| 1406 | var renderTitle = function renderTitle(instance, params) { |
| 1407 | var title = getTitle(); |
| 1408 | toggle(title, params.title || params.titleText, 'block'); |
| 1409 | |
| 1410 | if (params.title) { |
| 1411 | parseHtmlToContainer(params.title, title); |
| 1412 | } |
| 1413 | |
| 1414 | if (params.titleText) { |
| 1415 | title.innerText = params.titleText; |
| 1416 | } // Custom class |
| 1417 | |
| 1418 | |
| 1419 | applyCustomClass(title, params, 'title'); |
| 1420 | }; |
| 1421 | |
| 1422 | var renderHeader = function renderHeader(instance, params) { |
| 1423 | var header = getHeader(); // Custom class |
| 1424 | |
| 1425 | applyCustomClass(header, params, 'header'); // Progress steps |
| 1426 | |
| 1427 | renderProgressSteps(instance, params); // Icon |
| 1428 | |
| 1429 | renderIcon(instance, params); // Image |
| 1430 | |
| 1431 | renderImage(instance, params); // Title |
| 1432 | |
| 1433 | renderTitle(instance, params); // Close button |
| 1434 | |
| 1435 | renderCloseButton(instance, params); |
| 1436 | }; |
| 1437 | |
| 1438 | var renderPopup = function renderPopup(instance, params) { |
| 1439 | var container = getContainer(); |
| 1440 | var popup = getPopup(); // Width |
| 1441 | |
| 1442 | if (params.toast) { |
| 1443 | // #2170 |
| 1444 | applyNumericalStyle(container, 'width', params.width); |
| 1445 | popup.style.width = '100%'; |
| 1446 | } else { |
| 1447 | applyNumericalStyle(popup, 'width', params.width); |
| 1448 | } // Padding |
| 1449 | |
| 1450 | |
| 1451 | applyNumericalStyle(popup, 'padding', params.padding); // Background |
| 1452 | |
| 1453 | if (params.background) { |
| 1454 | popup.style.background = params.background; |
| 1455 | } |
| 1456 | |
| 1457 | hide(getValidationMessage()); // Classes |
| 1458 | |
| 1459 | addClasses(popup, params); |
| 1460 | }; |
| 1461 | |
| 1462 | var addClasses = function addClasses(popup, params) { |
| 1463 | // Default Class + showClass when updating Swal.update({}) |
| 1464 | popup.className = "".concat(swalClasses.popup, " ").concat(isVisible(popup) ? params.showClass.popup : ''); |
| 1465 | |
| 1466 | if (params.toast) { |
| 1467 | addClass([document.documentElement, document.body], swalClasses['toast-shown']); |
| 1468 | addClass(popup, swalClasses.toast); |
| 1469 | } else { |
| 1470 | addClass(popup, swalClasses.modal); |
| 1471 | } // Custom class |
| 1472 | |
| 1473 | |
| 1474 | applyCustomClass(popup, params, 'popup'); |
| 1475 | |
| 1476 | if (typeof params.customClass === 'string') { |
| 1477 | addClass(popup, params.customClass); |
| 1478 | } // Icon class (#1842) |
| 1479 | |
| 1480 | |
| 1481 | if (params.icon) { |
| 1482 | addClass(popup, swalClasses["icon-".concat(params.icon)]); |
| 1483 | } |
| 1484 | }; |
| 1485 | |
| 1486 | var render = function render(instance, params) { |
| 1487 | renderPopup(instance, params); |
| 1488 | renderContainer(instance, params); |
| 1489 | renderHeader(instance, params); |
| 1490 | renderContent(instance, params); |
| 1491 | renderActions(instance, params); |
| 1492 | renderFooter(instance, params); |
| 1493 | |
| 1494 | if (typeof params.didRender === 'function') { |
| 1495 | params.didRender(getPopup()); |
| 1496 | } else if (typeof params.onRender === 'function') { |
| 1497 | params.onRender(getPopup()); // @deprecated |
| 1498 | } |
| 1499 | }; |
| 1500 | |
| 1501 | /* |
| 1502 | * Global function to determine if SweetAlert2 popup is shown |
| 1503 | */ |
| 1504 | |
| 1505 | var isVisible$1 = function isVisible$$1() { |
| 1506 | return isVisible(getPopup()); |
| 1507 | }; |
| 1508 | /* |
| 1509 | * Global function to click 'Confirm' button |
| 1510 | */ |
| 1511 | |
| 1512 | var clickConfirm = function clickConfirm() { |
| 1513 | return getConfirmButton() && getConfirmButton().click(); |
| 1514 | }; |
| 1515 | /* |
| 1516 | * Global function to click 'Deny' button |
| 1517 | */ |
| 1518 | |
| 1519 | var clickDeny = function clickDeny() { |
| 1520 | return getDenyButton() && getDenyButton().click(); |
| 1521 | }; |
| 1522 | /* |
| 1523 | * Global function to click 'Cancel' button |
| 1524 | */ |
| 1525 | |
| 1526 | var clickCancel = function clickCancel() { |
| 1527 | return getCancelButton() && getCancelButton().click(); |
| 1528 | }; |
| 1529 | |
| 1530 | function fire() { |
| 1531 | var Swal = this; |
| 1532 | |
| 1533 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { |
| 1534 | args[_key] = arguments[_key]; |
| 1535 | } |
| 1536 | |
| 1537 | return _construct(Swal, args); |
| 1538 | } |
| 1539 | |
| 1540 | /** |
| 1541 | * Returns an extended version of `Swal` containing `params` as defaults. |
| 1542 | * Useful for reusing Swal configuration. |
| 1543 | * |
| 1544 | * For example: |
| 1545 | * |
| 1546 | * Before: |
| 1547 | * const textPromptOptions = { input: 'text', showCancelButton: true } |
| 1548 | * const {value: firstName} = await Swal.fire({ ...textPromptOptions, title: 'What is your first name?' }) |
| 1549 | * const {value: lastName} = await Swal.fire({ ...textPromptOptions, title: 'What is your last name?' }) |
| 1550 | * |
| 1551 | * After: |
| 1552 | * const TextPrompt = Swal.mixin({ input: 'text', showCancelButton: true }) |
| 1553 | * const {value: firstName} = await TextPrompt('What is your first name?') |
| 1554 | * const {value: lastName} = await TextPrompt('What is your last name?') |
| 1555 | * |
| 1556 | * @param mixinParams |
| 1557 | */ |
| 1558 | function mixin(mixinParams) { |
| 1559 | var MixinSwal = /*#__PURE__*/function (_this) { |
| 1560 | _inherits(MixinSwal, _this); |
| 1561 | |
| 1562 | var _super = _createSuper(MixinSwal); |
| 1563 | |
| 1564 | function MixinSwal() { |
| 1565 | _classCallCheck(this, MixinSwal); |
| 1566 | |
| 1567 | return _super.apply(this, arguments); |
| 1568 | } |
| 1569 | |
| 1570 | _createClass(MixinSwal, [{ |
| 1571 | key: "_main", |
| 1572 | value: function _main(params, priorityMixinParams) { |
| 1573 | return _get(_getPrototypeOf(MixinSwal.prototype), "_main", this).call(this, params, _extends({}, mixinParams, priorityMixinParams)); |
| 1574 | } |
| 1575 | }]); |
| 1576 | |
| 1577 | return MixinSwal; |
| 1578 | }(this); |
| 1579 | |
| 1580 | return MixinSwal; |
| 1581 | } |
| 1582 | |
| 1583 | /** |
| 1584 | * Shows loader (spinner), this is useful with AJAX requests. |
| 1585 | * By default the loader be shown instead of the "Confirm" button. |
| 1586 | */ |
| 1587 | |
| 1588 | var showLoading = function showLoading(buttonToReplace) { |
| 1589 | var popup = getPopup(); |
| 1590 | |
| 1591 | if (!popup) { |
| 1592 | Swal.fire(); |
| 1593 | } |
| 1594 | |
| 1595 | popup = getPopup(); |
| 1596 | var actions = getActions(); |
| 1597 | var loader = getLoader(); |
| 1598 | |
| 1599 | if (!buttonToReplace && isVisible(getConfirmButton())) { |
| 1600 | buttonToReplace = getConfirmButton(); |
| 1601 | } |
| 1602 | |
| 1603 | show(actions); |
| 1604 | |
| 1605 | if (buttonToReplace) { |
| 1606 | hide(buttonToReplace); |
| 1607 | loader.setAttribute('data-button-to-replace', buttonToReplace.className); |
| 1608 | } |
| 1609 | |
| 1610 | loader.parentNode.insertBefore(loader, buttonToReplace); |
| 1611 | addClass([popup, actions], swalClasses.loading); |
| 1612 | show(loader); |
| 1613 | popup.setAttribute('data-loading', true); |
| 1614 | popup.setAttribute('aria-busy', true); |
| 1615 | popup.focus(); |
| 1616 | }; |
| 1617 | |
| 1618 | var RESTORE_FOCUS_TIMEOUT = 100; |
| 1619 | |
| 1620 | var globalState = {}; |
| 1621 | |
| 1622 | var focusPreviousActiveElement = function focusPreviousActiveElement() { |
| 1623 | if (globalState.previousActiveElement && globalState.previousActiveElement.focus) { |
| 1624 | globalState.previousActiveElement.focus(); |
| 1625 | globalState.previousActiveElement = null; |
| 1626 | } else if (document.body) { |
| 1627 | document.body.focus(); |
| 1628 | } |
| 1629 | }; // Restore previous active (focused) element |
| 1630 | |
| 1631 | |
| 1632 | var restoreActiveElement = function restoreActiveElement(returnFocus) { |
| 1633 | return new Promise(function (resolve) { |
| 1634 | if (!returnFocus) { |
| 1635 | return resolve(); |
| 1636 | } |
| 1637 | |
| 1638 | var x = window.scrollX; |
| 1639 | var y = window.scrollY; |
| 1640 | globalState.restoreFocusTimeout = setTimeout(function () { |
| 1641 | focusPreviousActiveElement(); |
| 1642 | resolve(); |
| 1643 | }, RESTORE_FOCUS_TIMEOUT); // issues/900 |
| 1644 | |
| 1645 | if (typeof x !== 'undefined' && typeof y !== 'undefined') { |
| 1646 | // IE doesn't have scrollX/scrollY support |
| 1647 | window.scrollTo(x, y); |
| 1648 | } |
| 1649 | }); |
| 1650 | }; |
| 1651 | |
| 1652 | /** |
| 1653 | * If `timer` parameter is set, returns number of milliseconds of timer remained. |
| 1654 | * Otherwise, returns undefined. |
| 1655 | */ |
| 1656 | |
| 1657 | var getTimerLeft = function getTimerLeft() { |
| 1658 | return globalState.timeout && globalState.timeout.getTimerLeft(); |
| 1659 | }; |
| 1660 | /** |
| 1661 | * Stop timer. Returns number of milliseconds of timer remained. |
| 1662 | * If `timer` parameter isn't set, returns undefined. |
| 1663 | */ |
| 1664 | |
| 1665 | var stopTimer = function stopTimer() { |
| 1666 | if (globalState.timeout) { |
| 1667 | stopTimerProgressBar(); |
| 1668 | return globalState.timeout.stop(); |
| 1669 | } |
| 1670 | }; |
| 1671 | /** |
| 1672 | * Resume timer. Returns number of milliseconds of timer remained. |
| 1673 | * If `timer` parameter isn't set, returns undefined. |
| 1674 | */ |
| 1675 | |
| 1676 | var resumeTimer = function resumeTimer() { |
| 1677 | if (globalState.timeout) { |
| 1678 | var remaining = globalState.timeout.start(); |
| 1679 | animateTimerProgressBar(remaining); |
| 1680 | return remaining; |
| 1681 | } |
| 1682 | }; |
| 1683 | /** |
| 1684 | * Resume timer. Returns number of milliseconds of timer remained. |
| 1685 | * If `timer` parameter isn't set, returns undefined. |
| 1686 | */ |
| 1687 | |
| 1688 | var toggleTimer = function toggleTimer() { |
| 1689 | var timer = globalState.timeout; |
| 1690 | return timer && (timer.running ? stopTimer() : resumeTimer()); |
| 1691 | }; |
| 1692 | /** |
| 1693 | * Increase timer. Returns number of milliseconds of an updated timer. |
| 1694 | * If `timer` parameter isn't set, returns undefined. |
| 1695 | */ |
| 1696 | |
| 1697 | var increaseTimer = function increaseTimer(n) { |
| 1698 | if (globalState.timeout) { |
| 1699 | var remaining = globalState.timeout.increase(n); |
| 1700 | animateTimerProgressBar(remaining, true); |
| 1701 | return remaining; |
| 1702 | } |
| 1703 | }; |
| 1704 | /** |
| 1705 | * Check if timer is running. Returns true if timer is running |
| 1706 | * or false if timer is paused or stopped. |
| 1707 | * If `timer` parameter isn't set, returns undefined |
| 1708 | */ |
| 1709 | |
| 1710 | var isTimerRunning = function isTimerRunning() { |
| 1711 | return globalState.timeout && globalState.timeout.isRunning(); |
| 1712 | }; |
| 1713 | |
| 1714 | var bodyClickListenerAdded = false; |
| 1715 | var clickHandlers = {}; |
| 1716 | function bindClickHandler() { |
| 1717 | var attr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'data-swal-template'; |
| 1718 | clickHandlers[attr] = this; |
| 1719 | |
| 1720 | if (!bodyClickListenerAdded) { |
| 1721 | document.body.addEventListener('click', bodyClickListener); |
| 1722 | bodyClickListenerAdded = true; |
| 1723 | } |
| 1724 | } |
| 1725 | |
| 1726 | var bodyClickListener = function bodyClickListener(event) { |
| 1727 | // 1. using .parentNode instead of event.path because of better support by old browsers https://stackoverflow.com/a/39245638 |
| 1728 | // 2. using .parentNode instead of .parentElement because of IE11 + SVG https://stackoverflow.com/a/36270354 |
| 1729 | for (var el = event.target; el && el !== document; el = el.parentNode) { |
| 1730 | for (var attr in clickHandlers) { |
| 1731 | var template = el.getAttribute(attr); |
| 1732 | |
| 1733 | if (template) { |
| 1734 | clickHandlers[attr].fire({ |
| 1735 | template: template |
| 1736 | }); |
| 1737 | return; |
| 1738 | } |
| 1739 | } |
| 1740 | } |
| 1741 | }; |
| 1742 | |
| 1743 | var defaultParams = { |
| 1744 | title: '', |
| 1745 | titleText: '', |
| 1746 | text: '', |
| 1747 | html: '', |
| 1748 | footer: '', |
| 1749 | icon: undefined, |
| 1750 | iconColor: undefined, |
| 1751 | iconHtml: undefined, |
| 1752 | template: undefined, |
| 1753 | toast: false, |
| 1754 | animation: true, |
| 1755 | showClass: { |
| 1756 | popup: 'swal2-show', |
| 1757 | backdrop: 'swal2-backdrop-show', |
| 1758 | icon: 'swal2-icon-show' |
| 1759 | }, |
| 1760 | hideClass: { |
| 1761 | popup: 'swal2-hide', |
| 1762 | backdrop: 'swal2-backdrop-hide', |
| 1763 | icon: 'swal2-icon-hide' |
| 1764 | }, |
| 1765 | customClass: {}, |
| 1766 | target: 'body', |
| 1767 | backdrop: true, |
| 1768 | heightAuto: true, |
| 1769 | allowOutsideClick: true, |
| 1770 | allowEscapeKey: true, |
| 1771 | allowEnterKey: true, |
| 1772 | stopKeydownPropagation: true, |
| 1773 | keydownListenerCapture: false, |
| 1774 | showConfirmButton: true, |
| 1775 | showDenyButton: false, |
| 1776 | showCancelButton: false, |
| 1777 | preConfirm: undefined, |
| 1778 | preDeny: undefined, |
| 1779 | confirmButtonText: 'OK', |
| 1780 | confirmButtonAriaLabel: '', |
| 1781 | confirmButtonColor: undefined, |
| 1782 | denyButtonText: 'No', |
| 1783 | denyButtonAriaLabel: '', |
| 1784 | denyButtonColor: undefined, |
| 1785 | cancelButtonText: 'Cancel', |
| 1786 | cancelButtonAriaLabel: '', |
| 1787 | cancelButtonColor: undefined, |
| 1788 | buttonsStyling: true, |
| 1789 | reverseButtons: false, |
| 1790 | focusConfirm: true, |
| 1791 | focusDeny: false, |
| 1792 | focusCancel: false, |
| 1793 | returnFocus: true, |
| 1794 | showCloseButton: false, |
| 1795 | closeButtonHtml: '×', |
| 1796 | closeButtonAriaLabel: 'Close this dialog', |
| 1797 | loaderHtml: '', |
| 1798 | showLoaderOnConfirm: false, |
| 1799 | showLoaderOnDeny: false, |
| 1800 | imageUrl: undefined, |
| 1801 | imageWidth: undefined, |
| 1802 | imageHeight: undefined, |
| 1803 | imageAlt: '', |
| 1804 | timer: undefined, |
| 1805 | timerProgressBar: false, |
| 1806 | width: undefined, |
| 1807 | padding: undefined, |
| 1808 | background: undefined, |
| 1809 | input: undefined, |
| 1810 | inputPlaceholder: '', |
| 1811 | inputLabel: '', |
| 1812 | inputValue: '', |
| 1813 | inputOptions: {}, |
| 1814 | inputAutoTrim: true, |
| 1815 | inputAttributes: {}, |
| 1816 | inputValidator: undefined, |
| 1817 | returnInputValueOnDeny: false, |
| 1818 | validationMessage: undefined, |
| 1819 | grow: false, |
| 1820 | position: 'center', |
| 1821 | progressSteps: [], |
| 1822 | currentProgressStep: undefined, |
| 1823 | progressStepsDistance: undefined, |
| 1824 | onBeforeOpen: undefined, |
| 1825 | onOpen: undefined, |
| 1826 | willOpen: undefined, |
| 1827 | didOpen: undefined, |
| 1828 | onRender: undefined, |
| 1829 | didRender: undefined, |
| 1830 | onClose: undefined, |
| 1831 | onAfterClose: undefined, |
| 1832 | willClose: undefined, |
| 1833 | didClose: undefined, |
| 1834 | onDestroy: undefined, |
| 1835 | didDestroy: undefined, |
| 1836 | scrollbarPadding: true |
| 1837 | }; |
| 1838 | 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', 'returnFocus', 'reverseButtons', 'showCancelButton', 'showCloseButton', 'showConfirmButton', 'showDenyButton', 'text', 'title', 'titleText', 'willClose']; |
| 1839 | var deprecatedParams = { |
| 1840 | animation: 'showClass" and "hideClass', |
| 1841 | onBeforeOpen: 'willOpen', |
| 1842 | onOpen: 'didOpen', |
| 1843 | onRender: 'didRender', |
| 1844 | onClose: 'willClose', |
| 1845 | onAfterClose: 'didClose', |
| 1846 | onDestroy: 'didDestroy' |
| 1847 | }; |
| 1848 | var toastIncompatibleParams = ['allowOutsideClick', 'allowEnterKey', 'backdrop', 'focusConfirm', 'focusDeny', 'focusCancel', 'returnFocus', 'heightAuto', 'keydownListenerCapture']; |
| 1849 | /** |
| 1850 | * Is valid parameter |
| 1851 | * @param {String} paramName |
| 1852 | */ |
| 1853 | |
| 1854 | var isValidParameter = function isValidParameter(paramName) { |
| 1855 | return Object.prototype.hasOwnProperty.call(defaultParams, paramName); |
| 1856 | }; |
| 1857 | /** |
| 1858 | * Is valid parameter for Swal.update() method |
| 1859 | * @param {String} paramName |
| 1860 | */ |
| 1861 | |
| 1862 | var isUpdatableParameter = function isUpdatableParameter(paramName) { |
| 1863 | return updatableParams.indexOf(paramName) !== -1; |
| 1864 | }; |
| 1865 | /** |
| 1866 | * Is deprecated parameter |
| 1867 | * @param {String} paramName |
| 1868 | */ |
| 1869 | |
| 1870 | var isDeprecatedParameter = function isDeprecatedParameter(paramName) { |
| 1871 | return deprecatedParams[paramName]; |
| 1872 | }; |
| 1873 | |
| 1874 | var checkIfParamIsValid = function checkIfParamIsValid(param) { |
| 1875 | if (!isValidParameter(param)) { |
| 1876 | warn("Unknown parameter \"".concat(param, "\"")); |
| 1877 | } |
| 1878 | }; |
| 1879 | |
| 1880 | var checkIfToastParamIsValid = function checkIfToastParamIsValid(param) { |
| 1881 | if (toastIncompatibleParams.indexOf(param) !== -1) { |
| 1882 | warn("The parameter \"".concat(param, "\" is incompatible with toasts")); |
| 1883 | } |
| 1884 | }; |
| 1885 | |
| 1886 | var checkIfParamIsDeprecated = function checkIfParamIsDeprecated(param) { |
| 1887 | if (isDeprecatedParameter(param)) { |
| 1888 | warnAboutDeprecation(param, isDeprecatedParameter(param)); |
| 1889 | } |
| 1890 | }; |
| 1891 | /** |
| 1892 | * Show relevant warnings for given params |
| 1893 | * |
| 1894 | * @param params |
| 1895 | */ |
| 1896 | |
| 1897 | |
| 1898 | var showWarningsForParams = function showWarningsForParams(params) { |
| 1899 | for (var param in params) { |
| 1900 | checkIfParamIsValid(param); |
| 1901 | |
| 1902 | if (params.toast) { |
| 1903 | checkIfToastParamIsValid(param); |
| 1904 | } |
| 1905 | |
| 1906 | checkIfParamIsDeprecated(param); |
| 1907 | } |
| 1908 | }; |
| 1909 | |
| 1910 | |
| 1911 | |
| 1912 | var staticMethods = /*#__PURE__*/Object.freeze({ |
| 1913 | isValidParameter: isValidParameter, |
| 1914 | isUpdatableParameter: isUpdatableParameter, |
| 1915 | isDeprecatedParameter: isDeprecatedParameter, |
| 1916 | argsToParams: argsToParams, |
| 1917 | isVisible: isVisible$1, |
| 1918 | clickConfirm: clickConfirm, |
| 1919 | clickDeny: clickDeny, |
| 1920 | clickCancel: clickCancel, |
| 1921 | getContainer: getContainer, |
| 1922 | getPopup: getPopup, |
| 1923 | getTitle: getTitle, |
| 1924 | getContent: getContent, |
| 1925 | getHtmlContainer: getHtmlContainer, |
| 1926 | getImage: getImage, |
| 1927 | getIcon: getIcon, |
| 1928 | getInputLabel: getInputLabel, |
| 1929 | getCloseButton: getCloseButton, |
| 1930 | getActions: getActions, |
| 1931 | getConfirmButton: getConfirmButton, |
| 1932 | getDenyButton: getDenyButton, |
| 1933 | getCancelButton: getCancelButton, |
| 1934 | getLoader: getLoader, |
| 1935 | getHeader: getHeader, |
| 1936 | getFooter: getFooter, |
| 1937 | getTimerProgressBar: getTimerProgressBar, |
| 1938 | getFocusableElements: getFocusableElements, |
| 1939 | getValidationMessage: getValidationMessage, |
| 1940 | isLoading: isLoading, |
| 1941 | fire: fire, |
| 1942 | mixin: mixin, |
| 1943 | queue: queue, |
| 1944 | getQueueStep: getQueueStep, |
| 1945 | insertQueueStep: insertQueueStep, |
| 1946 | deleteQueueStep: deleteQueueStep, |
| 1947 | showLoading: showLoading, |
| 1948 | enableLoading: showLoading, |
| 1949 | getTimerLeft: getTimerLeft, |
| 1950 | stopTimer: stopTimer, |
| 1951 | resumeTimer: resumeTimer, |
| 1952 | toggleTimer: toggleTimer, |
| 1953 | increaseTimer: increaseTimer, |
| 1954 | isTimerRunning: isTimerRunning, |
| 1955 | bindClickHandler: bindClickHandler |
| 1956 | }); |
| 1957 | |
| 1958 | /** |
| 1959 | * Hides loader and shows back the button which was hidden by .showLoading() |
| 1960 | */ |
| 1961 | |
| 1962 | function hideLoading() { |
| 1963 | // do nothing if popup is closed |
| 1964 | var innerParams = privateProps.innerParams.get(this); |
| 1965 | |
| 1966 | if (!innerParams) { |
| 1967 | return; |
| 1968 | } |
| 1969 | |
| 1970 | var domCache = privateProps.domCache.get(this); |
| 1971 | hide(domCache.loader); |
| 1972 | var buttonToReplace = domCache.popup.getElementsByClassName(domCache.loader.getAttribute('data-button-to-replace')); |
| 1973 | |
| 1974 | if (buttonToReplace.length) { |
| 1975 | show(buttonToReplace[0], 'inline-block'); |
| 1976 | } else if (allButtonsAreHidden()) { |
| 1977 | hide(domCache.actions); |
| 1978 | } |
| 1979 | |
| 1980 | removeClass([domCache.popup, domCache.actions], swalClasses.loading); |
| 1981 | domCache.popup.removeAttribute('aria-busy'); |
| 1982 | domCache.popup.removeAttribute('data-loading'); |
| 1983 | domCache.confirmButton.disabled = false; |
| 1984 | domCache.denyButton.disabled = false; |
| 1985 | domCache.cancelButton.disabled = false; |
| 1986 | } |
| 1987 | |
| 1988 | function getInput$1(instance) { |
| 1989 | var innerParams = privateProps.innerParams.get(instance || this); |
| 1990 | var domCache = privateProps.domCache.get(instance || this); |
| 1991 | |
| 1992 | if (!domCache) { |
| 1993 | return null; |
| 1994 | } |
| 1995 | |
| 1996 | return getInput(domCache.content, innerParams.input); |
| 1997 | } |
| 1998 | |
| 1999 | var fixScrollbar = function fixScrollbar() { |
| 2000 | // for queues, do not do this more than once |
| 2001 | if (states.previousBodyPadding !== null) { |
| 2002 | return; |
| 2003 | } // if the body has overflow |
| 2004 | |
| 2005 | |
| 2006 | if (document.body.scrollHeight > window.innerHeight) { |
| 2007 | // add padding so the content doesn't shift after removal of scrollbar |
| 2008 | states.previousBodyPadding = parseInt(window.getComputedStyle(document.body).getPropertyValue('padding-right')); |
| 2009 | document.body.style.paddingRight = "".concat(states.previousBodyPadding + measureScrollbar(), "px"); |
| 2010 | } |
| 2011 | }; |
| 2012 | var undoScrollbar = function undoScrollbar() { |
| 2013 | if (states.previousBodyPadding !== null) { |
| 2014 | document.body.style.paddingRight = "".concat(states.previousBodyPadding, "px"); |
| 2015 | states.previousBodyPadding = null; |
| 2016 | } |
| 2017 | }; |
| 2018 | |
| 2019 | /* istanbul ignore file */ |
| 2020 | |
| 2021 | var iOSfix = function iOSfix() { |
| 2022 | var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream || navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1; |
| 2023 | |
| 2024 | if (iOS && !hasClass(document.body, swalClasses.iosfix)) { |
| 2025 | var offset = document.body.scrollTop; |
| 2026 | document.body.style.top = "".concat(offset * -1, "px"); |
| 2027 | addClass(document.body, swalClasses.iosfix); |
| 2028 | lockBodyScroll(); |
| 2029 | addBottomPaddingForTallPopups(); // #1948 |
| 2030 | } |
| 2031 | }; |
| 2032 | |
| 2033 | var addBottomPaddingForTallPopups = function addBottomPaddingForTallPopups() { |
| 2034 | var safari = !navigator.userAgent.match(/(CriOS|FxiOS|EdgiOS|YaBrowser|UCBrowser)/i); |
| 2035 | |
| 2036 | if (safari) { |
| 2037 | var bottomPanelHeight = 44; |
| 2038 | |
| 2039 | if (getPopup().scrollHeight > window.innerHeight - bottomPanelHeight) { |
| 2040 | getContainer().style.paddingBottom = "".concat(bottomPanelHeight, "px"); |
| 2041 | } |
| 2042 | } |
| 2043 | }; |
| 2044 | |
| 2045 | var lockBodyScroll = function lockBodyScroll() { |
| 2046 | // #1246 |
| 2047 | var container = getContainer(); |
| 2048 | var preventTouchMove; |
| 2049 | |
| 2050 | container.ontouchstart = function (e) { |
| 2051 | preventTouchMove = shouldPreventTouchMove(e); |
| 2052 | }; |
| 2053 | |
| 2054 | container.ontouchmove = function (e) { |
| 2055 | if (preventTouchMove) { |
| 2056 | e.preventDefault(); |
| 2057 | e.stopPropagation(); |
| 2058 | } |
| 2059 | }; |
| 2060 | }; |
| 2061 | |
| 2062 | var shouldPreventTouchMove = function shouldPreventTouchMove(event) { |
| 2063 | var target = event.target; |
| 2064 | var container = getContainer(); |
| 2065 | |
| 2066 | if (isStylys(event) || isZoom(event)) { |
| 2067 | return false; |
| 2068 | } |
| 2069 | |
| 2070 | if (target === container) { |
| 2071 | return true; |
| 2072 | } |
| 2073 | |
| 2074 | if (!isScrollable(container) && target.tagName !== 'INPUT' && // #1603 |
| 2075 | !(isScrollable(getContent()) && // #1944 |
| 2076 | getContent().contains(target))) { |
| 2077 | return true; |
| 2078 | } |
| 2079 | |
| 2080 | return false; |
| 2081 | }; |
| 2082 | |
| 2083 | var isStylys = function isStylys(event) { |
| 2084 | // #1786 |
| 2085 | return event.touches && event.touches.length && event.touches[0].touchType === 'stylus'; |
| 2086 | }; |
| 2087 | |
| 2088 | var isZoom = function isZoom(event) { |
| 2089 | // #1891 |
| 2090 | return event.touches && event.touches.length > 1; |
| 2091 | }; |
| 2092 | |
| 2093 | var undoIOSfix = function undoIOSfix() { |
| 2094 | if (hasClass(document.body, swalClasses.iosfix)) { |
| 2095 | var offset = parseInt(document.body.style.top, 10); |
| 2096 | removeClass(document.body, swalClasses.iosfix); |
| 2097 | document.body.style.top = ''; |
| 2098 | document.body.scrollTop = offset * -1; |
| 2099 | } |
| 2100 | }; |
| 2101 | |
| 2102 | /* istanbul ignore file */ |
| 2103 | |
| 2104 | var isIE11 = function isIE11() { |
| 2105 | return !!window.MSInputMethodContext && !!document.documentMode; |
| 2106 | }; // Fix IE11 centering sweetalert2/issues/933 |
| 2107 | |
| 2108 | |
| 2109 | var fixVerticalPositionIE = function fixVerticalPositionIE() { |
| 2110 | var container = getContainer(); |
| 2111 | var popup = getPopup(); |
| 2112 | container.style.removeProperty('align-items'); |
| 2113 | |
| 2114 | if (popup.offsetTop < 0) { |
| 2115 | container.style.alignItems = 'flex-start'; |
| 2116 | } |
| 2117 | }; |
| 2118 | |
| 2119 | var IEfix = function IEfix() { |
| 2120 | if (typeof window !== 'undefined' && isIE11()) { |
| 2121 | fixVerticalPositionIE(); |
| 2122 | window.addEventListener('resize', fixVerticalPositionIE); |
| 2123 | } |
| 2124 | }; |
| 2125 | var undoIEfix = function undoIEfix() { |
| 2126 | if (typeof window !== 'undefined' && isIE11()) { |
| 2127 | window.removeEventListener('resize', fixVerticalPositionIE); |
| 2128 | } |
| 2129 | }; |
| 2130 | |
| 2131 | // Adding aria-hidden="true" to elements outside of the active modal dialog ensures that |
| 2132 | // elements not within the active modal dialog will not be surfaced if a user opens a screen |
| 2133 | // reader’s list of elements (headings, form controls, landmarks, etc.) in the document. |
| 2134 | |
| 2135 | var setAriaHidden = function setAriaHidden() { |
| 2136 | var bodyChildren = toArray(document.body.children); |
| 2137 | bodyChildren.forEach(function (el) { |
| 2138 | if (el === getContainer() || contains(el, getContainer())) { |
| 2139 | return; |
| 2140 | } |
| 2141 | |
| 2142 | if (el.hasAttribute('aria-hidden')) { |
| 2143 | el.setAttribute('data-previous-aria-hidden', el.getAttribute('aria-hidden')); |
| 2144 | } |
| 2145 | |
| 2146 | el.setAttribute('aria-hidden', 'true'); |
| 2147 | }); |
| 2148 | }; |
| 2149 | var unsetAriaHidden = function unsetAriaHidden() { |
| 2150 | var bodyChildren = toArray(document.body.children); |
| 2151 | bodyChildren.forEach(function (el) { |
| 2152 | if (el.hasAttribute('data-previous-aria-hidden')) { |
| 2153 | el.setAttribute('aria-hidden', el.getAttribute('data-previous-aria-hidden')); |
| 2154 | el.removeAttribute('data-previous-aria-hidden'); |
| 2155 | } else { |
| 2156 | el.removeAttribute('aria-hidden'); |
| 2157 | } |
| 2158 | }); |
| 2159 | }; |
| 2160 | |
| 2161 | /** |
| 2162 | * This module containts `WeakMap`s for each effectively-"private property" that a `Swal` has. |
| 2163 | * For example, to set the private property "foo" of `this` to "bar", you can `privateProps.foo.set(this, 'bar')` |
| 2164 | * This is the approach that Babel will probably take to implement private methods/fields |
| 2165 | * https://github.com/tc39/proposal-private-methods |
| 2166 | * https://github.com/babel/babel/pull/7555 |
| 2167 | * Once we have the changes from that PR in Babel, and our core class fits reasonable in *one module* |
| 2168 | * then we can use that language feature. |
| 2169 | */ |
| 2170 | var privateMethods = { |
| 2171 | swalPromiseResolve: new WeakMap() |
| 2172 | }; |
| 2173 | |
| 2174 | /* |
| 2175 | * Instance method to close sweetAlert |
| 2176 | */ |
| 2177 | |
| 2178 | function removePopupAndResetState(instance, container, returnFocus, didClose) { |
| 2179 | if (isToast()) { |
| 2180 | triggerDidCloseAndDispose(instance, didClose); |
| 2181 | } else { |
| 2182 | restoreActiveElement(returnFocus).then(function () { |
| 2183 | return triggerDidCloseAndDispose(instance, didClose); |
| 2184 | }); |
| 2185 | globalState.keydownTarget.removeEventListener('keydown', globalState.keydownHandler, { |
| 2186 | capture: globalState.keydownListenerCapture |
| 2187 | }); |
| 2188 | globalState.keydownHandlerAdded = false; |
| 2189 | } |
| 2190 | |
| 2191 | if (container.parentNode && !document.body.getAttribute('data-swal2-queue-step')) { |
| 2192 | container.parentNode.removeChild(container); |
| 2193 | } |
| 2194 | |
| 2195 | if (isModal()) { |
| 2196 | undoScrollbar(); |
| 2197 | undoIOSfix(); |
| 2198 | undoIEfix(); |
| 2199 | unsetAriaHidden(); |
| 2200 | } |
| 2201 | |
| 2202 | removeBodyClasses(); |
| 2203 | } |
| 2204 | |
| 2205 | function removeBodyClasses() { |
| 2206 | removeClass([document.documentElement, document.body], [swalClasses.shown, swalClasses['height-auto'], swalClasses['no-backdrop'], swalClasses['toast-shown']]); |
| 2207 | } |
| 2208 | |
| 2209 | function close(resolveValue) { |
| 2210 | var popup = getPopup(); |
| 2211 | |
| 2212 | if (!popup) { |
| 2213 | return; |
| 2214 | } |
| 2215 | |
| 2216 | resolveValue = prepareResolveValue(resolveValue); |
| 2217 | var innerParams = privateProps.innerParams.get(this); |
| 2218 | |
| 2219 | if (!innerParams || hasClass(popup, innerParams.hideClass.popup)) { |
| 2220 | return; |
| 2221 | } |
| 2222 | |
| 2223 | var swalPromiseResolve = privateMethods.swalPromiseResolve.get(this); |
| 2224 | removeClass(popup, innerParams.showClass.popup); |
| 2225 | addClass(popup, innerParams.hideClass.popup); |
| 2226 | var backdrop = getContainer(); |
| 2227 | removeClass(backdrop, innerParams.showClass.backdrop); |
| 2228 | addClass(backdrop, innerParams.hideClass.backdrop); |
| 2229 | handlePopupAnimation(this, popup, innerParams); // Resolve Swal promise |
| 2230 | |
| 2231 | swalPromiseResolve(resolveValue); |
| 2232 | } |
| 2233 | |
| 2234 | var prepareResolveValue = function prepareResolveValue(resolveValue) { |
| 2235 | // When user calls Swal.close() |
| 2236 | if (typeof resolveValue === 'undefined') { |
| 2237 | return { |
| 2238 | isConfirmed: false, |
| 2239 | isDenied: false, |
| 2240 | isDismissed: true |
| 2241 | }; |
| 2242 | } |
| 2243 | |
| 2244 | return _extends({ |
| 2245 | isConfirmed: false, |
| 2246 | isDenied: false, |
| 2247 | isDismissed: false |
| 2248 | }, resolveValue); |
| 2249 | }; |
| 2250 | |
| 2251 | var handlePopupAnimation = function handlePopupAnimation(instance, popup, innerParams) { |
| 2252 | var container = getContainer(); // If animation is supported, animate |
| 2253 | |
| 2254 | var animationIsSupported = animationEndEvent && hasCssAnimation(popup); |
| 2255 | var onClose = innerParams.onClose, |
| 2256 | onAfterClose = innerParams.onAfterClose, |
| 2257 | willClose = innerParams.willClose, |
| 2258 | didClose = innerParams.didClose; |
| 2259 | runDidClose(popup, willClose, onClose); |
| 2260 | |
| 2261 | if (animationIsSupported) { |
| 2262 | animatePopup(instance, popup, container, innerParams.returnFocus, didClose || onAfterClose); |
| 2263 | } else { |
| 2264 | // Otherwise, remove immediately |
| 2265 | removePopupAndResetState(instance, container, innerParams.returnFocus, didClose || onAfterClose); |
| 2266 | } |
| 2267 | }; |
| 2268 | |
| 2269 | var runDidClose = function runDidClose(popup, willClose, onClose) { |
| 2270 | if (willClose !== null && typeof willClose === 'function') { |
| 2271 | willClose(popup); |
| 2272 | } else if (onClose !== null && typeof onClose === 'function') { |
| 2273 | onClose(popup); // @deprecated |
| 2274 | } |
| 2275 | }; |
| 2276 | |
| 2277 | var animatePopup = function animatePopup(instance, popup, container, returnFocus, didClose) { |
| 2278 | globalState.swalCloseEventFinishedCallback = removePopupAndResetState.bind(null, instance, container, returnFocus, didClose); |
| 2279 | popup.addEventListener(animationEndEvent, function (e) { |
| 2280 | if (e.target === popup) { |
| 2281 | globalState.swalCloseEventFinishedCallback(); |
| 2282 | delete globalState.swalCloseEventFinishedCallback; |
| 2283 | } |
| 2284 | }); |
| 2285 | }; |
| 2286 | |
| 2287 | var triggerDidCloseAndDispose = function triggerDidCloseAndDispose(instance, didClose) { |
| 2288 | setTimeout(function () { |
| 2289 | if (typeof didClose === 'function') { |
| 2290 | didClose(); |
| 2291 | } |
| 2292 | |
| 2293 | instance._destroy(); |
| 2294 | }); |
| 2295 | }; |
| 2296 | |
| 2297 | function setButtonsDisabled(instance, buttons, disabled) { |
| 2298 | var domCache = privateProps.domCache.get(instance); |
| 2299 | buttons.forEach(function (button) { |
| 2300 | domCache[button].disabled = disabled; |
| 2301 | }); |
| 2302 | } |
| 2303 | |
| 2304 | function setInputDisabled(input, disabled) { |
| 2305 | if (!input) { |
| 2306 | return false; |
| 2307 | } |
| 2308 | |
| 2309 | if (input.type === 'radio') { |
| 2310 | var radiosContainer = input.parentNode.parentNode; |
| 2311 | var radios = radiosContainer.querySelectorAll('input'); |
| 2312 | |
| 2313 | for (var i = 0; i < radios.length; i++) { |
| 2314 | radios[i].disabled = disabled; |
| 2315 | } |
| 2316 | } else { |
| 2317 | input.disabled = disabled; |
| 2318 | } |
| 2319 | } |
| 2320 | |
| 2321 | function enableButtons() { |
| 2322 | setButtonsDisabled(this, ['confirmButton', 'denyButton', 'cancelButton'], false); |
| 2323 | } |
| 2324 | function disableButtons() { |
| 2325 | setButtonsDisabled(this, ['confirmButton', 'denyButton', 'cancelButton'], true); |
| 2326 | } |
| 2327 | function enableInput() { |
| 2328 | return setInputDisabled(this.getInput(), false); |
| 2329 | } |
| 2330 | function disableInput() { |
| 2331 | return setInputDisabled(this.getInput(), true); |
| 2332 | } |
| 2333 | |
| 2334 | function showValidationMessage(error) { |
| 2335 | var domCache = privateProps.domCache.get(this); |
| 2336 | var params = privateProps.innerParams.get(this); |
| 2337 | setInnerHtml(domCache.validationMessage, error); |
| 2338 | domCache.validationMessage.className = swalClasses['validation-message']; |
| 2339 | |
| 2340 | if (params.customClass && params.customClass.validationMessage) { |
| 2341 | addClass(domCache.validationMessage, params.customClass.validationMessage); |
| 2342 | } |
| 2343 | |
| 2344 | show(domCache.validationMessage); |
| 2345 | var input = this.getInput(); |
| 2346 | |
| 2347 | if (input) { |
| 2348 | input.setAttribute('aria-invalid', true); |
| 2349 | input.setAttribute('aria-describedBy', swalClasses['validation-message']); |
| 2350 | focusInput(input); |
| 2351 | addClass(input, swalClasses.inputerror); |
| 2352 | } |
| 2353 | } // Hide block with validation message |
| 2354 | |
| 2355 | function resetValidationMessage$1() { |
| 2356 | var domCache = privateProps.domCache.get(this); |
| 2357 | |
| 2358 | if (domCache.validationMessage) { |
| 2359 | hide(domCache.validationMessage); |
| 2360 | } |
| 2361 | |
| 2362 | var input = this.getInput(); |
| 2363 | |
| 2364 | if (input) { |
| 2365 | input.removeAttribute('aria-invalid'); |
| 2366 | input.removeAttribute('aria-describedBy'); |
| 2367 | removeClass(input, swalClasses.inputerror); |
| 2368 | } |
| 2369 | } |
| 2370 | |
| 2371 | function getProgressSteps$1() { |
| 2372 | var domCache = privateProps.domCache.get(this); |
| 2373 | return domCache.progressSteps; |
| 2374 | } |
| 2375 | |
| 2376 | var Timer = /*#__PURE__*/function () { |
| 2377 | function Timer(callback, delay) { |
| 2378 | _classCallCheck(this, Timer); |
| 2379 | |
| 2380 | this.callback = callback; |
| 2381 | this.remaining = delay; |
| 2382 | this.running = false; |
| 2383 | this.start(); |
| 2384 | } |
| 2385 | |
| 2386 | _createClass(Timer, [{ |
| 2387 | key: "start", |
| 2388 | value: function start() { |
| 2389 | if (!this.running) { |
| 2390 | this.running = true; |
| 2391 | this.started = new Date(); |
| 2392 | this.id = setTimeout(this.callback, this.remaining); |
| 2393 | } |
| 2394 | |
| 2395 | return this.remaining; |
| 2396 | } |
| 2397 | }, { |
| 2398 | key: "stop", |
| 2399 | value: function stop() { |
| 2400 | if (this.running) { |
| 2401 | this.running = false; |
| 2402 | clearTimeout(this.id); |
| 2403 | this.remaining -= new Date() - this.started; |
| 2404 | } |
| 2405 | |
| 2406 | return this.remaining; |
| 2407 | } |
| 2408 | }, { |
| 2409 | key: "increase", |
| 2410 | value: function increase(n) { |
| 2411 | var running = this.running; |
| 2412 | |
| 2413 | if (running) { |
| 2414 | this.stop(); |
| 2415 | } |
| 2416 | |
| 2417 | this.remaining += n; |
| 2418 | |
| 2419 | if (running) { |
| 2420 | this.start(); |
| 2421 | } |
| 2422 | |
| 2423 | return this.remaining; |
| 2424 | } |
| 2425 | }, { |
| 2426 | key: "getTimerLeft", |
| 2427 | value: function getTimerLeft() { |
| 2428 | if (this.running) { |
| 2429 | this.stop(); |
| 2430 | this.start(); |
| 2431 | } |
| 2432 | |
| 2433 | return this.remaining; |
| 2434 | } |
| 2435 | }, { |
| 2436 | key: "isRunning", |
| 2437 | value: function isRunning() { |
| 2438 | return this.running; |
| 2439 | } |
| 2440 | }]); |
| 2441 | |
| 2442 | return Timer; |
| 2443 | }(); |
| 2444 | |
| 2445 | var defaultInputValidators = { |
| 2446 | email: function email(string, validationMessage) { |
| 2447 | 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'); |
| 2448 | }, |
| 2449 | url: function url(string, validationMessage) { |
| 2450 | // taken from https://stackoverflow.com/a/3809435 with a small change from #1306 and #2013 |
| 2451 | 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'); |
| 2452 | } |
| 2453 | }; |
| 2454 | |
| 2455 | function setDefaultInputValidators(params) { |
| 2456 | // Use default `inputValidator` for supported input types if not provided |
| 2457 | if (!params.inputValidator) { |
| 2458 | Object.keys(defaultInputValidators).forEach(function (key) { |
| 2459 | if (params.input === key) { |
| 2460 | params.inputValidator = defaultInputValidators[key]; |
| 2461 | } |
| 2462 | }); |
| 2463 | } |
| 2464 | } |
| 2465 | |
| 2466 | function validateCustomTargetElement(params) { |
| 2467 | // Determine if the custom target element is valid |
| 2468 | if (!params.target || typeof params.target === 'string' && !document.querySelector(params.target) || typeof params.target !== 'string' && !params.target.appendChild) { |
| 2469 | warn('Target parameter is not valid, defaulting to "body"'); |
| 2470 | params.target = 'body'; |
| 2471 | } |
| 2472 | } |
| 2473 | /** |
| 2474 | * Set type, text and actions on popup |
| 2475 | * |
| 2476 | * @param params |
| 2477 | * @returns {boolean} |
| 2478 | */ |
| 2479 | |
| 2480 | |
| 2481 | function setParameters(params) { |
| 2482 | setDefaultInputValidators(params); // showLoaderOnConfirm && preConfirm |
| 2483 | |
| 2484 | if (params.showLoaderOnConfirm && !params.preConfirm) { |
| 2485 | 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'); |
| 2486 | } // params.animation will be actually used in renderPopup.js |
| 2487 | // but in case when params.animation is a function, we need to call that function |
| 2488 | // before popup (re)initialization, so it'll be possible to check Swal.isVisible() |
| 2489 | // inside the params.animation function |
| 2490 | |
| 2491 | |
| 2492 | params.animation = callIfFunction(params.animation); |
| 2493 | validateCustomTargetElement(params); // Replace newlines with <br> in title |
| 2494 | |
| 2495 | if (typeof params.title === 'string') { |
| 2496 | params.title = params.title.split('\n').join('<br />'); |
| 2497 | } |
| 2498 | |
| 2499 | init(params); |
| 2500 | } |
| 2501 | |
| 2502 | var swalStringParams = ['swal-title', 'swal-html', 'swal-footer']; |
| 2503 | var getTemplateParams = function getTemplateParams(params) { |
| 2504 | var template = typeof params.template === 'string' ? document.querySelector(params.template) : params.template; |
| 2505 | |
| 2506 | if (!template) { |
| 2507 | return {}; |
| 2508 | } |
| 2509 | |
| 2510 | var templateContent = template.content || template; // IE11 |
| 2511 | |
| 2512 | showWarningsForElements(templateContent); |
| 2513 | |
| 2514 | var result = _extends(getSwalParams(templateContent), getSwalButtons(templateContent), getSwalImage(templateContent), getSwalIcon(templateContent), getSwalInput(templateContent), getSwalStringParams(templateContent, swalStringParams)); |
| 2515 | |
| 2516 | return result; |
| 2517 | }; |
| 2518 | |
| 2519 | var getSwalParams = function getSwalParams(templateContent) { |
| 2520 | var result = {}; |
| 2521 | toArray(templateContent.querySelectorAll('swal-param')).forEach(function (param) { |
| 2522 | showWarningsForAttributes(param, ['name', 'value']); |
| 2523 | var paramName = param.getAttribute('name'); |
| 2524 | var value = param.getAttribute('value'); |
| 2525 | |
| 2526 | if (typeof defaultParams[paramName] === 'boolean' && value === 'false') { |
| 2527 | value = false; |
| 2528 | } |
| 2529 | |
| 2530 | if (_typeof(defaultParams[paramName]) === 'object') { |
| 2531 | value = JSON.parse(value); |
| 2532 | } |
| 2533 | |
| 2534 | result[paramName] = value; |
| 2535 | }); |
| 2536 | return result; |
| 2537 | }; |
| 2538 | |
| 2539 | var getSwalButtons = function getSwalButtons(templateContent) { |
| 2540 | var result = {}; |
| 2541 | toArray(templateContent.querySelectorAll('swal-button')).forEach(function (button) { |
| 2542 | showWarningsForAttributes(button, ['type', 'color', 'aria-label']); |
| 2543 | var type = button.getAttribute('type'); |
| 2544 | result["".concat(type, "ButtonText")] = button.innerHTML; |
| 2545 | result["show".concat(capitalizeFirstLetter(type), "Button")] = true; |
| 2546 | |
| 2547 | if (button.hasAttribute('color')) { |
| 2548 | result["".concat(type, "ButtonColor")] = button.getAttribute('color'); |
| 2549 | } |
| 2550 | |
| 2551 | if (button.hasAttribute('aria-label')) { |
| 2552 | result["".concat(type, "ButtonAriaLabel")] = button.getAttribute('aria-label'); |
| 2553 | } |
| 2554 | }); |
| 2555 | return result; |
| 2556 | }; |
| 2557 | |
| 2558 | var getSwalImage = function getSwalImage(templateContent) { |
| 2559 | var result = {}; |
| 2560 | var image = templateContent.querySelector('swal-image'); |
| 2561 | |
| 2562 | if (image) { |
| 2563 | showWarningsForAttributes(image, ['src', 'width', 'height', 'alt']); |
| 2564 | |
| 2565 | if (image.hasAttribute('src')) { |
| 2566 | result.imageUrl = image.getAttribute('src'); |
| 2567 | } |
| 2568 | |
| 2569 | if (image.hasAttribute('width')) { |
| 2570 | result.imageWidth = image.getAttribute('width'); |
| 2571 | } |
| 2572 | |
| 2573 | if (image.hasAttribute('height')) { |
| 2574 | result.imageHeight = image.getAttribute('height'); |
| 2575 | } |
| 2576 | |
| 2577 | if (image.hasAttribute('alt')) { |
| 2578 | result.imageAlt = image.getAttribute('alt'); |
| 2579 | } |
| 2580 | } |
| 2581 | |
| 2582 | return result; |
| 2583 | }; |
| 2584 | |
| 2585 | var getSwalIcon = function getSwalIcon(templateContent) { |
| 2586 | var result = {}; |
| 2587 | var icon = templateContent.querySelector('swal-icon'); |
| 2588 | |
| 2589 | if (icon) { |
| 2590 | showWarningsForAttributes(icon, ['type', 'color']); |
| 2591 | |
| 2592 | if (icon.hasAttribute('type')) { |
| 2593 | result.icon = icon.getAttribute('type'); |
| 2594 | } |
| 2595 | |
| 2596 | if (icon.hasAttribute('color')) { |
| 2597 | result.iconColor = icon.getAttribute('color'); |
| 2598 | } |
| 2599 | |
| 2600 | result.iconHtml = icon.innerHTML; |
| 2601 | } |
| 2602 | |
| 2603 | return result; |
| 2604 | }; |
| 2605 | |
| 2606 | var getSwalInput = function getSwalInput(templateContent) { |
| 2607 | var result = {}; |
| 2608 | var input = templateContent.querySelector('swal-input'); |
| 2609 | |
| 2610 | if (input) { |
| 2611 | showWarningsForAttributes(input, ['type', 'label', 'placeholder', 'value']); |
| 2612 | result.input = input.getAttribute('type') || 'text'; |
| 2613 | |
| 2614 | if (input.hasAttribute('label')) { |
| 2615 | result.inputLabel = input.getAttribute('label'); |
| 2616 | } |
| 2617 | |
| 2618 | if (input.hasAttribute('placeholder')) { |
| 2619 | result.inputPlaceholder = input.getAttribute('placeholder'); |
| 2620 | } |
| 2621 | |
| 2622 | if (input.hasAttribute('value')) { |
| 2623 | result.inputValue = input.getAttribute('value'); |
| 2624 | } |
| 2625 | } |
| 2626 | |
| 2627 | var inputOptions = templateContent.querySelectorAll('swal-input-option'); |
| 2628 | |
| 2629 | if (inputOptions.length) { |
| 2630 | result.inputOptions = {}; |
| 2631 | toArray(inputOptions).forEach(function (option) { |
| 2632 | showWarningsForAttributes(option, ['value']); |
| 2633 | var optionValue = option.getAttribute('value'); |
| 2634 | var optionName = option.innerHTML; |
| 2635 | result.inputOptions[optionValue] = optionName; |
| 2636 | }); |
| 2637 | } |
| 2638 | |
| 2639 | return result; |
| 2640 | }; |
| 2641 | |
| 2642 | var getSwalStringParams = function getSwalStringParams(templateContent, paramNames) { |
| 2643 | var result = {}; |
| 2644 | |
| 2645 | for (var i in paramNames) { |
| 2646 | var paramName = paramNames[i]; |
| 2647 | var tag = templateContent.querySelector(paramName); |
| 2648 | |
| 2649 | if (tag) { |
| 2650 | showWarningsForAttributes(tag, []); |
| 2651 | result[paramName.replace(/^swal-/, '')] = tag.innerHTML.trim(); |
| 2652 | } |
| 2653 | } |
| 2654 | |
| 2655 | return result; |
| 2656 | }; |
| 2657 | |
| 2658 | var showWarningsForElements = function showWarningsForElements(template) { |
| 2659 | var allowedElements = swalStringParams.concat(['swal-param', 'swal-button', 'swal-image', 'swal-icon', 'swal-input', 'swal-input-option']); |
| 2660 | toArray(template.querySelectorAll('*')).forEach(function (el) { |
| 2661 | if (el.parentNode !== template) { |
| 2662 | // can't use template.children because of IE11 |
| 2663 | return; |
| 2664 | } |
| 2665 | |
| 2666 | var tagName = el.tagName.toLowerCase(); |
| 2667 | |
| 2668 | if (allowedElements.indexOf(tagName) === -1) { |
| 2669 | warn("Unrecognized element <".concat(tagName, ">")); |
| 2670 | } |
| 2671 | }); |
| 2672 | }; |
| 2673 | |
| 2674 | var showWarningsForAttributes = function showWarningsForAttributes(el, allowedAttributes) { |
| 2675 | toArray(el.attributes).forEach(function (attribute) { |
| 2676 | if (allowedAttributes.indexOf(attribute.name) === -1) { |
| 2677 | 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.')]); |
| 2678 | } |
| 2679 | }); |
| 2680 | }; |
| 2681 | |
| 2682 | var SHOW_CLASS_TIMEOUT = 10; |
| 2683 | /** |
| 2684 | * Open popup, add necessary classes and styles, fix scrollbar |
| 2685 | * |
| 2686 | * @param params |
| 2687 | */ |
| 2688 | |
| 2689 | var openPopup = function openPopup(params) { |
| 2690 | var container = getContainer(); |
| 2691 | var popup = getPopup(); |
| 2692 | |
| 2693 | if (typeof params.willOpen === 'function') { |
| 2694 | params.willOpen(popup); |
| 2695 | } else if (typeof params.onBeforeOpen === 'function') { |
| 2696 | params.onBeforeOpen(popup); // @deprecated |
| 2697 | } |
| 2698 | |
| 2699 | var bodyStyles = window.getComputedStyle(document.body); |
| 2700 | var initialBodyOverflow = bodyStyles.overflowY; |
| 2701 | addClasses$1(container, popup, params); // scrolling is 'hidden' until animation is done, after that 'auto' |
| 2702 | |
| 2703 | setTimeout(function () { |
| 2704 | setScrollingVisibility(container, popup); |
| 2705 | }, SHOW_CLASS_TIMEOUT); |
| 2706 | |
| 2707 | if (isModal()) { |
| 2708 | fixScrollContainer(container, params.scrollbarPadding, initialBodyOverflow); |
| 2709 | setAriaHidden(); |
| 2710 | } |
| 2711 | |
| 2712 | if (!isToast() && !globalState.previousActiveElement) { |
| 2713 | globalState.previousActiveElement = document.activeElement; |
| 2714 | } |
| 2715 | |
| 2716 | runDidOpen(popup, params); |
| 2717 | removeClass(container, swalClasses['no-transition']); |
| 2718 | }; |
| 2719 | |
| 2720 | var runDidOpen = function runDidOpen(popup, params) { |
| 2721 | if (typeof params.didOpen === 'function') { |
| 2722 | setTimeout(function () { |
| 2723 | return params.didOpen(popup); |
| 2724 | }); |
| 2725 | } else if (typeof params.onOpen === 'function') { |
| 2726 | setTimeout(function () { |
| 2727 | return params.onOpen(popup); |
| 2728 | }); // @deprecated |
| 2729 | } |
| 2730 | }; |
| 2731 | |
| 2732 | var swalOpenAnimationFinished = function swalOpenAnimationFinished(event) { |
| 2733 | var popup = getPopup(); |
| 2734 | |
| 2735 | if (event.target !== popup) { |
| 2736 | return; |
| 2737 | } |
| 2738 | |
| 2739 | var container = getContainer(); |
| 2740 | popup.removeEventListener(animationEndEvent, swalOpenAnimationFinished); |
| 2741 | container.style.overflowY = 'auto'; |
| 2742 | }; |
| 2743 | |
| 2744 | var setScrollingVisibility = function setScrollingVisibility(container, popup) { |
| 2745 | if (animationEndEvent && hasCssAnimation(popup)) { |
| 2746 | container.style.overflowY = 'hidden'; |
| 2747 | popup.addEventListener(animationEndEvent, swalOpenAnimationFinished); |
| 2748 | } else { |
| 2749 | container.style.overflowY = 'auto'; |
| 2750 | } |
| 2751 | }; |
| 2752 | |
| 2753 | var fixScrollContainer = function fixScrollContainer(container, scrollbarPadding, initialBodyOverflow) { |
| 2754 | iOSfix(); |
| 2755 | IEfix(); |
| 2756 | |
| 2757 | if (scrollbarPadding && initialBodyOverflow !== 'hidden') { |
| 2758 | fixScrollbar(); |
| 2759 | } // sweetalert2/issues/1247 |
| 2760 | |
| 2761 | |
| 2762 | setTimeout(function () { |
| 2763 | container.scrollTop = 0; |
| 2764 | }); |
| 2765 | }; |
| 2766 | |
| 2767 | var addClasses$1 = function addClasses(container, popup, params) { |
| 2768 | addClass(container, params.showClass.backdrop); // the workaround with setting/unsetting opacity is needed for #2019 and 2059 |
| 2769 | |
| 2770 | popup.style.setProperty('opacity', '0', 'important'); |
| 2771 | show(popup); |
| 2772 | setTimeout(function () { |
| 2773 | // Animate popup right after showing it |
| 2774 | addClass(popup, params.showClass.popup); // and remove the opacity workaround |
| 2775 | |
| 2776 | popup.style.removeProperty('opacity'); |
| 2777 | }, SHOW_CLASS_TIMEOUT); // 10ms in order to fix #2062 |
| 2778 | |
| 2779 | addClass([document.documentElement, document.body], swalClasses.shown); |
| 2780 | |
| 2781 | if (params.heightAuto && params.backdrop && !params.toast) { |
| 2782 | addClass([document.documentElement, document.body], swalClasses['height-auto']); |
| 2783 | } |
| 2784 | }; |
| 2785 | |
| 2786 | var handleInputOptionsAndValue = function handleInputOptionsAndValue(instance, params) { |
| 2787 | if (params.input === 'select' || params.input === 'radio') { |
| 2788 | handleInputOptions(instance, params); |
| 2789 | } else if (['text', 'email', 'number', 'tel', 'textarea'].indexOf(params.input) !== -1 && (hasToPromiseFn(params.inputValue) || isPromise(params.inputValue))) { |
| 2790 | handleInputValue(instance, params); |
| 2791 | } |
| 2792 | }; |
| 2793 | var getInputValue = function getInputValue(instance, innerParams) { |
| 2794 | var input = instance.getInput(); |
| 2795 | |
| 2796 | if (!input) { |
| 2797 | return null; |
| 2798 | } |
| 2799 | |
| 2800 | switch (innerParams.input) { |
| 2801 | case 'checkbox': |
| 2802 | return getCheckboxValue(input); |
| 2803 | |
| 2804 | case 'radio': |
| 2805 | return getRadioValue(input); |
| 2806 | |
| 2807 | case 'file': |
| 2808 | return getFileValue(input); |
| 2809 | |
| 2810 | default: |
| 2811 | return innerParams.inputAutoTrim ? input.value.trim() : input.value; |
| 2812 | } |
| 2813 | }; |
| 2814 | |
| 2815 | var getCheckboxValue = function getCheckboxValue(input) { |
| 2816 | return input.checked ? 1 : 0; |
| 2817 | }; |
| 2818 | |
| 2819 | var getRadioValue = function getRadioValue(input) { |
| 2820 | return input.checked ? input.value : null; |
| 2821 | }; |
| 2822 | |
| 2823 | var getFileValue = function getFileValue(input) { |
| 2824 | return input.files.length ? input.getAttribute('multiple') !== null ? input.files : input.files[0] : null; |
| 2825 | }; |
| 2826 | |
| 2827 | var handleInputOptions = function handleInputOptions(instance, params) { |
| 2828 | var content = getContent(); |
| 2829 | |
| 2830 | var processInputOptions = function processInputOptions(inputOptions) { |
| 2831 | return populateInputOptions[params.input](content, formatInputOptions(inputOptions), params); |
| 2832 | }; |
| 2833 | |
| 2834 | if (hasToPromiseFn(params.inputOptions) || isPromise(params.inputOptions)) { |
| 2835 | showLoading(getConfirmButton()); |
| 2836 | asPromise(params.inputOptions).then(function (inputOptions) { |
| 2837 | instance.hideLoading(); |
| 2838 | processInputOptions(inputOptions); |
| 2839 | }); |
| 2840 | } else if (_typeof(params.inputOptions) === 'object') { |
| 2841 | processInputOptions(params.inputOptions); |
| 2842 | } else { |
| 2843 | error("Unexpected type of inputOptions! Expected object, Map or Promise, got ".concat(_typeof(params.inputOptions))); |
| 2844 | } |
| 2845 | }; |
| 2846 | |
| 2847 | var handleInputValue = function handleInputValue(instance, params) { |
| 2848 | var input = instance.getInput(); |
| 2849 | hide(input); |
| 2850 | asPromise(params.inputValue).then(function (inputValue) { |
| 2851 | input.value = params.input === 'number' ? parseFloat(inputValue) || 0 : "".concat(inputValue); |
| 2852 | show(input); |
| 2853 | input.focus(); |
| 2854 | instance.hideLoading(); |
| 2855 | })["catch"](function (err) { |
| 2856 | error("Error in inputValue promise: ".concat(err)); |
| 2857 | input.value = ''; |
| 2858 | show(input); |
| 2859 | input.focus(); |
| 2860 | instance.hideLoading(); |
| 2861 | }); |
| 2862 | }; |
| 2863 | |
| 2864 | var populateInputOptions = { |
| 2865 | select: function select(content, inputOptions, params) { |
| 2866 | var select = getChildByClass(content, swalClasses.select); |
| 2867 | |
| 2868 | var renderOption = function renderOption(parent, optionLabel, optionValue) { |
| 2869 | var option = document.createElement('option'); |
| 2870 | option.value = optionValue; |
| 2871 | setInnerHtml(option, optionLabel); |
| 2872 | option.selected = isSelected(optionValue, params.inputValue); |
| 2873 | parent.appendChild(option); |
| 2874 | }; |
| 2875 | |
| 2876 | inputOptions.forEach(function (inputOption) { |
| 2877 | var optionValue = inputOption[0]; |
| 2878 | var optionLabel = inputOption[1]; // <optgroup> spec: |
| 2879 | // https://www.w3.org/TR/html401/interact/forms.html#h-17.6 |
| 2880 | // "...all OPTGROUP elements must be specified directly within a SELECT element (i.e., groups may not be nested)..." |
| 2881 | // check whether this is a <optgroup> |
| 2882 | |
| 2883 | if (Array.isArray(optionLabel)) { |
| 2884 | // if it is an array, then it is an <optgroup> |
| 2885 | var optgroup = document.createElement('optgroup'); |
| 2886 | optgroup.label = optionValue; |
| 2887 | optgroup.disabled = false; // not configurable for now |
| 2888 | |
| 2889 | select.appendChild(optgroup); |
| 2890 | optionLabel.forEach(function (o) { |
| 2891 | return renderOption(optgroup, o[1], o[0]); |
| 2892 | }); |
| 2893 | } else { |
| 2894 | // case of <option> |
| 2895 | renderOption(select, optionLabel, optionValue); |
| 2896 | } |
| 2897 | }); |
| 2898 | select.focus(); |
| 2899 | }, |
| 2900 | radio: function radio(content, inputOptions, params) { |
| 2901 | var radio = getChildByClass(content, swalClasses.radio); |
| 2902 | inputOptions.forEach(function (inputOption) { |
| 2903 | var radioValue = inputOption[0]; |
| 2904 | var radioLabel = inputOption[1]; |
| 2905 | var radioInput = document.createElement('input'); |
| 2906 | var radioLabelElement = document.createElement('label'); |
| 2907 | radioInput.type = 'radio'; |
| 2908 | radioInput.name = swalClasses.radio; |
| 2909 | radioInput.value = radioValue; |
| 2910 | |
| 2911 | if (isSelected(radioValue, params.inputValue)) { |
| 2912 | radioInput.checked = true; |
| 2913 | } |
| 2914 | |
| 2915 | var label = document.createElement('span'); |
| 2916 | setInnerHtml(label, radioLabel); |
| 2917 | label.className = swalClasses.label; |
| 2918 | radioLabelElement.appendChild(radioInput); |
| 2919 | radioLabelElement.appendChild(label); |
| 2920 | radio.appendChild(radioLabelElement); |
| 2921 | }); |
| 2922 | var radios = radio.querySelectorAll('input'); |
| 2923 | |
| 2924 | if (radios.length) { |
| 2925 | radios[0].focus(); |
| 2926 | } |
| 2927 | } |
| 2928 | }; |
| 2929 | /** |
| 2930 | * Converts `inputOptions` into an array of `[value, label]`s |
| 2931 | * @param inputOptions |
| 2932 | */ |
| 2933 | |
| 2934 | var formatInputOptions = function formatInputOptions(inputOptions) { |
| 2935 | var result = []; |
| 2936 | |
| 2937 | if (typeof Map !== 'undefined' && inputOptions instanceof Map) { |
| 2938 | inputOptions.forEach(function (value, key) { |
| 2939 | var valueFormatted = value; |
| 2940 | |
| 2941 | if (_typeof(valueFormatted) === 'object') { |
| 2942 | // case of <optgroup> |
| 2943 | valueFormatted = formatInputOptions(valueFormatted); |
| 2944 | } |
| 2945 | |
| 2946 | result.push([key, valueFormatted]); |
| 2947 | }); |
| 2948 | } else { |
| 2949 | Object.keys(inputOptions).forEach(function (key) { |
| 2950 | var valueFormatted = inputOptions[key]; |
| 2951 | |
| 2952 | if (_typeof(valueFormatted) === 'object') { |
| 2953 | // case of <optgroup> |
| 2954 | valueFormatted = formatInputOptions(valueFormatted); |
| 2955 | } |
| 2956 | |
| 2957 | result.push([key, valueFormatted]); |
| 2958 | }); |
| 2959 | } |
| 2960 | |
| 2961 | return result; |
| 2962 | }; |
| 2963 | |
| 2964 | var isSelected = function isSelected(optionValue, inputValue) { |
| 2965 | return inputValue && inputValue.toString() === optionValue.toString(); |
| 2966 | }; |
| 2967 | |
| 2968 | var handleConfirmButtonClick = function handleConfirmButtonClick(instance, innerParams) { |
| 2969 | instance.disableButtons(); |
| 2970 | |
| 2971 | if (innerParams.input) { |
| 2972 | handleConfirmOrDenyWithInput(instance, innerParams, 'confirm'); |
| 2973 | } else { |
| 2974 | confirm(instance, innerParams, true); |
| 2975 | } |
| 2976 | }; |
| 2977 | var handleDenyButtonClick = function handleDenyButtonClick(instance, innerParams) { |
| 2978 | instance.disableButtons(); |
| 2979 | |
| 2980 | if (innerParams.returnInputValueOnDeny) { |
| 2981 | handleConfirmOrDenyWithInput(instance, innerParams, 'deny'); |
| 2982 | } else { |
| 2983 | deny(instance, innerParams, false); |
| 2984 | } |
| 2985 | }; |
| 2986 | var handleCancelButtonClick = function handleCancelButtonClick(instance, dismissWith) { |
| 2987 | instance.disableButtons(); |
| 2988 | dismissWith(DismissReason.cancel); |
| 2989 | }; |
| 2990 | |
| 2991 | var handleConfirmOrDenyWithInput = function handleConfirmOrDenyWithInput(instance, innerParams, type |
| 2992 | /* type is either 'confirm' or 'deny' */ |
| 2993 | ) { |
| 2994 | var inputValue = getInputValue(instance, innerParams); |
| 2995 | |
| 2996 | if (innerParams.inputValidator) { |
| 2997 | handleInputValidator(instance, innerParams, inputValue); |
| 2998 | } else if (!instance.getInput().checkValidity()) { |
| 2999 | instance.enableButtons(); |
| 3000 | instance.showValidationMessage(innerParams.validationMessage); |
| 3001 | } else if (type === 'deny') { |
| 3002 | deny(instance, innerParams, inputValue); |
| 3003 | } else { |
| 3004 | confirm(instance, innerParams, inputValue); |
| 3005 | } |
| 3006 | }; |
| 3007 | |
| 3008 | var handleInputValidator = function handleInputValidator(instance, innerParams, inputValue) { |
| 3009 | instance.disableInput(); |
| 3010 | var validationPromise = Promise.resolve().then(function () { |
| 3011 | return asPromise(innerParams.inputValidator(inputValue, innerParams.validationMessage)); |
| 3012 | }); |
| 3013 | validationPromise.then(function (validationMessage) { |
| 3014 | instance.enableButtons(); |
| 3015 | instance.enableInput(); |
| 3016 | |
| 3017 | if (validationMessage) { |
| 3018 | instance.showValidationMessage(validationMessage); |
| 3019 | } else { |
| 3020 | confirm(instance, innerParams, inputValue); |
| 3021 | } |
| 3022 | }); |
| 3023 | }; |
| 3024 | |
| 3025 | var deny = function deny(instance, innerParams, value) { |
| 3026 | if (innerParams.showLoaderOnDeny) { |
| 3027 | showLoading(getDenyButton()); |
| 3028 | } |
| 3029 | |
| 3030 | if (innerParams.preDeny) { |
| 3031 | var preDenyPromise = Promise.resolve().then(function () { |
| 3032 | return asPromise(innerParams.preDeny(value, innerParams.validationMessage)); |
| 3033 | }); |
| 3034 | preDenyPromise.then(function (preDenyValue) { |
| 3035 | if (preDenyValue === false) { |
| 3036 | instance.hideLoading(); |
| 3037 | } else { |
| 3038 | instance.closePopup({ |
| 3039 | isDenied: true, |
| 3040 | value: typeof preDenyValue === 'undefined' ? value : preDenyValue |
| 3041 | }); |
| 3042 | } |
| 3043 | }); |
| 3044 | } else { |
| 3045 | instance.closePopup({ |
| 3046 | isDenied: true, |
| 3047 | value: value |
| 3048 | }); |
| 3049 | } |
| 3050 | }; |
| 3051 | |
| 3052 | var succeedWith = function succeedWith(instance, value) { |
| 3053 | instance.closePopup({ |
| 3054 | isConfirmed: true, |
| 3055 | value: value |
| 3056 | }); |
| 3057 | }; |
| 3058 | |
| 3059 | var confirm = function confirm(instance, innerParams, value) { |
| 3060 | if (innerParams.showLoaderOnConfirm) { |
| 3061 | showLoading(); // TODO: make showLoading an *instance* method |
| 3062 | } |
| 3063 | |
| 3064 | if (innerParams.preConfirm) { |
| 3065 | instance.resetValidationMessage(); |
| 3066 | var preConfirmPromise = Promise.resolve().then(function () { |
| 3067 | return asPromise(innerParams.preConfirm(value, innerParams.validationMessage)); |
| 3068 | }); |
| 3069 | preConfirmPromise.then(function (preConfirmValue) { |
| 3070 | if (isVisible(getValidationMessage()) || preConfirmValue === false) { |
| 3071 | instance.hideLoading(); |
| 3072 | } else { |
| 3073 | succeedWith(instance, typeof preConfirmValue === 'undefined' ? value : preConfirmValue); |
| 3074 | } |
| 3075 | }); |
| 3076 | } else { |
| 3077 | succeedWith(instance, value); |
| 3078 | } |
| 3079 | }; |
| 3080 | |
| 3081 | var addKeydownHandler = function addKeydownHandler(instance, globalState, innerParams, dismissWith) { |
| 3082 | if (globalState.keydownTarget && globalState.keydownHandlerAdded) { |
| 3083 | globalState.keydownTarget.removeEventListener('keydown', globalState.keydownHandler, { |
| 3084 | capture: globalState.keydownListenerCapture |
| 3085 | }); |
| 3086 | globalState.keydownHandlerAdded = false; |
| 3087 | } |
| 3088 | |
| 3089 | if (!innerParams.toast) { |
| 3090 | globalState.keydownHandler = function (e) { |
| 3091 | return keydownHandler(instance, e, dismissWith); |
| 3092 | }; |
| 3093 | |
| 3094 | globalState.keydownTarget = innerParams.keydownListenerCapture ? window : getPopup(); |
| 3095 | globalState.keydownListenerCapture = innerParams.keydownListenerCapture; |
| 3096 | globalState.keydownTarget.addEventListener('keydown', globalState.keydownHandler, { |
| 3097 | capture: globalState.keydownListenerCapture |
| 3098 | }); |
| 3099 | globalState.keydownHandlerAdded = true; |
| 3100 | } |
| 3101 | }; // Focus handling |
| 3102 | |
| 3103 | var setFocus = function setFocus(innerParams, index, increment) { |
| 3104 | var focusableElements = getFocusableElements(); // search for visible elements and select the next possible match |
| 3105 | |
| 3106 | if (focusableElements.length) { |
| 3107 | index = index + increment; // rollover to first item |
| 3108 | |
| 3109 | if (index === focusableElements.length) { |
| 3110 | index = 0; // go to last item |
| 3111 | } else if (index === -1) { |
| 3112 | index = focusableElements.length - 1; |
| 3113 | } |
| 3114 | |
| 3115 | return focusableElements[index].focus(); |
| 3116 | } // no visible focusable elements, focus the popup |
| 3117 | |
| 3118 | |
| 3119 | getPopup().focus(); |
| 3120 | }; |
| 3121 | var arrowKeysNextButton = ['ArrowRight', 'ArrowDown', 'Right', 'Down' // IE11 |
| 3122 | ]; |
| 3123 | var arrowKeysPreviousButton = ['ArrowLeft', 'ArrowUp', 'Left', 'Up' // IE11 |
| 3124 | ]; |
| 3125 | var escKeys = ['Escape', 'Esc' // IE11 |
| 3126 | ]; |
| 3127 | |
| 3128 | var keydownHandler = function keydownHandler(instance, e, dismissWith) { |
| 3129 | var innerParams = privateProps.innerParams.get(instance); |
| 3130 | |
| 3131 | if (!innerParams) { |
| 3132 | return; // This instance has already been destroyed |
| 3133 | } |
| 3134 | |
| 3135 | if (innerParams.stopKeydownPropagation) { |
| 3136 | e.stopPropagation(); |
| 3137 | } // ENTER |
| 3138 | |
| 3139 | |
| 3140 | if (e.key === 'Enter') { |
| 3141 | handleEnter(instance, e, innerParams); // TAB |
| 3142 | } else if (e.key === 'Tab') { |
| 3143 | handleTab(e, innerParams); // ARROWS - switch focus between buttons |
| 3144 | } else if ([].concat(arrowKeysNextButton, arrowKeysPreviousButton).indexOf(e.key) !== -1) { |
| 3145 | handleArrows(e.key); // ESC |
| 3146 | } else if (escKeys.indexOf(e.key) !== -1) { |
| 3147 | handleEsc(e, innerParams, dismissWith); |
| 3148 | } |
| 3149 | }; |
| 3150 | |
| 3151 | var handleEnter = function handleEnter(instance, e, innerParams) { |
| 3152 | // #720 #721 |
| 3153 | if (e.isComposing) { |
| 3154 | return; |
| 3155 | } |
| 3156 | |
| 3157 | if (e.target && instance.getInput() && e.target.outerHTML === instance.getInput().outerHTML) { |
| 3158 | if (['textarea', 'file'].indexOf(innerParams.input) !== -1) { |
| 3159 | return; // do not submit |
| 3160 | } |
| 3161 | |
| 3162 | clickConfirm(); |
| 3163 | e.preventDefault(); |
| 3164 | } |
| 3165 | }; |
| 3166 | |
| 3167 | var handleTab = function handleTab(e, innerParams) { |
| 3168 | var targetElement = e.target; |
| 3169 | var focusableElements = getFocusableElements(); |
| 3170 | var btnIndex = -1; |
| 3171 | |
| 3172 | for (var i = 0; i < focusableElements.length; i++) { |
| 3173 | if (targetElement === focusableElements[i]) { |
| 3174 | btnIndex = i; |
| 3175 | break; |
| 3176 | } |
| 3177 | } |
| 3178 | |
| 3179 | if (!e.shiftKey) { |
| 3180 | // Cycle to the next button |
| 3181 | setFocus(innerParams, btnIndex, 1); |
| 3182 | } else { |
| 3183 | // Cycle to the prev button |
| 3184 | setFocus(innerParams, btnIndex, -1); |
| 3185 | } |
| 3186 | |
| 3187 | e.stopPropagation(); |
| 3188 | e.preventDefault(); |
| 3189 | }; |
| 3190 | |
| 3191 | var handleArrows = function handleArrows(key) { |
| 3192 | var confirmButton = getConfirmButton(); |
| 3193 | var denyButton = getDenyButton(); |
| 3194 | var cancelButton = getCancelButton(); |
| 3195 | |
| 3196 | if (!([confirmButton, denyButton, cancelButton].indexOf(document.activeElement) !== -1)) { |
| 3197 | return; |
| 3198 | } |
| 3199 | |
| 3200 | var sibling = arrowKeysNextButton.indexOf(key) !== -1 ? 'nextElementSibling' : 'previousElementSibling'; |
| 3201 | var buttonToFocus = document.activeElement[sibling]; |
| 3202 | |
| 3203 | if (buttonToFocus) { |
| 3204 | buttonToFocus.focus(); |
| 3205 | } |
| 3206 | }; |
| 3207 | |
| 3208 | var handleEsc = function handleEsc(e, innerParams, dismissWith) { |
| 3209 | if (callIfFunction(innerParams.allowEscapeKey)) { |
| 3210 | e.preventDefault(); |
| 3211 | dismissWith(DismissReason.esc); |
| 3212 | } |
| 3213 | }; |
| 3214 | |
| 3215 | var handlePopupClick = function handlePopupClick(instance, domCache, dismissWith) { |
| 3216 | var innerParams = privateProps.innerParams.get(instance); |
| 3217 | |
| 3218 | if (innerParams.toast) { |
| 3219 | handleToastClick(instance, domCache, dismissWith); |
| 3220 | } else { |
| 3221 | // Ignore click events that had mousedown on the popup but mouseup on the container |
| 3222 | // This can happen when the user drags a slider |
| 3223 | handleModalMousedown(domCache); // Ignore click events that had mousedown on the container but mouseup on the popup |
| 3224 | |
| 3225 | handleContainerMousedown(domCache); |
| 3226 | handleModalClick(instance, domCache, dismissWith); |
| 3227 | } |
| 3228 | }; |
| 3229 | |
| 3230 | var handleToastClick = function handleToastClick(instance, domCache, dismissWith) { |
| 3231 | // Closing toast by internal click |
| 3232 | domCache.popup.onclick = function () { |
| 3233 | var innerParams = privateProps.innerParams.get(instance); |
| 3234 | |
| 3235 | if (innerParams.showConfirmButton || innerParams.showDenyButton || innerParams.showCancelButton || innerParams.showCloseButton || innerParams.timer || innerParams.input) { |
| 3236 | return; |
| 3237 | } |
| 3238 | |
| 3239 | dismissWith(DismissReason.close); |
| 3240 | }; |
| 3241 | }; |
| 3242 | |
| 3243 | var ignoreOutsideClick = false; |
| 3244 | |
| 3245 | var handleModalMousedown = function handleModalMousedown(domCache) { |
| 3246 | domCache.popup.onmousedown = function () { |
| 3247 | domCache.container.onmouseup = function (e) { |
| 3248 | domCache.container.onmouseup = undefined; // We only check if the mouseup target is the container because usually it doesn't |
| 3249 | // have any other direct children aside of the popup |
| 3250 | |
| 3251 | if (e.target === domCache.container) { |
| 3252 | ignoreOutsideClick = true; |
| 3253 | } |
| 3254 | }; |
| 3255 | }; |
| 3256 | }; |
| 3257 | |
| 3258 | var handleContainerMousedown = function handleContainerMousedown(domCache) { |
| 3259 | domCache.container.onmousedown = function () { |
| 3260 | domCache.popup.onmouseup = function (e) { |
| 3261 | domCache.popup.onmouseup = undefined; // We also need to check if the mouseup target is a child of the popup |
| 3262 | |
| 3263 | if (e.target === domCache.popup || domCache.popup.contains(e.target)) { |
| 3264 | ignoreOutsideClick = true; |
| 3265 | } |
| 3266 | }; |
| 3267 | }; |
| 3268 | }; |
| 3269 | |
| 3270 | var handleModalClick = function handleModalClick(instance, domCache, dismissWith) { |
| 3271 | domCache.container.onclick = function (e) { |
| 3272 | var innerParams = privateProps.innerParams.get(instance); |
| 3273 | |
| 3274 | if (ignoreOutsideClick) { |
| 3275 | ignoreOutsideClick = false; |
| 3276 | return; |
| 3277 | } |
| 3278 | |
| 3279 | if (e.target === domCache.container && callIfFunction(innerParams.allowOutsideClick)) { |
| 3280 | dismissWith(DismissReason.backdrop); |
| 3281 | } |
| 3282 | }; |
| 3283 | }; |
| 3284 | |
| 3285 | function _main(userParams) { |
| 3286 | var mixinParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; |
| 3287 | showWarningsForParams(_extends({}, mixinParams, userParams)); |
| 3288 | |
| 3289 | if (globalState.currentInstance) { |
| 3290 | globalState.currentInstance._destroy(); |
| 3291 | } |
| 3292 | |
| 3293 | globalState.currentInstance = this; |
| 3294 | var innerParams = prepareParams(userParams, mixinParams); |
| 3295 | setParameters(innerParams); |
| 3296 | Object.freeze(innerParams); // clear the previous timer |
| 3297 | |
| 3298 | if (globalState.timeout) { |
| 3299 | globalState.timeout.stop(); |
| 3300 | delete globalState.timeout; |
| 3301 | } // clear the restore focus timeout |
| 3302 | |
| 3303 | |
| 3304 | clearTimeout(globalState.restoreFocusTimeout); |
| 3305 | var domCache = populateDomCache(this); |
| 3306 | render(this, innerParams); |
| 3307 | privateProps.innerParams.set(this, innerParams); |
| 3308 | return swalPromise(this, domCache, innerParams); |
| 3309 | } |
| 3310 | |
| 3311 | var prepareParams = function prepareParams(userParams, mixinParams) { |
| 3312 | var templateParams = getTemplateParams(userParams); |
| 3313 | |
| 3314 | var params = _extends({}, defaultParams, mixinParams, templateParams, userParams); // precedence is described in #2131 |
| 3315 | |
| 3316 | |
| 3317 | params.showClass = _extends({}, defaultParams.showClass, params.showClass); |
| 3318 | params.hideClass = _extends({}, defaultParams.hideClass, params.hideClass); // @deprecated |
| 3319 | |
| 3320 | if (userParams.animation === false) { |
| 3321 | params.showClass = { |
| 3322 | popup: 'swal2-noanimation', |
| 3323 | backdrop: 'swal2-noanimation' |
| 3324 | }; |
| 3325 | params.hideClass = {}; |
| 3326 | } |
| 3327 | |
| 3328 | return params; |
| 3329 | }; |
| 3330 | |
| 3331 | var swalPromise = function swalPromise(instance, domCache, innerParams) { |
| 3332 | return new Promise(function (resolve) { |
| 3333 | // functions to handle all closings/dismissals |
| 3334 | var dismissWith = function dismissWith(dismiss) { |
| 3335 | instance.closePopup({ |
| 3336 | isDismissed: true, |
| 3337 | dismiss: dismiss |
| 3338 | }); |
| 3339 | }; |
| 3340 | |
| 3341 | privateMethods.swalPromiseResolve.set(instance, resolve); |
| 3342 | |
| 3343 | domCache.confirmButton.onclick = function () { |
| 3344 | return handleConfirmButtonClick(instance, innerParams); |
| 3345 | }; |
| 3346 | |
| 3347 | domCache.denyButton.onclick = function () { |
| 3348 | return handleDenyButtonClick(instance, innerParams); |
| 3349 | }; |
| 3350 | |
| 3351 | domCache.cancelButton.onclick = function () { |
| 3352 | return handleCancelButtonClick(instance, dismissWith); |
| 3353 | }; |
| 3354 | |
| 3355 | domCache.closeButton.onclick = function () { |
| 3356 | return dismissWith(DismissReason.close); |
| 3357 | }; |
| 3358 | |
| 3359 | handlePopupClick(instance, domCache, dismissWith); |
| 3360 | addKeydownHandler(instance, globalState, innerParams, dismissWith); |
| 3361 | handleInputOptionsAndValue(instance, innerParams); |
| 3362 | openPopup(innerParams); |
| 3363 | setupTimer(globalState, innerParams, dismissWith); |
| 3364 | initFocus(domCache, innerParams); // Scroll container to top on open (#1247, #1946) |
| 3365 | |
| 3366 | setTimeout(function () { |
| 3367 | domCache.container.scrollTop = 0; |
| 3368 | }); |
| 3369 | }); |
| 3370 | }; |
| 3371 | |
| 3372 | var populateDomCache = function populateDomCache(instance) { |
| 3373 | var domCache = { |
| 3374 | popup: getPopup(), |
| 3375 | container: getContainer(), |
| 3376 | content: getContent(), |
| 3377 | actions: getActions(), |
| 3378 | confirmButton: getConfirmButton(), |
| 3379 | denyButton: getDenyButton(), |
| 3380 | cancelButton: getCancelButton(), |
| 3381 | loader: getLoader(), |
| 3382 | closeButton: getCloseButton(), |
| 3383 | validationMessage: getValidationMessage(), |
| 3384 | progressSteps: getProgressSteps() |
| 3385 | }; |
| 3386 | privateProps.domCache.set(instance, domCache); |
| 3387 | return domCache; |
| 3388 | }; |
| 3389 | |
| 3390 | var setupTimer = function setupTimer(globalState$$1, innerParams, dismissWith) { |
| 3391 | var timerProgressBar = getTimerProgressBar(); |
| 3392 | hide(timerProgressBar); |
| 3393 | |
| 3394 | if (innerParams.timer) { |
| 3395 | globalState$$1.timeout = new Timer(function () { |
| 3396 | dismissWith('timer'); |
| 3397 | delete globalState$$1.timeout; |
| 3398 | }, innerParams.timer); |
| 3399 | |
| 3400 | if (innerParams.timerProgressBar) { |
| 3401 | show(timerProgressBar); |
| 3402 | setTimeout(function () { |
| 3403 | if (globalState$$1.timeout && globalState$$1.timeout.running) { |
| 3404 | // timer can be already stopped or unset at this point |
| 3405 | animateTimerProgressBar(innerParams.timer); |
| 3406 | } |
| 3407 | }); |
| 3408 | } |
| 3409 | } |
| 3410 | }; |
| 3411 | |
| 3412 | var initFocus = function initFocus(domCache, innerParams) { |
| 3413 | if (innerParams.toast) { |
| 3414 | return; |
| 3415 | } |
| 3416 | |
| 3417 | if (!callIfFunction(innerParams.allowEnterKey)) { |
| 3418 | return blurActiveElement(); |
| 3419 | } |
| 3420 | |
| 3421 | if (!focusButton(domCache, innerParams)) { |
| 3422 | setFocus(innerParams, -1, 1); |
| 3423 | } |
| 3424 | }; |
| 3425 | |
| 3426 | var focusButton = function focusButton(domCache, innerParams) { |
| 3427 | if (innerParams.focusDeny && isVisible(domCache.denyButton)) { |
| 3428 | domCache.denyButton.focus(); |
| 3429 | return true; |
| 3430 | } |
| 3431 | |
| 3432 | if (innerParams.focusCancel && isVisible(domCache.cancelButton)) { |
| 3433 | domCache.cancelButton.focus(); |
| 3434 | return true; |
| 3435 | } |
| 3436 | |
| 3437 | if (innerParams.focusConfirm && isVisible(domCache.confirmButton)) { |
| 3438 | domCache.confirmButton.focus(); |
| 3439 | return true; |
| 3440 | } |
| 3441 | |
| 3442 | return false; |
| 3443 | }; |
| 3444 | |
| 3445 | var blurActiveElement = function blurActiveElement() { |
| 3446 | if (document.activeElement && typeof document.activeElement.blur === 'function') { |
| 3447 | document.activeElement.blur(); |
| 3448 | } |
| 3449 | }; |
| 3450 | |
| 3451 | /** |
| 3452 | * Updates popup parameters. |
| 3453 | */ |
| 3454 | |
| 3455 | function update(params) { |
| 3456 | var popup = getPopup(); |
| 3457 | var innerParams = privateProps.innerParams.get(this); |
| 3458 | |
| 3459 | if (!popup || hasClass(popup, innerParams.hideClass.popup)) { |
| 3460 | 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."); |
| 3461 | } |
| 3462 | |
| 3463 | var validUpdatableParams = {}; // assign valid params from `params` to `defaults` |
| 3464 | |
| 3465 | Object.keys(params).forEach(function (param) { |
| 3466 | if (Swal.isUpdatableParameter(param)) { |
| 3467 | validUpdatableParams[param] = params[param]; |
| 3468 | } else { |
| 3469 | 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")); |
| 3470 | } |
| 3471 | }); |
| 3472 | |
| 3473 | var updatedParams = _extends({}, innerParams, validUpdatableParams); |
| 3474 | |
| 3475 | render(this, updatedParams); |
| 3476 | privateProps.innerParams.set(this, updatedParams); |
| 3477 | Object.defineProperties(this, { |
| 3478 | params: { |
| 3479 | value: _extends({}, this.params, params), |
| 3480 | writable: false, |
| 3481 | enumerable: true |
| 3482 | } |
| 3483 | }); |
| 3484 | } |
| 3485 | |
| 3486 | function _destroy() { |
| 3487 | var domCache = privateProps.domCache.get(this); |
| 3488 | var innerParams = privateProps.innerParams.get(this); |
| 3489 | |
| 3490 | if (!innerParams) { |
| 3491 | return; // This instance has already been destroyed |
| 3492 | } // Check if there is another Swal closing |
| 3493 | |
| 3494 | |
| 3495 | if (domCache.popup && globalState.swalCloseEventFinishedCallback) { |
| 3496 | globalState.swalCloseEventFinishedCallback(); |
| 3497 | delete globalState.swalCloseEventFinishedCallback; |
| 3498 | } // Check if there is a swal disposal defer timer |
| 3499 | |
| 3500 | |
| 3501 | if (globalState.deferDisposalTimer) { |
| 3502 | clearTimeout(globalState.deferDisposalTimer); |
| 3503 | delete globalState.deferDisposalTimer; |
| 3504 | } |
| 3505 | |
| 3506 | runDidDestroy(innerParams); |
| 3507 | disposeSwal(this); |
| 3508 | } |
| 3509 | |
| 3510 | var runDidDestroy = function runDidDestroy(innerParams) { |
| 3511 | if (typeof innerParams.didDestroy === 'function') { |
| 3512 | innerParams.didDestroy(); |
| 3513 | } else if (typeof innerParams.onDestroy === 'function') { |
| 3514 | innerParams.onDestroy(); // @deprecated |
| 3515 | } |
| 3516 | }; |
| 3517 | |
| 3518 | var disposeSwal = function disposeSwal(instance) { |
| 3519 | // Unset this.params so GC will dispose it (#1569) |
| 3520 | delete instance.params; // Unset globalState props so GC will dispose globalState (#1569) |
| 3521 | |
| 3522 | delete globalState.keydownHandler; |
| 3523 | delete globalState.keydownTarget; // Unset WeakMaps so GC will be able to dispose them (#1569) |
| 3524 | |
| 3525 | unsetWeakMaps(privateProps); |
| 3526 | unsetWeakMaps(privateMethods); |
| 3527 | }; |
| 3528 | |
| 3529 | var unsetWeakMaps = function unsetWeakMaps(obj) { |
| 3530 | for (var i in obj) { |
| 3531 | obj[i] = new WeakMap(); |
| 3532 | } |
| 3533 | }; |
| 3534 | |
| 3535 | |
| 3536 | |
| 3537 | var instanceMethods = /*#__PURE__*/Object.freeze({ |
| 3538 | hideLoading: hideLoading, |
| 3539 | disableLoading: hideLoading, |
| 3540 | getInput: getInput$1, |
| 3541 | close: close, |
| 3542 | closePopup: close, |
| 3543 | closeModal: close, |
| 3544 | closeToast: close, |
| 3545 | enableButtons: enableButtons, |
| 3546 | disableButtons: disableButtons, |
| 3547 | enableInput: enableInput, |
| 3548 | disableInput: disableInput, |
| 3549 | showValidationMessage: showValidationMessage, |
| 3550 | resetValidationMessage: resetValidationMessage$1, |
| 3551 | getProgressSteps: getProgressSteps$1, |
| 3552 | _main: _main, |
| 3553 | update: update, |
| 3554 | _destroy: _destroy |
| 3555 | }); |
| 3556 | |
| 3557 | var currentInstance; |
| 3558 | |
| 3559 | var SweetAlert = /*#__PURE__*/function () { |
| 3560 | function SweetAlert() { |
| 3561 | _classCallCheck(this, SweetAlert); |
| 3562 | |
| 3563 | // Prevent run in Node env |
| 3564 | if (typeof window === 'undefined') { |
| 3565 | return; |
| 3566 | } // Check for the existence of Promise |
| 3567 | |
| 3568 | |
| 3569 | if (typeof Promise === 'undefined') { |
| 3570 | 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)'); |
| 3571 | } |
| 3572 | |
| 3573 | currentInstance = this; |
| 3574 | |
| 3575 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { |
| 3576 | args[_key] = arguments[_key]; |
| 3577 | } |
| 3578 | |
| 3579 | var outerParams = Object.freeze(this.constructor.argsToParams(args)); |
| 3580 | Object.defineProperties(this, { |
| 3581 | params: { |
| 3582 | value: outerParams, |
| 3583 | writable: false, |
| 3584 | enumerable: true, |
| 3585 | configurable: true |
| 3586 | } |
| 3587 | }); |
| 3588 | |
| 3589 | var promise = this._main(this.params); |
| 3590 | |
| 3591 | privateProps.promise.set(this, promise); |
| 3592 | } // `catch` cannot be the name of a module export, so we define our thenable methods here instead |
| 3593 | |
| 3594 | |
| 3595 | _createClass(SweetAlert, [{ |
| 3596 | key: "then", |
| 3597 | value: function then(onFulfilled) { |
| 3598 | var promise = privateProps.promise.get(this); |
| 3599 | return promise.then(onFulfilled); |
| 3600 | } |
| 3601 | }, { |
| 3602 | key: "finally", |
| 3603 | value: function _finally(onFinally) { |
| 3604 | var promise = privateProps.promise.get(this); |
| 3605 | return promise["finally"](onFinally); |
| 3606 | } |
| 3607 | }]); |
| 3608 | |
| 3609 | return SweetAlert; |
| 3610 | }(); // Assign instance methods from src/instanceMethods/*.js to prototype |
| 3611 | |
| 3612 | |
| 3613 | _extends(SweetAlert.prototype, instanceMethods); // Assign static methods from src/staticMethods/*.js to constructor |
| 3614 | |
| 3615 | |
| 3616 | _extends(SweetAlert, staticMethods); // Proxy to instance methods to constructor, for now, for backwards compatibility |
| 3617 | |
| 3618 | |
| 3619 | Object.keys(instanceMethods).forEach(function (key) { |
| 3620 | SweetAlert[key] = function () { |
| 3621 | if (currentInstance) { |
| 3622 | var _currentInstance; |
| 3623 | |
| 3624 | return (_currentInstance = currentInstance)[key].apply(_currentInstance, arguments); |
| 3625 | } |
| 3626 | }; |
| 3627 | }); |
| 3628 | SweetAlert.DismissReason = DismissReason; |
| 3629 | SweetAlert.version = '10.16.9'; |
| 3630 | |
| 3631 | var Swal = SweetAlert; |
| 3632 | Swal["default"] = Swal; |
| 3633 | |
| 3634 | return Swal; |
| 3635 | |
| 3636 | })); |
| 3637 | if (typeof this !== 'undefined' && this.Sweetalert2){ this.swal = this.sweetAlert = this.Swal = this.SweetAlert = this.Sweetalert2} |
| 3638 |