backup
2 years ago
notices
2 years ago
analytics-consent-modal.js
2 years ago
analytics-consent-modal.js.map
2 years ago
analytics-consent-modal.min.js
2 years ago
analytics-consent-modal.min.js.map
2 years ago
wpstg-admin-beta.js
2 years ago
wpstg-admin-beta.js.map
2 years ago
wpstg-admin-beta.min.js
5 years ago
wpstg-admin-beta.min.js.map
2 years ago
wpstg-admin-corrupt-settings.js
2 years ago
wpstg-admin-corrupt-settings.js.map
2 years ago
wpstg-admin-corrupt-settings.min.js
2 years ago
wpstg-admin-corrupt-settings.min.js.map
2 years ago
wpstg-admin-plugins.js
2 years ago
wpstg-admin-plugins.js.map
2 years ago
wpstg-admin-plugins.min.js
2 years ago
wpstg-admin-plugins.min.js.map
2 years ago
wpstg-admin-rating.js
2 years ago
wpstg-admin-rating.js.map
2 years ago
wpstg-admin-rating.min.js
2 years ago
wpstg-admin-rating.min.js.map
2 years ago
wpstg-admin.js
2 years ago
wpstg-admin.js.map
2 years ago
wpstg-admin.min.js
2 years ago
wpstg-admin.min.js.map
2 years ago
wpstg-blank-loader.js
2 years ago
wpstg-blank-loader.js.map
2 years ago
wpstg-blank-loader.min.js
2 years ago
wpstg-blank-loader.min.js.map
2 years ago
wpstg-sweetalert2.js
2 years ago
wpstg-sweetalert2.js.map
2 years ago
wpstg-sweetalert2.min.js
2 years ago
wpstg-sweetalert2.min.js.map
2 years ago
wpstg.js
2 years ago
wpstg.js.map
2 years ago
wpstg.min.js
2 years ago
wpstg.min.js.map
2 years ago
wpstg-sweetalert2.js
2749 lines
| 1 | (function () { |
| 2 | 'use strict'; |
| 3 | |
| 4 | /** |
| 5 | * This is a namespaced port of SweetAlert2 to avoid conflicts with other versions. |
| 6 | * sweetalert2 v9.14.0 |
| 7 | * Released under the MIT License. |
| 8 | */ |
| 9 | |
| 10 | /* eslint-disable prefer-spread */ |
| 11 | /* eslint-disable prefer-rest-params */ |
| 12 | /* eslint-disable guard-for-in */ |
| 13 | /* eslint-disable new-cap */ |
| 14 | (function (global, factory) { |
| 15 | typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global = global || self, global.wpstgSweetalert2 = factory()); |
| 16 | })(undefined, function () { |
| 17 | |
| 18 | function _typeof(obj) { |
| 19 | '@babel/helpers - typeof'; |
| 20 | |
| 21 | if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { |
| 22 | _typeof = function _typeof(obj) { |
| 23 | return typeof obj; |
| 24 | }; |
| 25 | } else { |
| 26 | _typeof = function _typeof(obj) { |
| 27 | return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj; |
| 28 | }; |
| 29 | } |
| 30 | return _typeof(obj); |
| 31 | } |
| 32 | function _classCallCheck(instance, Constructor) { |
| 33 | if (!(instance instanceof Constructor)) { |
| 34 | throw new TypeError('Cannot call a class as a function'); |
| 35 | } |
| 36 | } |
| 37 | function _defineProperties(target, props) { |
| 38 | for (var i = 0; i < props.length; i++) { |
| 39 | var descriptor = props[i]; |
| 40 | descriptor.enumerable = descriptor.enumerable || false; |
| 41 | descriptor.configurable = true; |
| 42 | if ('value' in descriptor) descriptor.writable = true; |
| 43 | Object.defineProperty(target, descriptor.key, descriptor); |
| 44 | } |
| 45 | } |
| 46 | function _createClass(Constructor, protoProps, staticProps) { |
| 47 | if (protoProps) _defineProperties(Constructor.prototype, protoProps); |
| 48 | if (staticProps) _defineProperties(Constructor, staticProps); |
| 49 | return Constructor; |
| 50 | } |
| 51 | function _extends() { |
| 52 | _extends = Object.assign || function (target) { |
| 53 | for (var i = 1; i < arguments.length; i++) { |
| 54 | var source = arguments[i]; |
| 55 | for (var key in source) { |
| 56 | if (Object.prototype.hasOwnProperty.call(source, key)) { |
| 57 | target[key] = source[key]; |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | return target; |
| 62 | }; |
| 63 | return _extends.apply(this, arguments); |
| 64 | } |
| 65 | function _inherits(subClass, superClass) { |
| 66 | if (typeof superClass !== 'function' && superClass !== null) { |
| 67 | throw new TypeError('Super expression must either be null or a function'); |
| 68 | } |
| 69 | subClass.prototype = Object.create(superClass && superClass.prototype, { |
| 70 | constructor: { |
| 71 | value: subClass, |
| 72 | writable: true, |
| 73 | configurable: true |
| 74 | } |
| 75 | }); |
| 76 | if (superClass) _setPrototypeOf(subClass, superClass); |
| 77 | } |
| 78 | function _getPrototypeOf(o) { |
| 79 | _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { |
| 80 | return o.__proto__ || Object.getPrototypeOf(o); |
| 81 | }; |
| 82 | return _getPrototypeOf(o); |
| 83 | } |
| 84 | function _setPrototypeOf(o, p) { |
| 85 | _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { |
| 86 | o.__proto__ = p; |
| 87 | return o; |
| 88 | }; |
| 89 | return _setPrototypeOf(o, p); |
| 90 | } |
| 91 | function _isNativeReflectConstruct() { |
| 92 | if (typeof Reflect === 'undefined' || !Reflect.construct) return false; |
| 93 | if (Reflect.construct.sham) return false; |
| 94 | if (typeof Proxy === 'function') return true; |
| 95 | try { |
| 96 | Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); |
| 97 | return true; |
| 98 | } catch (e) { |
| 99 | return false; |
| 100 | } |
| 101 | } |
| 102 | function _construct(Parent, args, Class) { |
| 103 | if (_isNativeReflectConstruct()) { |
| 104 | _construct = Reflect.construct; |
| 105 | } else { |
| 106 | _construct = function _construct(Parent, args, Class) { |
| 107 | var a = [null]; |
| 108 | a.push.apply(a, args); |
| 109 | var Constructor = Function.bind.apply(Parent, a); |
| 110 | var instance = new Constructor(); |
| 111 | if (Class) _setPrototypeOf(instance, Class.prototype); |
| 112 | return instance; |
| 113 | }; |
| 114 | } |
| 115 | return _construct.apply(null, arguments); |
| 116 | } |
| 117 | function _assertThisInitialized(self) { |
| 118 | if (self === void 0) { |
| 119 | throw new ReferenceError('this hasn\'t been initialised - super() hasn\'t been called'); |
| 120 | } |
| 121 | return self; |
| 122 | } |
| 123 | function _possibleConstructorReturn(self, call) { |
| 124 | if (call && (typeof call === 'object' || typeof call === 'function')) { |
| 125 | return call; |
| 126 | } |
| 127 | return _assertThisInitialized(self); |
| 128 | } |
| 129 | function _createSuper(Derived) { |
| 130 | var hasNativeReflectConstruct = _isNativeReflectConstruct(); |
| 131 | return function _createSuperInternal() { |
| 132 | var Super = _getPrototypeOf(Derived); |
| 133 | var result; |
| 134 | if (hasNativeReflectConstruct) { |
| 135 | var NewTarget = _getPrototypeOf(this).constructor; |
| 136 | result = Reflect.construct(Super, arguments, NewTarget); |
| 137 | } else { |
| 138 | result = Super.apply(this, arguments); |
| 139 | } |
| 140 | return _possibleConstructorReturn(this, result); |
| 141 | }; |
| 142 | } |
| 143 | function _superPropBase(object, property) { |
| 144 | while (!Object.prototype.hasOwnProperty.call(object, property)) { |
| 145 | object = _getPrototypeOf(object); |
| 146 | if (object === null) break; |
| 147 | } |
| 148 | return object; |
| 149 | } |
| 150 | function _get(target, property, receiver) { |
| 151 | if (typeof Reflect !== 'undefined' && Reflect.get) { |
| 152 | _get = Reflect.get; |
| 153 | } else { |
| 154 | _get = function _get(target, property, receiver) { |
| 155 | var base = _superPropBase(target, property); |
| 156 | if (!base) return; |
| 157 | var desc = Object.getOwnPropertyDescriptor(base, property); |
| 158 | if (desc.get) { |
| 159 | return desc.get.call(receiver); |
| 160 | } |
| 161 | return desc.value; |
| 162 | }; |
| 163 | } |
| 164 | return _get(target, property, receiver || target); |
| 165 | } |
| 166 | var consolePrefix = 'SweetAlert2:'; |
| 167 | /** |
| 168 | * Filter the unique values into a new array |
| 169 | * @param arr |
| 170 | */ |
| 171 | |
| 172 | var uniqueArray = function uniqueArray(arr) { |
| 173 | var result = []; |
| 174 | for (var i = 0; i < arr.length; i++) { |
| 175 | if (result.indexOf(arr[i]) === -1) { |
| 176 | result.push(arr[i]); |
| 177 | } |
| 178 | } |
| 179 | return result; |
| 180 | }; |
| 181 | /** |
| 182 | * Capitalize the first letter of a string |
| 183 | * @param str |
| 184 | */ |
| 185 | |
| 186 | var capitalizeFirstLetter = function capitalizeFirstLetter(str) { |
| 187 | return str.charAt(0).toUpperCase() + str.slice(1); |
| 188 | }; |
| 189 | /** |
| 190 | * Returns the array ob object values (Object.values isn't supported in IE11) |
| 191 | * @param obj |
| 192 | */ |
| 193 | |
| 194 | var objectValues = function objectValues(obj) { |
| 195 | return Object.keys(obj).map(function (key) { |
| 196 | return obj[key]; |
| 197 | }); |
| 198 | }; |
| 199 | /** |
| 200 | * Convert NodeList to Array |
| 201 | * @param nodeList |
| 202 | */ |
| 203 | |
| 204 | var toArray = function toArray(nodeList) { |
| 205 | return Array.prototype.slice.call(nodeList); |
| 206 | }; |
| 207 | /** |
| 208 | * Standardise console warnings |
| 209 | * @param message |
| 210 | */ |
| 211 | |
| 212 | var warn = function warn(message) { |
| 213 | console.warn(''.concat(consolePrefix, ' ').concat(message)); |
| 214 | }; |
| 215 | /** |
| 216 | * Standardise console errors |
| 217 | * @param message |
| 218 | */ |
| 219 | |
| 220 | var error = function error(message) { |
| 221 | console.error(''.concat(consolePrefix, ' ').concat(message)); |
| 222 | }; |
| 223 | /** |
| 224 | * Private global state for `warnOnce` |
| 225 | * @type {Array} |
| 226 | * @private |
| 227 | */ |
| 228 | |
| 229 | var previousWarnOnceMessages = []; |
| 230 | /** |
| 231 | * Show a console warning, but only if it hasn't already been shown |
| 232 | * @param message |
| 233 | */ |
| 234 | |
| 235 | var warnOnce = function warnOnce(message) { |
| 236 | if (!(previousWarnOnceMessages.indexOf(message) !== -1)) { |
| 237 | previousWarnOnceMessages.push(message); |
| 238 | warn(message); |
| 239 | } |
| 240 | }; |
| 241 | /** |
| 242 | * Show a one-time console warning about deprecated params/methods |
| 243 | */ |
| 244 | |
| 245 | var warnAboutDepreation = function warnAboutDepreation(deprecatedParam, useInstead) { |
| 246 | warnOnce('"'.concat(deprecatedParam, '" is deprecated and will be removed in the next major release. Please use "').concat(useInstead, '" instead.')); |
| 247 | }; |
| 248 | /** |
| 249 | * If `arg` is a function, call it (with no arguments or context) and return the result. |
| 250 | * Otherwise, just pass the value through |
| 251 | * @param arg |
| 252 | */ |
| 253 | |
| 254 | var callIfFunction = function callIfFunction(arg) { |
| 255 | return typeof arg === 'function' ? arg() : arg; |
| 256 | }; |
| 257 | var isPromise = function isPromise(arg) { |
| 258 | return arg && Promise.resolve(arg) === arg; |
| 259 | }; |
| 260 | var DismissReason = Object.freeze({ |
| 261 | cancel: 'cancel', |
| 262 | backdrop: 'backdrop', |
| 263 | close: 'close', |
| 264 | esc: 'esc', |
| 265 | timer: 'timer' |
| 266 | }); |
| 267 | var isJqueryElement = function isJqueryElement(elem) { |
| 268 | return _typeof(elem) === 'object' && elem.jquery; |
| 269 | }; |
| 270 | var isElement = function isElement(elem) { |
| 271 | return elem instanceof Element || isJqueryElement(elem); |
| 272 | }; |
| 273 | var argsToParams = function argsToParams(args) { |
| 274 | var params = {}; |
| 275 | if (_typeof(args[0]) === 'object' && !isElement(args[0])) { |
| 276 | _extends(params, args[0]); |
| 277 | } else { |
| 278 | ['title', 'html', 'icon'].forEach(function (name, index) { |
| 279 | var arg = args[index]; |
| 280 | if (typeof arg === 'string' || isElement(arg)) { |
| 281 | params[name] = arg; |
| 282 | } else if (arg !== undefined) { |
| 283 | error('Unexpected type of '.concat(name, '! Expected "string" or "Element", got ').concat(_typeof(arg))); |
| 284 | } |
| 285 | }); |
| 286 | } |
| 287 | return params; |
| 288 | }; |
| 289 | var swalPrefix = 'wpstg--swal2-'; |
| 290 | var prefix = function prefix(items) { |
| 291 | var result = {}; |
| 292 | for (var i in items) { |
| 293 | result[items[i]] = swalPrefix + items[i]; |
| 294 | } |
| 295 | return result; |
| 296 | }; |
| 297 | var swalClasses = prefix(['container', 'shown', 'height-auto', 'iosfix', 'popup', 'modal', 'no-backdrop', 'no-transition', 'toast', 'toast-shown', 'toast-column', 'show', 'hide', 'close', 'title', 'header', 'content', 'html-container', 'actions', 'confirm', 'cancel', 'footer', 'icon', 'icon-content', 'image', 'input', 'file', 'range', 'select', 'radio', 'checkbox', 'label', 'textarea', 'inputerror', 'validation-message', 'progress-steps', 'active-progress-step', 'progress-step', 'progress-step-line', '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']); |
| 298 | var iconTypes = prefix(['success', 'warning', 'info', 'question', 'error']); |
| 299 | var getContainer = function getContainer() { |
| 300 | return document.body.querySelector('.'.concat(swalClasses.container)); |
| 301 | }; |
| 302 | var elementBySelector = function elementBySelector(selectorString) { |
| 303 | var container = getContainer(); |
| 304 | return container ? container.querySelector(selectorString) : null; |
| 305 | }; |
| 306 | var elementByClass = function elementByClass(className) { |
| 307 | return elementBySelector('.'.concat(className)); |
| 308 | }; |
| 309 | var getPopup = function getPopup() { |
| 310 | return elementByClass(swalClasses.popup); |
| 311 | }; |
| 312 | var getIcons = function getIcons() { |
| 313 | var popup = getPopup(); |
| 314 | return toArray(popup.querySelectorAll('.'.concat(swalClasses.icon))); |
| 315 | }; |
| 316 | var getIcon = function getIcon() { |
| 317 | var visibleIcon = getIcons().filter(function (icon) { |
| 318 | return isVisible(icon); |
| 319 | }); |
| 320 | return visibleIcon.length ? visibleIcon[0] : null; |
| 321 | }; |
| 322 | var getTitle = function getTitle() { |
| 323 | return elementByClass(swalClasses.title); |
| 324 | }; |
| 325 | var getContent = function getContent() { |
| 326 | return elementByClass(swalClasses.content); |
| 327 | }; |
| 328 | var getHtmlContainer = function getHtmlContainer() { |
| 329 | return elementByClass(swalClasses['html-container']); |
| 330 | }; |
| 331 | var getImage = function getImage() { |
| 332 | return elementByClass(swalClasses.image); |
| 333 | }; |
| 334 | var getProgressSteps = function getProgressSteps() { |
| 335 | return elementByClass(swalClasses['progress-steps']); |
| 336 | }; |
| 337 | var getValidationMessage = function getValidationMessage() { |
| 338 | return elementByClass(swalClasses['validation-message']); |
| 339 | }; |
| 340 | var getConfirmButton = function getConfirmButton() { |
| 341 | return elementBySelector('.'.concat(swalClasses.actions, ' .').concat(swalClasses.confirm)); |
| 342 | }; |
| 343 | var getCancelButton = function getCancelButton() { |
| 344 | return elementBySelector('.'.concat(swalClasses.actions, ' .').concat(swalClasses.cancel)); |
| 345 | }; |
| 346 | var getActions = function getActions() { |
| 347 | return elementByClass(swalClasses.actions); |
| 348 | }; |
| 349 | var getHeader = function getHeader() { |
| 350 | return elementByClass(swalClasses.header); |
| 351 | }; |
| 352 | var getFooter = function getFooter() { |
| 353 | return elementByClass(swalClasses.footer); |
| 354 | }; |
| 355 | var getTimerProgressBar = function getTimerProgressBar() { |
| 356 | return elementByClass(swalClasses['timer-progress-bar']); |
| 357 | }; |
| 358 | var getCloseButton = function getCloseButton() { |
| 359 | return elementByClass(swalClasses.close); |
| 360 | }; // https://github.com/jkup/focusable/blob/master/index.js |
| 361 | |
| 362 | 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'; |
| 363 | var getFocusableElements = function getFocusableElements() { |
| 364 | var focusableElementsWithTabindex = toArray(getPopup().querySelectorAll('[tabindex]:not([tabindex="-1"]):not([tabindex="0"])')) // sort according to tabindex |
| 365 | .sort(function (a, b) { |
| 366 | a = parseInt(a.getAttribute('tabindex')); |
| 367 | b = parseInt(b.getAttribute('tabindex')); |
| 368 | if (a > b) { |
| 369 | return 1; |
| 370 | } else if (a < b) { |
| 371 | return -1; |
| 372 | } |
| 373 | return 0; |
| 374 | }); |
| 375 | var otherFocusableElements = toArray(getPopup().querySelectorAll(focusable)).filter(function (el) { |
| 376 | return el.getAttribute('tabindex') !== '-1'; |
| 377 | }); |
| 378 | return uniqueArray(focusableElementsWithTabindex.concat(otherFocusableElements)).filter(function (el) { |
| 379 | return isVisible(el); |
| 380 | }); |
| 381 | }; |
| 382 | var isModal = function isModal() { |
| 383 | return !isToast() && !document.body.classList.contains(swalClasses['no-backdrop']); |
| 384 | }; |
| 385 | var isToast = function isToast() { |
| 386 | return document.body.classList.contains(swalClasses['toast-shown']); |
| 387 | }; |
| 388 | var isLoading = function isLoading() { |
| 389 | return getPopup().hasAttribute('data-loading'); |
| 390 | }; |
| 391 | var states = { |
| 392 | previousBodyPadding: null |
| 393 | }; |
| 394 | var setInnerHtml = function setInnerHtml(elem, html) { |
| 395 | // #1926 |
| 396 | elem.textContent = ''; |
| 397 | if (html) { |
| 398 | var parser = new DOMParser(); |
| 399 | var parsed = parser.parseFromString(html, 'text/html'); |
| 400 | toArray(parsed.querySelector('head').childNodes).forEach(function (child) { |
| 401 | elem.appendChild(child); |
| 402 | }); |
| 403 | toArray(parsed.querySelector('body').childNodes).forEach(function (child) { |
| 404 | elem.appendChild(child); |
| 405 | }); |
| 406 | } |
| 407 | }; |
| 408 | var hasClass = function hasClass(elem, className) { |
| 409 | if (!className) { |
| 410 | return false; |
| 411 | } |
| 412 | var classList = className.split(/\s+/); |
| 413 | for (var i = 0; i < classList.length; i++) { |
| 414 | if (!elem.classList.contains(classList[i])) { |
| 415 | return false; |
| 416 | } |
| 417 | } |
| 418 | return true; |
| 419 | }; |
| 420 | var removeCustomClasses = function removeCustomClasses(elem, params) { |
| 421 | toArray(elem.classList).forEach(function (className) { |
| 422 | if (!(objectValues(swalClasses).indexOf(className) !== -1) && !(objectValues(iconTypes).indexOf(className) !== -1) && !(objectValues(params.showClass).indexOf(className) !== -1)) { |
| 423 | elem.classList.remove(className); |
| 424 | } |
| 425 | }); |
| 426 | }; |
| 427 | var applyCustomClass = function applyCustomClass(elem, params, className) { |
| 428 | removeCustomClasses(elem, params); |
| 429 | if (params.customClass && params.customClass[className]) { |
| 430 | if (typeof params.customClass[className] !== 'string' && !params.customClass[className].forEach) { |
| 431 | return warn('Invalid type of customClass.'.concat(className, '! Expected string or iterable object, got "').concat(_typeof(params.customClass[className]), '"')); |
| 432 | } |
| 433 | addClass(elem, params.customClass[className]); |
| 434 | } |
| 435 | }; |
| 436 | function getInput(content, inputType) { |
| 437 | if (!inputType) { |
| 438 | return null; |
| 439 | } |
| 440 | switch (inputType) { |
| 441 | case 'select': |
| 442 | case 'textarea': |
| 443 | case 'file': |
| 444 | return getChildByClass(content, swalClasses[inputType]); |
| 445 | case 'checkbox': |
| 446 | return content.querySelector('.'.concat(swalClasses.checkbox, ' input')); |
| 447 | case 'radio': |
| 448 | return content.querySelector('.'.concat(swalClasses.radio, ' input:checked')) || content.querySelector('.'.concat(swalClasses.radio, ' input:first-child')); |
| 449 | case 'range': |
| 450 | return content.querySelector('.'.concat(swalClasses.range, ' input')); |
| 451 | default: |
| 452 | return getChildByClass(content, swalClasses.input); |
| 453 | } |
| 454 | } |
| 455 | var focusInput = function focusInput(input) { |
| 456 | input.focus(); // place cursor at end of text in text input |
| 457 | |
| 458 | if (input.type !== 'file') { |
| 459 | // http://stackoverflow.com/a/2345915 |
| 460 | var val = input.value; |
| 461 | input.value = ''; |
| 462 | input.value = val; |
| 463 | } |
| 464 | }; |
| 465 | var toggleClass = function toggleClass(target, classList, condition) { |
| 466 | if (!target || !classList) { |
| 467 | return; |
| 468 | } |
| 469 | if (typeof classList === 'string') { |
| 470 | classList = classList.split(/\s+/).filter(Boolean); |
| 471 | } |
| 472 | classList.forEach(function (className) { |
| 473 | if (target.forEach) { |
| 474 | target.forEach(function (elem) { |
| 475 | condition ? elem.classList.add(className) : elem.classList.remove(className); |
| 476 | }); |
| 477 | } else { |
| 478 | condition ? target.classList.add(className) : target.classList.remove(className); |
| 479 | } |
| 480 | }); |
| 481 | }; |
| 482 | var addClass = function addClass(target, classList) { |
| 483 | toggleClass(target, classList, true); |
| 484 | }; |
| 485 | var removeClass = function removeClass(target, classList) { |
| 486 | toggleClass(target, classList, false); |
| 487 | }; |
| 488 | var getChildByClass = function getChildByClass(elem, className) { |
| 489 | for (var i = 0; i < elem.childNodes.length; i++) { |
| 490 | if (hasClass(elem.childNodes[i], className)) { |
| 491 | return elem.childNodes[i]; |
| 492 | } |
| 493 | } |
| 494 | }; |
| 495 | var applyNumericalStyle = function applyNumericalStyle(elem, property, value) { |
| 496 | if (value || parseInt(value) === 0) { |
| 497 | elem.style[property] = typeof value === 'number' ? ''.concat(value, 'px') : value; |
| 498 | } else { |
| 499 | elem.style.removeProperty(property); |
| 500 | } |
| 501 | }; |
| 502 | var show = function show(elem) { |
| 503 | var display = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'flex'; |
| 504 | elem.style.opacity = ''; |
| 505 | elem.style.display = display; |
| 506 | }; |
| 507 | var hide = function hide(elem) { |
| 508 | elem.style.opacity = ''; |
| 509 | elem.style.display = 'none'; |
| 510 | }; |
| 511 | var toggle = function toggle(elem, condition, display) { |
| 512 | condition ? show(elem, display) : hide(elem); |
| 513 | }; // borrowed from jquery $(elem).is(':visible') implementation |
| 514 | |
| 515 | var isVisible = function isVisible(elem) { |
| 516 | return !!(elem && (elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length)); |
| 517 | }; |
| 518 | /* istanbul ignore next */ |
| 519 | |
| 520 | var isScrollable = function isScrollable(elem) { |
| 521 | return !!(elem.scrollHeight > elem.clientHeight); |
| 522 | }; // borrowed from https://stackoverflow.com/a/46352119 |
| 523 | |
| 524 | var hasCssAnimation = function hasCssAnimation(elem) { |
| 525 | var style = window.getComputedStyle(elem); |
| 526 | var animDuration = parseFloat(style.getPropertyValue('animation-duration') || '0'); |
| 527 | var transDuration = parseFloat(style.getPropertyValue('transition-duration') || '0'); |
| 528 | return animDuration > 0 || transDuration > 0; |
| 529 | }; |
| 530 | var contains = function contains(haystack, needle) { |
| 531 | if (typeof haystack.contains === 'function') { |
| 532 | return haystack.contains(needle); |
| 533 | } |
| 534 | }; |
| 535 | var animateTimerProgressBar = function animateTimerProgressBar(timer) { |
| 536 | var reset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; |
| 537 | var timerProgressBar = getTimerProgressBar(); |
| 538 | if (isVisible(timerProgressBar)) { |
| 539 | if (reset) { |
| 540 | timerProgressBar.style.transition = 'none'; |
| 541 | timerProgressBar.style.width = '100%'; |
| 542 | } |
| 543 | setTimeout(function () { |
| 544 | timerProgressBar.style.transition = 'width '.concat(timer / 1000, 's linear'); |
| 545 | timerProgressBar.style.width = '0%'; |
| 546 | }, 10); |
| 547 | } |
| 548 | }; |
| 549 | var stopTimerProgressBar = function stopTimerProgressBar() { |
| 550 | var timerProgressBar = getTimerProgressBar(); |
| 551 | var timerProgressBarWidth = parseInt(window.getComputedStyle(timerProgressBar).width); |
| 552 | timerProgressBar.style.removeProperty('transition'); |
| 553 | timerProgressBar.style.width = '100%'; |
| 554 | var timerProgressBarFullWidth = parseInt(window.getComputedStyle(timerProgressBar).width); |
| 555 | var timerProgressBarPercent = parseInt(timerProgressBarWidth / timerProgressBarFullWidth * 100); |
| 556 | timerProgressBar.style.removeProperty('transition'); |
| 557 | timerProgressBar.style.width = ''.concat(timerProgressBarPercent, '%'); |
| 558 | }; |
| 559 | |
| 560 | // Detect Node env |
| 561 | var isNodeEnv = function isNodeEnv() { |
| 562 | return typeof window === 'undefined' || typeof document === 'undefined'; |
| 563 | }; |
| 564 | 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, ' ').concat(iconTypes.error, '"></div>\n <div class="').concat(swalClasses.icon, ' ').concat(iconTypes.question, '"></div>\n <div class="').concat(swalClasses.icon, ' ').concat(iconTypes.warning, '"></div>\n <div class="').concat(swalClasses.icon, ' ').concat(iconTypes.info, '"></div>\n <div class="').concat(swalClasses.icon, ' ').concat(iconTypes.success, '"></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 <button type="button" class="').concat(swalClasses.confirm, '">OK</button>\n <button type="button" class="').concat(swalClasses.cancel, '">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, ''); |
| 565 | var resetOldContainer = function resetOldContainer() { |
| 566 | var oldContainer = getContainer(); |
| 567 | if (!oldContainer) { |
| 568 | return false; |
| 569 | } |
| 570 | oldContainer.parentNode.removeChild(oldContainer); |
| 571 | removeClass([document.documentElement, document.body], [swalClasses['no-backdrop'], swalClasses['toast-shown'], swalClasses['has-column']]); |
| 572 | return true; |
| 573 | }; |
| 574 | var oldInputVal; // IE11 workaround, see #1109 for details |
| 575 | |
| 576 | var resetValidationMessage = function resetValidationMessage(e) { |
| 577 | if (wpstgSwal.isVisible() && oldInputVal !== e.target.value) { |
| 578 | wpstgSwal.resetValidationMessage(); |
| 579 | } |
| 580 | oldInputVal = e.target.value; |
| 581 | }; |
| 582 | var addInputChangeListeners = function addInputChangeListeners() { |
| 583 | var content = getContent(); |
| 584 | var input = getChildByClass(content, swalClasses.input); |
| 585 | var file = getChildByClass(content, swalClasses.file); |
| 586 | var range = content.querySelector('.'.concat(swalClasses.range, ' input')); |
| 587 | var rangeOutput = content.querySelector('.'.concat(swalClasses.range, ' output')); |
| 588 | var select = getChildByClass(content, swalClasses.select); |
| 589 | var checkbox = content.querySelector('.'.concat(swalClasses.checkbox, ' input')); |
| 590 | var textarea = getChildByClass(content, swalClasses.textarea); |
| 591 | input.oninput = resetValidationMessage; |
| 592 | file.onchange = resetValidationMessage; |
| 593 | select.onchange = resetValidationMessage; |
| 594 | checkbox.onchange = resetValidationMessage; |
| 595 | textarea.oninput = resetValidationMessage; |
| 596 | range.oninput = function (e) { |
| 597 | resetValidationMessage(e); |
| 598 | rangeOutput.value = range.value; |
| 599 | }; |
| 600 | range.onchange = function (e) { |
| 601 | resetValidationMessage(e); |
| 602 | range.nextSibling.value = range.value; |
| 603 | }; |
| 604 | }; |
| 605 | var getTarget = function getTarget(target) { |
| 606 | return typeof target === 'string' ? document.querySelector(target) : target; |
| 607 | }; |
| 608 | var setupAccessibility = function setupAccessibility(params) { |
| 609 | var popup = getPopup(); |
| 610 | popup.setAttribute('role', params.toast ? 'alert' : 'dialog'); |
| 611 | popup.setAttribute('aria-live', params.toast ? 'polite' : 'assertive'); |
| 612 | if (!params.toast) { |
| 613 | popup.setAttribute('aria-modal', 'true'); |
| 614 | } |
| 615 | }; |
| 616 | var setupRTL = function setupRTL(targetElement) { |
| 617 | if (window.getComputedStyle(targetElement).direction === 'rtl') { |
| 618 | addClass(getContainer(), swalClasses.rtl); |
| 619 | } |
| 620 | }; |
| 621 | /* |
| 622 | * Add modal + backdrop to DOM |
| 623 | */ |
| 624 | |
| 625 | var init = function init(params) { |
| 626 | // Clean up the old popup container if it exists |
| 627 | var oldContainerExisted = resetOldContainer(); |
| 628 | /* istanbul ignore if */ |
| 629 | |
| 630 | if (isNodeEnv()) { |
| 631 | error('SweetAlert2 requires document to initialize'); |
| 632 | return; |
| 633 | } |
| 634 | var container = document.createElement('div'); |
| 635 | container.className = swalClasses.container; |
| 636 | if (oldContainerExisted) { |
| 637 | addClass(container, swalClasses['no-transition']); |
| 638 | } |
| 639 | setInnerHtml(container, sweetHTML); |
| 640 | var targetElement = getTarget(params.target); |
| 641 | targetElement.appendChild(container); |
| 642 | setupAccessibility(params); |
| 643 | setupRTL(targetElement); |
| 644 | addInputChangeListeners(); |
| 645 | }; |
| 646 | var parseHtmlToContainer = function parseHtmlToContainer(param, target) { |
| 647 | // DOM element |
| 648 | if (param instanceof HTMLElement) { |
| 649 | target.appendChild(param); // Object |
| 650 | } else if (_typeof(param) === 'object') { |
| 651 | handleObject(param, target); // Plain string |
| 652 | } else if (param) { |
| 653 | setInnerHtml(target, param); |
| 654 | } |
| 655 | }; |
| 656 | var handleObject = function handleObject(param, target) { |
| 657 | // JQuery element(s) |
| 658 | if (param.jquery) { |
| 659 | handleJqueryElem(target, param); // For other objects use their string representation |
| 660 | } else { |
| 661 | setInnerHtml(target, param.toString()); |
| 662 | } |
| 663 | }; |
| 664 | var handleJqueryElem = function handleJqueryElem(target, elem) { |
| 665 | target.textContent = ''; |
| 666 | if (0 in elem) { |
| 667 | for (var i = 0; (i in elem); i++) { |
| 668 | target.appendChild(elem[i].cloneNode(true)); |
| 669 | } |
| 670 | } else { |
| 671 | target.appendChild(elem.cloneNode(true)); |
| 672 | } |
| 673 | }; |
| 674 | var animationEndEvent = function () { |
| 675 | // Prevent run in Node env |
| 676 | |
| 677 | /* istanbul ignore if */ |
| 678 | if (isNodeEnv()) { |
| 679 | return false; |
| 680 | } |
| 681 | var testEl = document.createElement('div'); |
| 682 | var transEndEventNames = { |
| 683 | WebkitAnimation: 'webkitAnimationEnd', |
| 684 | OAnimation: 'oAnimationEnd oanimationend', |
| 685 | animation: 'animationend' |
| 686 | }; |
| 687 | for (var i in transEndEventNames) { |
| 688 | if (Object.prototype.hasOwnProperty.call(transEndEventNames, i) && typeof testEl.style[i] !== 'undefined') { |
| 689 | return transEndEventNames[i]; |
| 690 | } |
| 691 | } |
| 692 | return false; |
| 693 | }(); |
| 694 | |
| 695 | // https://github.com/twbs/bootstrap/blob/master/js/src/modal.js |
| 696 | |
| 697 | var measureScrollbar = function measureScrollbar() { |
| 698 | var scrollDiv = document.createElement('div'); |
| 699 | scrollDiv.className = swalClasses['scrollbar-measure']; |
| 700 | document.body.appendChild(scrollDiv); |
| 701 | var scrollbarWidth = scrollDiv.getBoundingClientRect().width - scrollDiv.clientWidth; |
| 702 | document.body.removeChild(scrollDiv); |
| 703 | return scrollbarWidth; |
| 704 | }; |
| 705 | var renderActions = function renderActions(instance, params) { |
| 706 | var actions = getActions(); |
| 707 | var confirmButton = getConfirmButton(); |
| 708 | var cancelButton = getCancelButton(); // Actions (buttons) wrapper |
| 709 | |
| 710 | if (!params.showConfirmButton && !params.showCancelButton) { |
| 711 | hide(actions); |
| 712 | } // Custom class |
| 713 | |
| 714 | applyCustomClass(actions, params, 'actions'); // Render confirm button |
| 715 | |
| 716 | renderButton(confirmButton, 'confirm', params); // render Cancel Button |
| 717 | |
| 718 | renderButton(cancelButton, 'cancel', params); |
| 719 | if (params.buttonsStyling) { |
| 720 | handleButtonsStyling(confirmButton, cancelButton, params); |
| 721 | } else { |
| 722 | removeClass([confirmButton, cancelButton], swalClasses.styled); |
| 723 | confirmButton.style.backgroundColor = confirmButton.style.borderLeftColor = confirmButton.style.borderRightColor = ''; |
| 724 | cancelButton.style.backgroundColor = cancelButton.style.borderLeftColor = cancelButton.style.borderRightColor = ''; |
| 725 | } |
| 726 | if (params.reverseButtons) { |
| 727 | confirmButton.parentNode.insertBefore(cancelButton, confirmButton); |
| 728 | } |
| 729 | }; |
| 730 | function handleButtonsStyling(confirmButton, cancelButton, params) { |
| 731 | addClass([confirmButton, cancelButton], swalClasses.styled); // Buttons background colors |
| 732 | |
| 733 | if (params.confirmButtonColor) { |
| 734 | confirmButton.style.backgroundColor = params.confirmButtonColor; |
| 735 | } |
| 736 | if (params.cancelButtonColor) { |
| 737 | cancelButton.style.backgroundColor = params.cancelButtonColor; |
| 738 | } // Loading state |
| 739 | |
| 740 | if (!isLoading()) { |
| 741 | var confirmButtonBackgroundColor = window.getComputedStyle(confirmButton).getPropertyValue('background-color'); |
| 742 | confirmButton.style.borderLeftColor = confirmButtonBackgroundColor; |
| 743 | confirmButton.style.borderRightColor = confirmButtonBackgroundColor; |
| 744 | } |
| 745 | } |
| 746 | function renderButton(button, buttonType, params) { |
| 747 | toggle(button, params['show'.concat(capitalizeFirstLetter(buttonType), 'Button')], 'inline-block'); |
| 748 | setInnerHtml(button, params[''.concat(buttonType, 'ButtonText')]); // Set caption text |
| 749 | |
| 750 | button.setAttribute('aria-label', params[''.concat(buttonType, 'ButtonAriaLabel')]); // ARIA label |
| 751 | // Add buttons custom classes |
| 752 | |
| 753 | button.className = swalClasses[buttonType]; |
| 754 | applyCustomClass(button, params, ''.concat(buttonType, 'Button')); |
| 755 | addClass(button, params[''.concat(buttonType, 'ButtonClass')]); |
| 756 | } |
| 757 | function handleBackdropParam(container, backdrop) { |
| 758 | if (typeof backdrop === 'string') { |
| 759 | container.style.background = backdrop; |
| 760 | } else if (!backdrop) { |
| 761 | addClass([document.documentElement, document.body], swalClasses['no-backdrop']); |
| 762 | } |
| 763 | } |
| 764 | function handlePositionParam(container, position) { |
| 765 | if (position in swalClasses) { |
| 766 | addClass(container, swalClasses[position]); |
| 767 | } else { |
| 768 | warn('The "position" parameter is not valid, defaulting to "center"'); |
| 769 | addClass(container, swalClasses.center); |
| 770 | } |
| 771 | } |
| 772 | function handleGrowParam(container, grow) { |
| 773 | if (grow && typeof grow === 'string') { |
| 774 | var growClass = 'grow-'.concat(grow); |
| 775 | if (growClass in swalClasses) { |
| 776 | addClass(container, swalClasses[growClass]); |
| 777 | } |
| 778 | } |
| 779 | } |
| 780 | var renderContainer = function renderContainer(instance, params) { |
| 781 | var container = getContainer(); |
| 782 | if (!container) { |
| 783 | return; |
| 784 | } |
| 785 | handleBackdropParam(container, params.backdrop); |
| 786 | if (!params.backdrop && params.allowOutsideClick) { |
| 787 | warn('"allowOutsideClick" parameter requires `backdrop` parameter to be set to `true`'); |
| 788 | } |
| 789 | handlePositionParam(container, params.position); |
| 790 | handleGrowParam(container, params.grow); // Custom class |
| 791 | |
| 792 | applyCustomClass(container, params, 'container'); // Set queue step attribute for getQueueStep() method |
| 793 | |
| 794 | var queueStep = document.body.getAttribute('data-swal2-queue-step'); |
| 795 | if (queueStep) { |
| 796 | container.setAttribute('data-queue-step', queueStep); |
| 797 | document.body.removeAttribute('data-swal2-queue-step'); |
| 798 | } |
| 799 | }; |
| 800 | |
| 801 | /** |
| 802 | * This module containts `WeakMap`s for each effectively-"private property" that a `Swal` has. |
| 803 | * For example, to set the private property "foo" of `this` to "bar", you can `privateProps.foo.set(this, 'bar')` |
| 804 | * This is the approach that Babel will probably take to implement private methods/fields |
| 805 | * https://github.com/tc39/proposal-private-methods |
| 806 | * https://github.com/babel/babel/pull/7555 |
| 807 | * Once we have the changes from that PR in Babel, and our core class fits reasonable in *one module* |
| 808 | * then we can use that language feature. |
| 809 | */ |
| 810 | var privateProps = { |
| 811 | promise: new WeakMap(), |
| 812 | innerParams: new WeakMap(), |
| 813 | domCache: new WeakMap() |
| 814 | }; |
| 815 | var inputTypes = ['input', 'file', 'range', 'select', 'radio', 'checkbox', 'textarea']; |
| 816 | var renderInput = function renderInput(instance, params) { |
| 817 | var content = getContent(); |
| 818 | var innerParams = privateProps.innerParams.get(instance); |
| 819 | var rerender = !innerParams || params.input !== innerParams.input; |
| 820 | inputTypes.forEach(function (inputType) { |
| 821 | var inputClass = swalClasses[inputType]; |
| 822 | var inputContainer = getChildByClass(content, inputClass); // set attributes |
| 823 | |
| 824 | setAttributes(inputType, params.inputAttributes); // set class |
| 825 | |
| 826 | inputContainer.className = inputClass; |
| 827 | if (rerender) { |
| 828 | hide(inputContainer); |
| 829 | } |
| 830 | }); |
| 831 | if (params.input) { |
| 832 | if (rerender) { |
| 833 | showInput(params); |
| 834 | } // set custom class |
| 835 | |
| 836 | setCustomClass(params); |
| 837 | } |
| 838 | }; |
| 839 | var showInput = function showInput(params) { |
| 840 | if (!renderInputType[params.input]) { |
| 841 | return error('Unexpected type of input! Expected "text", "email", "password", "number", "tel", "select", "radio", "checkbox", "textarea", "file" or "url", got "'.concat(params.input, '"')); |
| 842 | } |
| 843 | var inputContainer = getInputContainer(params.input); |
| 844 | var input = renderInputType[params.input](inputContainer, params); |
| 845 | show(input); // input autofocus |
| 846 | |
| 847 | setTimeout(function () { |
| 848 | focusInput(input); |
| 849 | }); |
| 850 | }; |
| 851 | var removeAttributes = function removeAttributes(input) { |
| 852 | for (var i = 0; i < input.attributes.length; i++) { |
| 853 | var attrName = input.attributes[i].name; |
| 854 | if (!(['type', 'value', 'style'].indexOf(attrName) !== -1)) { |
| 855 | input.removeAttribute(attrName); |
| 856 | } |
| 857 | } |
| 858 | }; |
| 859 | var setAttributes = function setAttributes(inputType, inputAttributes) { |
| 860 | var input = getInput(getContent(), inputType); |
| 861 | if (!input) { |
| 862 | return; |
| 863 | } |
| 864 | removeAttributes(input); |
| 865 | for (var attr in inputAttributes) { |
| 866 | // Do not set a placeholder for <input type="range"> |
| 867 | // it'll crash Edge, #1298 |
| 868 | if (inputType === 'range' && attr === 'placeholder') { |
| 869 | continue; |
| 870 | } |
| 871 | input.setAttribute(attr, inputAttributes[attr]); |
| 872 | } |
| 873 | }; |
| 874 | var setCustomClass = function setCustomClass(params) { |
| 875 | var inputContainer = getInputContainer(params.input); |
| 876 | if (params.customClass) { |
| 877 | addClass(inputContainer, params.customClass.input); |
| 878 | } |
| 879 | }; |
| 880 | var setInputPlaceholder = function setInputPlaceholder(input, params) { |
| 881 | if (!input.placeholder || params.inputPlaceholder) { |
| 882 | input.placeholder = params.inputPlaceholder; |
| 883 | } |
| 884 | }; |
| 885 | var getInputContainer = function getInputContainer(inputType) { |
| 886 | var inputClass = swalClasses[inputType] ? swalClasses[inputType] : swalClasses.input; |
| 887 | return getChildByClass(getContent(), inputClass); |
| 888 | }; |
| 889 | var renderInputType = {}; |
| 890 | renderInputType.text = renderInputType.email = renderInputType.password = renderInputType.number = renderInputType.tel = renderInputType.url = function (input, params) { |
| 891 | if (typeof params.inputValue === 'string' || typeof params.inputValue === 'number') { |
| 892 | input.value = params.inputValue; |
| 893 | } else if (!isPromise(params.inputValue)) { |
| 894 | warn('Unexpected type of inputValue! Expected "string", "number" or "Promise", got "'.concat(_typeof(params.inputValue), '"')); |
| 895 | } |
| 896 | setInputPlaceholder(input, params); |
| 897 | input.type = params.input; |
| 898 | return input; |
| 899 | }; |
| 900 | renderInputType.file = function (input, params) { |
| 901 | setInputPlaceholder(input, params); |
| 902 | return input; |
| 903 | }; |
| 904 | renderInputType.range = function (range, params) { |
| 905 | var rangeInput = range.querySelector('input'); |
| 906 | var rangeOutput = range.querySelector('output'); |
| 907 | rangeInput.value = params.inputValue; |
| 908 | rangeInput.type = params.input; |
| 909 | rangeOutput.value = params.inputValue; |
| 910 | return range; |
| 911 | }; |
| 912 | renderInputType.select = function (select, params) { |
| 913 | select.textContent = ''; |
| 914 | if (params.inputPlaceholder) { |
| 915 | var placeholder = document.createElement('option'); |
| 916 | setInnerHtml(placeholder, params.inputPlaceholder); |
| 917 | placeholder.value = ''; |
| 918 | placeholder.disabled = true; |
| 919 | placeholder.selected = true; |
| 920 | select.appendChild(placeholder); |
| 921 | } |
| 922 | return select; |
| 923 | }; |
| 924 | renderInputType.radio = function (radio) { |
| 925 | radio.textContent = ''; |
| 926 | return radio; |
| 927 | }; |
| 928 | renderInputType.checkbox = function (checkboxContainer, params) { |
| 929 | var checkbox = getInput(getContent(), 'checkbox'); |
| 930 | checkbox.value = 1; |
| 931 | checkbox.id = swalClasses.checkbox; |
| 932 | checkbox.checked = Boolean(params.inputValue); |
| 933 | var label = checkboxContainer.querySelector('span'); |
| 934 | setInnerHtml(label, params.inputPlaceholder); |
| 935 | return checkboxContainer; |
| 936 | }; |
| 937 | renderInputType.textarea = function (textarea, params) { |
| 938 | textarea.value = params.inputValue; |
| 939 | setInputPlaceholder(textarea, params); |
| 940 | if ('MutationObserver' in window) { |
| 941 | // #1699 |
| 942 | var initialPopupWidth = parseInt(window.getComputedStyle(getPopup()).width); |
| 943 | var popupPadding = parseInt(window.getComputedStyle(getPopup()).paddingLeft) + parseInt(window.getComputedStyle(getPopup()).paddingRight); |
| 944 | var outputsize = function outputsize() { |
| 945 | var contentWidth = textarea.offsetWidth + popupPadding; |
| 946 | if (contentWidth > initialPopupWidth) { |
| 947 | getPopup().style.width = ''.concat(contentWidth, 'px'); |
| 948 | } else { |
| 949 | getPopup().style.width = null; |
| 950 | } |
| 951 | }; |
| 952 | new MutationObserver(outputsize).observe(textarea, { |
| 953 | attributes: true, |
| 954 | attributeFilter: ['style'] |
| 955 | }); |
| 956 | } |
| 957 | return textarea; |
| 958 | }; |
| 959 | var renderContent = function renderContent(instance, params) { |
| 960 | var content = getContent().querySelector('#'.concat(swalClasses.content)); // Content as HTML |
| 961 | |
| 962 | if (params.html) { |
| 963 | parseHtmlToContainer(params.html, content); |
| 964 | show(content, 'block'); // Content as plain text |
| 965 | } else if (params.text) { |
| 966 | content.textContent = params.text; |
| 967 | show(content, 'block'); // No content |
| 968 | } else { |
| 969 | hide(content); |
| 970 | } |
| 971 | renderInput(instance, params); // Custom class |
| 972 | |
| 973 | applyCustomClass(getContent(), params, 'content'); |
| 974 | }; |
| 975 | var renderFooter = function renderFooter(instance, params) { |
| 976 | var footer = getFooter(); |
| 977 | toggle(footer, params.footer); |
| 978 | if (params.footer) { |
| 979 | parseHtmlToContainer(params.footer, footer); |
| 980 | } // Custom class |
| 981 | |
| 982 | applyCustomClass(footer, params, 'footer'); |
| 983 | }; |
| 984 | var renderCloseButton = function renderCloseButton(instance, params) { |
| 985 | var closeButton = getCloseButton(); |
| 986 | setInnerHtml(closeButton, params.closeButtonHtml); // Custom class |
| 987 | |
| 988 | applyCustomClass(closeButton, params, 'closeButton'); |
| 989 | toggle(closeButton, params.showCloseButton); |
| 990 | closeButton.setAttribute('aria-label', params.closeButtonAriaLabel); |
| 991 | }; |
| 992 | var renderIcon = function renderIcon(instance, params) { |
| 993 | var innerParams = privateProps.innerParams.get(instance); // if the give icon already rendered, apply the custom class without re-rendering the icon |
| 994 | |
| 995 | if (innerParams && params.icon === innerParams.icon && getIcon()) { |
| 996 | applyCustomClass(getIcon(), params, 'icon'); |
| 997 | return; |
| 998 | } |
| 999 | hideAllIcons(); |
| 1000 | if (!params.icon) { |
| 1001 | return; |
| 1002 | } |
| 1003 | if (Object.keys(iconTypes).indexOf(params.icon) !== -1) { |
| 1004 | var icon = elementBySelector('.'.concat(swalClasses.icon, '.').concat(iconTypes[params.icon])); |
| 1005 | show(icon); // Custom or default content |
| 1006 | |
| 1007 | setContent(icon, params); |
| 1008 | adjustSuccessIconBackgoundColor(); // Custom class |
| 1009 | |
| 1010 | applyCustomClass(icon, params, 'icon'); // Animate icon |
| 1011 | |
| 1012 | addClass(icon, params.showClass.icon); |
| 1013 | } else { |
| 1014 | error('Unknown icon! Expected "success", "error", "warning", "info" or "question", got "'.concat(params.icon, '"')); |
| 1015 | } |
| 1016 | }; |
| 1017 | var hideAllIcons = function hideAllIcons() { |
| 1018 | var icons = getIcons(); |
| 1019 | for (var i = 0; i < icons.length; i++) { |
| 1020 | hide(icons[i]); |
| 1021 | } |
| 1022 | }; // Adjust success icon background color to match the popup background color |
| 1023 | |
| 1024 | var adjustSuccessIconBackgoundColor = function adjustSuccessIconBackgoundColor() { |
| 1025 | var popup = getPopup(); |
| 1026 | var popupBackgroundColor = window.getComputedStyle(popup).getPropertyValue('background-color'); |
| 1027 | var successIconParts = popup.querySelectorAll('[class^=wpstg--swal2-success-circular-line], .wpstg--swal2-success-fix'); |
| 1028 | for (var i = 0; i < successIconParts.length; i++) { |
| 1029 | successIconParts[i].style.backgroundColor = popupBackgroundColor; |
| 1030 | } |
| 1031 | }; |
| 1032 | var setContent = function setContent(icon, params) { |
| 1033 | icon.textContent = ''; |
| 1034 | if (params.iconHtml) { |
| 1035 | setInnerHtml(icon, iconContent(params.iconHtml)); |
| 1036 | } else if (params.icon === 'success') { |
| 1037 | setInnerHtml(icon, '\n <div class="wpstg--swal2-success-circular-line-left"></div>\n <span class="wpstg--swal2-success-line-tip"></span> <span class="wpstg--swal2-success-line-long"></span>\n <div class="wpstg--swal2-success-ring"></div> <div class="wpstg--swal2-success-fix"></div>\n <div class="wpstg--swal2-success-circular-line-right"></div>\n '); |
| 1038 | } else if (params.icon === 'error') { |
| 1039 | setInnerHtml(icon, '\n <span class="wpstg--swal2-x-mark">\n <span class="wpstg--swal2-x-mark-line-left"></span>\n <span class="wpstg--swal2-x-mark-line-right"></span>\n </span>\n '); |
| 1040 | } else { |
| 1041 | var defaultIconHtml = { |
| 1042 | question: '?', |
| 1043 | warning: '!', |
| 1044 | info: 'i' |
| 1045 | }; |
| 1046 | setInnerHtml(icon, iconContent(defaultIconHtml[params.icon])); |
| 1047 | } |
| 1048 | }; |
| 1049 | var iconContent = function iconContent(content) { |
| 1050 | return '<div class="'.concat(swalClasses['icon-content'], '">').concat(content, '</div>'); |
| 1051 | }; |
| 1052 | var renderImage = function renderImage(instance, params) { |
| 1053 | var image = getImage(); |
| 1054 | if (!params.imageUrl) { |
| 1055 | return hide(image); |
| 1056 | } |
| 1057 | show(image, ''); // Src, alt |
| 1058 | |
| 1059 | image.setAttribute('src', params.imageUrl); |
| 1060 | image.setAttribute('alt', params.imageAlt); // Width, height |
| 1061 | |
| 1062 | applyNumericalStyle(image, 'width', params.imageWidth); |
| 1063 | applyNumericalStyle(image, 'height', params.imageHeight); // Class |
| 1064 | |
| 1065 | image.className = swalClasses.image; |
| 1066 | applyCustomClass(image, params, 'image'); |
| 1067 | }; |
| 1068 | var currentSteps = []; |
| 1069 | /* |
| 1070 | * Global function for chaining sweetAlert popups |
| 1071 | */ |
| 1072 | |
| 1073 | var queue = function queue(steps) { |
| 1074 | var Swal = this; |
| 1075 | currentSteps = steps; |
| 1076 | var resetAndResolve = function resetAndResolve(resolve, value) { |
| 1077 | currentSteps = []; |
| 1078 | resolve(value); |
| 1079 | }; |
| 1080 | var queueResult = []; |
| 1081 | return new Promise(function (resolve) { |
| 1082 | (function step(i, callback) { |
| 1083 | if (i < currentSteps.length) { |
| 1084 | document.body.setAttribute('data-swal2-queue-step', i); |
| 1085 | Swal.fire(currentSteps[i]).then(function (result) { |
| 1086 | if (typeof result.value !== 'undefined') { |
| 1087 | queueResult.push(result.value); |
| 1088 | step(i + 1); |
| 1089 | } else { |
| 1090 | resetAndResolve(resolve, { |
| 1091 | dismiss: result.dismiss |
| 1092 | }); |
| 1093 | } |
| 1094 | }); |
| 1095 | } else { |
| 1096 | resetAndResolve(resolve, { |
| 1097 | value: queueResult |
| 1098 | }); |
| 1099 | } |
| 1100 | })(0); |
| 1101 | }); |
| 1102 | }; |
| 1103 | /* |
| 1104 | * Global function for getting the index of current popup in queue |
| 1105 | */ |
| 1106 | |
| 1107 | var getQueueStep = function getQueueStep() { |
| 1108 | return getContainer() && getContainer().getAttribute('data-queue-step'); |
| 1109 | }; |
| 1110 | /* |
| 1111 | * Global function for inserting a popup to the queue |
| 1112 | */ |
| 1113 | |
| 1114 | var insertQueueStep = function insertQueueStep(step, index) { |
| 1115 | if (index && index < currentSteps.length) { |
| 1116 | return currentSteps.splice(index, 0, step); |
| 1117 | } |
| 1118 | return currentSteps.push(step); |
| 1119 | }; |
| 1120 | /* |
| 1121 | * Global function for deleting a popup from the queue |
| 1122 | */ |
| 1123 | |
| 1124 | var deleteQueueStep = function deleteQueueStep(index) { |
| 1125 | if (typeof currentSteps[index] !== 'undefined') { |
| 1126 | currentSteps.splice(index, 1); |
| 1127 | } |
| 1128 | }; |
| 1129 | var createStepElement = function createStepElement(step) { |
| 1130 | var stepEl = document.createElement('li'); |
| 1131 | addClass(stepEl, swalClasses['progress-step']); |
| 1132 | setInnerHtml(stepEl, step); |
| 1133 | return stepEl; |
| 1134 | }; |
| 1135 | var createLineElement = function createLineElement(params) { |
| 1136 | var lineEl = document.createElement('li'); |
| 1137 | addClass(lineEl, swalClasses['progress-step-line']); |
| 1138 | if (params.progressStepsDistance) { |
| 1139 | lineEl.style.width = params.progressStepsDistance; |
| 1140 | } |
| 1141 | return lineEl; |
| 1142 | }; |
| 1143 | var renderProgressSteps = function renderProgressSteps(instance, params) { |
| 1144 | var progressStepsContainer = getProgressSteps(); |
| 1145 | if (!params.progressSteps || params.progressSteps.length === 0) { |
| 1146 | return hide(progressStepsContainer); |
| 1147 | } |
| 1148 | show(progressStepsContainer); |
| 1149 | progressStepsContainer.textContent = ''; |
| 1150 | var currentProgressStep = parseInt(params.currentProgressStep === undefined ? getQueueStep() : params.currentProgressStep); |
| 1151 | if (currentProgressStep >= params.progressSteps.length) { |
| 1152 | warn('Invalid currentProgressStep parameter, it should be less than progressSteps.length ' + '(currentProgressStep like JS arrays starts from 0)'); |
| 1153 | } |
| 1154 | params.progressSteps.forEach(function (step, index) { |
| 1155 | var stepEl = createStepElement(step); |
| 1156 | progressStepsContainer.appendChild(stepEl); |
| 1157 | if (index === currentProgressStep) { |
| 1158 | addClass(stepEl, swalClasses['active-progress-step']); |
| 1159 | } |
| 1160 | if (index !== params.progressSteps.length - 1) { |
| 1161 | var lineEl = createLineElement(step); |
| 1162 | progressStepsContainer.appendChild(lineEl); |
| 1163 | } |
| 1164 | }); |
| 1165 | }; |
| 1166 | var renderTitle = function renderTitle(instance, params) { |
| 1167 | var title = getTitle(); |
| 1168 | toggle(title, params.title || params.titleText); |
| 1169 | if (params.title) { |
| 1170 | parseHtmlToContainer(params.title, title); |
| 1171 | } |
| 1172 | if (params.titleText) { |
| 1173 | title.innerText = params.titleText; |
| 1174 | } // Custom class |
| 1175 | |
| 1176 | applyCustomClass(title, params, 'title'); |
| 1177 | }; |
| 1178 | var renderHeader = function renderHeader(instance, params) { |
| 1179 | var header = getHeader(); // Custom class |
| 1180 | |
| 1181 | applyCustomClass(header, params, 'header'); // Progress steps |
| 1182 | |
| 1183 | renderProgressSteps(instance, params); // Icon |
| 1184 | |
| 1185 | renderIcon(instance, params); // Image |
| 1186 | |
| 1187 | renderImage(instance, params); // Title |
| 1188 | |
| 1189 | renderTitle(instance, params); // Close button |
| 1190 | |
| 1191 | renderCloseButton(instance, params); |
| 1192 | }; |
| 1193 | var renderPopup = function renderPopup(instance, params) { |
| 1194 | var popup = getPopup(); // Width |
| 1195 | |
| 1196 | applyNumericalStyle(popup, 'width', params.width); // Padding |
| 1197 | |
| 1198 | applyNumericalStyle(popup, 'padding', params.padding); // Background |
| 1199 | |
| 1200 | if (params.background) { |
| 1201 | popup.style.background = params.background; |
| 1202 | } // Classes |
| 1203 | |
| 1204 | addClasses(popup, params); |
| 1205 | }; |
| 1206 | var addClasses = function addClasses(popup, params) { |
| 1207 | // Default Class + showClass when updating Swal.update({}) |
| 1208 | popup.className = ''.concat(swalClasses.popup, ' ').concat(isVisible(popup) ? params.showClass.popup : ''); |
| 1209 | if (params.toast) { |
| 1210 | addClass([document.documentElement, document.body], swalClasses['toast-shown']); |
| 1211 | addClass(popup, swalClasses.toast); |
| 1212 | } else { |
| 1213 | addClass(popup, swalClasses.modal); |
| 1214 | } // Custom class |
| 1215 | |
| 1216 | applyCustomClass(popup, params, 'popup'); |
| 1217 | if (typeof params.customClass === 'string') { |
| 1218 | addClass(popup, params.customClass); |
| 1219 | } // Icon class (#1842) |
| 1220 | |
| 1221 | if (params.icon) { |
| 1222 | addClass(popup, swalClasses['icon-'.concat(params.icon)]); |
| 1223 | } |
| 1224 | }; |
| 1225 | var render = function render(instance, params) { |
| 1226 | renderPopup(instance, params); |
| 1227 | renderContainer(instance, params); |
| 1228 | renderHeader(instance, params); |
| 1229 | renderContent(instance, params); |
| 1230 | renderActions(instance, params); |
| 1231 | renderFooter(instance, params); |
| 1232 | if (typeof params.onRender === 'function') { |
| 1233 | params.onRender(getPopup()); |
| 1234 | } |
| 1235 | }; |
| 1236 | |
| 1237 | /* |
| 1238 | * Global function to determine if SweetAlert2 popup is shown |
| 1239 | */ |
| 1240 | |
| 1241 | var isVisible$1 = function isVisible$$1() { |
| 1242 | return isVisible(getPopup()); |
| 1243 | }; |
| 1244 | /* |
| 1245 | * Global function to click 'Confirm' button |
| 1246 | */ |
| 1247 | |
| 1248 | var clickConfirm = function clickConfirm() { |
| 1249 | return getConfirmButton() && getConfirmButton().click(); |
| 1250 | }; |
| 1251 | /* |
| 1252 | * Global function to click 'Cancel' button |
| 1253 | */ |
| 1254 | |
| 1255 | var clickCancel = function clickCancel() { |
| 1256 | return getCancelButton() && getCancelButton().click(); |
| 1257 | }; |
| 1258 | function fire() { |
| 1259 | var Swal = this; |
| 1260 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { |
| 1261 | args[_key] = arguments[_key]; |
| 1262 | } |
| 1263 | return _construct(Swal, args); |
| 1264 | } |
| 1265 | |
| 1266 | /** |
| 1267 | * Returns an extended version of `Swal` containing `params` as defaults. |
| 1268 | * Useful for reusing Swal configuration. |
| 1269 | * |
| 1270 | * For example: |
| 1271 | * |
| 1272 | * Before: |
| 1273 | * const textPromptOptions = { input: 'text', showCancelButton: true } |
| 1274 | * const {value: firstName} = await Swal.fire({ ...textPromptOptions, title: 'What is your first name?' }) |
| 1275 | * const {value: lastName} = await Swal.fire({ ...textPromptOptions, title: 'What is your last name?' }) |
| 1276 | * |
| 1277 | * After: |
| 1278 | * const TextPrompt = Swal.mixin({ input: 'text', showCancelButton: true }) |
| 1279 | * const {value: firstName} = await TextPrompt('What is your first name?') |
| 1280 | * const {value: lastName} = await TextPrompt('What is your last name?') |
| 1281 | * |
| 1282 | * @param mixinParams |
| 1283 | */ |
| 1284 | function mixin(mixinParams) { |
| 1285 | var MixinSwal = /* #__PURE__*/function (_this) { |
| 1286 | _inherits(MixinSwal, _this); |
| 1287 | var _super = _createSuper(MixinSwal); |
| 1288 | function MixinSwal() { |
| 1289 | _classCallCheck(this, MixinSwal); |
| 1290 | return _super.apply(this, arguments); |
| 1291 | } |
| 1292 | _createClass(MixinSwal, [{ |
| 1293 | key: '_main', |
| 1294 | value: function _main(params) { |
| 1295 | return _get(_getPrototypeOf(MixinSwal.prototype), '_main', this).call(this, _extends({}, mixinParams, params)); |
| 1296 | } |
| 1297 | }]); |
| 1298 | return MixinSwal; |
| 1299 | }(this); |
| 1300 | return MixinSwal; |
| 1301 | } |
| 1302 | |
| 1303 | /** |
| 1304 | * Show spinner instead of Confirm button |
| 1305 | */ |
| 1306 | |
| 1307 | var showLoading = function showLoading() { |
| 1308 | var popup = getPopup(); |
| 1309 | if (!popup) { |
| 1310 | wpstgSwal.fire(); |
| 1311 | } |
| 1312 | popup = getPopup(); |
| 1313 | var actions = getActions(); |
| 1314 | var confirmButton = getConfirmButton(); |
| 1315 | show(actions); |
| 1316 | show(confirmButton, 'inline-block'); |
| 1317 | addClass([popup, actions], swalClasses.loading); |
| 1318 | confirmButton.disabled = true; |
| 1319 | popup.setAttribute('data-loading', true); |
| 1320 | popup.setAttribute('aria-busy', true); |
| 1321 | popup.focus(); |
| 1322 | }; |
| 1323 | var RESTORE_FOCUS_TIMEOUT = 100; |
| 1324 | var globalState = {}; |
| 1325 | var focusPreviousActiveElement = function focusPreviousActiveElement() { |
| 1326 | if (globalState.previousActiveElement && globalState.previousActiveElement.focus) { |
| 1327 | globalState.previousActiveElement.focus(); |
| 1328 | globalState.previousActiveElement = null; |
| 1329 | } else if (document.body) { |
| 1330 | document.body.focus(); |
| 1331 | } |
| 1332 | }; // Restore previous active (focused) element |
| 1333 | |
| 1334 | var restoreActiveElement = function restoreActiveElement() { |
| 1335 | return new Promise(function (resolve) { |
| 1336 | var x = window.scrollX; |
| 1337 | var y = window.scrollY; |
| 1338 | globalState.restoreFocusTimeout = setTimeout(function () { |
| 1339 | focusPreviousActiveElement(); |
| 1340 | resolve(); |
| 1341 | }, RESTORE_FOCUS_TIMEOUT); // issues/900 |
| 1342 | |
| 1343 | /* istanbul ignore if */ |
| 1344 | |
| 1345 | if (typeof x !== 'undefined' && typeof y !== 'undefined') { |
| 1346 | // IE doesn't have scrollX/scrollY support |
| 1347 | window.scrollTo(x, y); |
| 1348 | } |
| 1349 | }); |
| 1350 | }; |
| 1351 | |
| 1352 | /** |
| 1353 | * If `timer` parameter is set, returns number of milliseconds of timer remained. |
| 1354 | * Otherwise, returns undefined. |
| 1355 | */ |
| 1356 | |
| 1357 | var getTimerLeft = function getTimerLeft() { |
| 1358 | return globalState.timeout && globalState.timeout.getTimerLeft(); |
| 1359 | }; |
| 1360 | /** |
| 1361 | * Stop timer. Returns number of milliseconds of timer remained. |
| 1362 | * If `timer` parameter isn't set, returns undefined. |
| 1363 | */ |
| 1364 | |
| 1365 | var stopTimer = function stopTimer() { |
| 1366 | if (globalState.timeout) { |
| 1367 | stopTimerProgressBar(); |
| 1368 | return globalState.timeout.stop(); |
| 1369 | } |
| 1370 | }; |
| 1371 | /** |
| 1372 | * Resume timer. Returns number of milliseconds of timer remained. |
| 1373 | * If `timer` parameter isn't set, returns undefined. |
| 1374 | */ |
| 1375 | |
| 1376 | var resumeTimer = function resumeTimer() { |
| 1377 | if (globalState.timeout) { |
| 1378 | var remaining = globalState.timeout.start(); |
| 1379 | animateTimerProgressBar(remaining); |
| 1380 | return remaining; |
| 1381 | } |
| 1382 | }; |
| 1383 | /** |
| 1384 | * Resume timer. Returns number of milliseconds of timer remained. |
| 1385 | * If `timer` parameter isn't set, returns undefined. |
| 1386 | */ |
| 1387 | |
| 1388 | var toggleTimer = function toggleTimer() { |
| 1389 | var timer = globalState.timeout; |
| 1390 | return timer && (timer.running ? stopTimer() : resumeTimer()); |
| 1391 | }; |
| 1392 | /** |
| 1393 | * Increase timer. Returns number of milliseconds of an updated timer. |
| 1394 | * If `timer` parameter isn't set, returns undefined. |
| 1395 | */ |
| 1396 | |
| 1397 | var increaseTimer = function increaseTimer(n) { |
| 1398 | if (globalState.timeout) { |
| 1399 | var remaining = globalState.timeout.increase(n); |
| 1400 | animateTimerProgressBar(remaining, true); |
| 1401 | return remaining; |
| 1402 | } |
| 1403 | }; |
| 1404 | /** |
| 1405 | * Check if timer is running. Returns true if timer is running |
| 1406 | * or false if timer is paused or stopped. |
| 1407 | * If `timer` parameter isn't set, returns undefined |
| 1408 | */ |
| 1409 | |
| 1410 | var isTimerRunning = function isTimerRunning() { |
| 1411 | return globalState.timeout && globalState.timeout.isRunning(); |
| 1412 | }; |
| 1413 | var defaultParams = { |
| 1414 | title: '', |
| 1415 | titleText: '', |
| 1416 | text: '', |
| 1417 | html: '', |
| 1418 | footer: '', |
| 1419 | icon: undefined, |
| 1420 | iconHtml: undefined, |
| 1421 | toast: false, |
| 1422 | animation: true, |
| 1423 | showClass: { |
| 1424 | popup: 'wpstg--swal2-show', |
| 1425 | backdrop: 'wpstg--swal2-backdrop-show', |
| 1426 | icon: 'wpstg--swal2-icon-show' |
| 1427 | }, |
| 1428 | hideClass: { |
| 1429 | popup: 'wpstg--swal2-hide', |
| 1430 | backdrop: 'wpstg--swal2-backdrop-hide', |
| 1431 | icon: 'wpstg--swal2-icon-hide' |
| 1432 | }, |
| 1433 | customClass: undefined, |
| 1434 | target: 'body', |
| 1435 | backdrop: true, |
| 1436 | heightAuto: true, |
| 1437 | allowOutsideClick: true, |
| 1438 | allowEscapeKey: true, |
| 1439 | allowEnterKey: true, |
| 1440 | stopKeydownPropagation: true, |
| 1441 | keydownListenerCapture: false, |
| 1442 | showConfirmButton: true, |
| 1443 | showCancelButton: false, |
| 1444 | preConfirm: undefined, |
| 1445 | confirmButtonText: 'OK', |
| 1446 | confirmButtonAriaLabel: '', |
| 1447 | confirmButtonColor: undefined, |
| 1448 | cancelButtonText: 'Cancel', |
| 1449 | cancelButtonAriaLabel: '', |
| 1450 | cancelButtonColor: undefined, |
| 1451 | buttonsStyling: true, |
| 1452 | reverseButtons: false, |
| 1453 | focusConfirm: true, |
| 1454 | focusCancel: false, |
| 1455 | showCloseButton: false, |
| 1456 | closeButtonHtml: '×', |
| 1457 | closeButtonAriaLabel: 'Close this dialog', |
| 1458 | showLoaderOnConfirm: false, |
| 1459 | imageUrl: undefined, |
| 1460 | imageWidth: undefined, |
| 1461 | imageHeight: undefined, |
| 1462 | imageAlt: '', |
| 1463 | timer: undefined, |
| 1464 | timerProgressBar: false, |
| 1465 | width: undefined, |
| 1466 | padding: undefined, |
| 1467 | background: undefined, |
| 1468 | input: undefined, |
| 1469 | inputPlaceholder: '', |
| 1470 | inputValue: '', |
| 1471 | inputOptions: {}, |
| 1472 | inputAutoTrim: true, |
| 1473 | inputAttributes: {}, |
| 1474 | inputValidator: undefined, |
| 1475 | validationMessage: undefined, |
| 1476 | grow: false, |
| 1477 | position: 'center', |
| 1478 | progressSteps: [], |
| 1479 | currentProgressStep: undefined, |
| 1480 | progressStepsDistance: undefined, |
| 1481 | onBeforeOpen: undefined, |
| 1482 | onOpen: undefined, |
| 1483 | onRender: undefined, |
| 1484 | onClose: undefined, |
| 1485 | onAfterClose: undefined, |
| 1486 | onDestroy: undefined, |
| 1487 | scrollbarPadding: true |
| 1488 | }; |
| 1489 | var updatableParams = ['title', 'titleText', 'text', 'html', 'footer', 'icon', 'hideClass', 'customClass', 'allowOutsideClick', 'allowEscapeKey', 'showConfirmButton', 'showCancelButton', 'confirmButtonText', 'confirmButtonAriaLabel', 'confirmButtonColor', 'cancelButtonText', 'cancelButtonAriaLabel', 'cancelButtonColor', 'buttonsStyling', 'reverseButtons', 'imageUrl', 'imageWidth', 'imageHeight', 'imageAlt', 'progressSteps', 'currentProgressStep', 'onClose', 'onAfterClose', 'onDestroy']; |
| 1490 | var deprecatedParams = { |
| 1491 | animation: 'showClass" and "hideClass' |
| 1492 | }; |
| 1493 | var toastIncompatibleParams = ['allowOutsideClick', 'allowEnterKey', 'backdrop', 'focusConfirm', 'focusCancel', 'heightAuto', 'keydownListenerCapture']; |
| 1494 | /** |
| 1495 | * Is valid parameter |
| 1496 | * @param {String} paramName |
| 1497 | */ |
| 1498 | |
| 1499 | var isValidParameter = function isValidParameter(paramName) { |
| 1500 | return Object.prototype.hasOwnProperty.call(defaultParams, paramName); |
| 1501 | }; |
| 1502 | /** |
| 1503 | * Is valid parameter for Swal.update() method |
| 1504 | * @param {String} paramName |
| 1505 | */ |
| 1506 | |
| 1507 | var isUpdatableParameter = function isUpdatableParameter(paramName) { |
| 1508 | return updatableParams.indexOf(paramName) !== -1; |
| 1509 | }; |
| 1510 | /** |
| 1511 | * Is deprecated parameter |
| 1512 | * @param {String} paramName |
| 1513 | */ |
| 1514 | |
| 1515 | var isDeprecatedParameter = function isDeprecatedParameter(paramName) { |
| 1516 | return deprecatedParams[paramName]; |
| 1517 | }; |
| 1518 | var checkIfParamIsValid = function checkIfParamIsValid(param) { |
| 1519 | if (!isValidParameter(param)) { |
| 1520 | warn('Unknown parameter "'.concat(param, '"')); |
| 1521 | } |
| 1522 | }; |
| 1523 | var checkIfToastParamIsValid = function checkIfToastParamIsValid(param) { |
| 1524 | if (toastIncompatibleParams.indexOf(param) !== -1) { |
| 1525 | warn('The parameter "'.concat(param, '" is incompatible with toasts')); |
| 1526 | } |
| 1527 | }; |
| 1528 | var checkIfParamIsDeprecated = function checkIfParamIsDeprecated(param) { |
| 1529 | if (isDeprecatedParameter(param)) { |
| 1530 | warnAboutDepreation(param, isDeprecatedParameter(param)); |
| 1531 | } |
| 1532 | }; |
| 1533 | /** |
| 1534 | * Show relevant warnings for given params |
| 1535 | * |
| 1536 | * @param params |
| 1537 | */ |
| 1538 | |
| 1539 | var showWarningsForParams = function showWarningsForParams(params) { |
| 1540 | for (var param in params) { |
| 1541 | checkIfParamIsValid(param); |
| 1542 | if (params.toast) { |
| 1543 | checkIfToastParamIsValid(param); |
| 1544 | } |
| 1545 | checkIfParamIsDeprecated(param); |
| 1546 | } |
| 1547 | }; |
| 1548 | var staticMethods = /* #__PURE__*/Object.freeze({ |
| 1549 | isValidParameter: isValidParameter, |
| 1550 | isUpdatableParameter: isUpdatableParameter, |
| 1551 | isDeprecatedParameter: isDeprecatedParameter, |
| 1552 | argsToParams: argsToParams, |
| 1553 | isVisible: isVisible$1, |
| 1554 | clickConfirm: clickConfirm, |
| 1555 | clickCancel: clickCancel, |
| 1556 | getContainer: getContainer, |
| 1557 | getPopup: getPopup, |
| 1558 | getTitle: getTitle, |
| 1559 | getContent: getContent, |
| 1560 | getHtmlContainer: getHtmlContainer, |
| 1561 | getImage: getImage, |
| 1562 | getIcon: getIcon, |
| 1563 | getIcons: getIcons, |
| 1564 | getCloseButton: getCloseButton, |
| 1565 | getActions: getActions, |
| 1566 | getConfirmButton: getConfirmButton, |
| 1567 | getCancelButton: getCancelButton, |
| 1568 | getHeader: getHeader, |
| 1569 | getFooter: getFooter, |
| 1570 | getTimerProgressBar: getTimerProgressBar, |
| 1571 | getFocusableElements: getFocusableElements, |
| 1572 | getValidationMessage: getValidationMessage, |
| 1573 | isLoading: isLoading, |
| 1574 | fire: fire, |
| 1575 | mixin: mixin, |
| 1576 | queue: queue, |
| 1577 | getQueueStep: getQueueStep, |
| 1578 | insertQueueStep: insertQueueStep, |
| 1579 | deleteQueueStep: deleteQueueStep, |
| 1580 | showLoading: showLoading, |
| 1581 | enableLoading: showLoading, |
| 1582 | getTimerLeft: getTimerLeft, |
| 1583 | stopTimer: stopTimer, |
| 1584 | resumeTimer: resumeTimer, |
| 1585 | toggleTimer: toggleTimer, |
| 1586 | increaseTimer: increaseTimer, |
| 1587 | isTimerRunning: isTimerRunning |
| 1588 | }); |
| 1589 | |
| 1590 | /** |
| 1591 | * Enables buttons and hide loader. |
| 1592 | */ |
| 1593 | |
| 1594 | function hideLoading() { |
| 1595 | // do nothing if popup is closed |
| 1596 | var innerParams = privateProps.innerParams.get(this); |
| 1597 | if (!innerParams) { |
| 1598 | return; |
| 1599 | } |
| 1600 | var domCache = privateProps.domCache.get(this); |
| 1601 | if (!innerParams.showConfirmButton) { |
| 1602 | hide(domCache.confirmButton); |
| 1603 | if (!innerParams.showCancelButton) { |
| 1604 | hide(domCache.actions); |
| 1605 | } |
| 1606 | } |
| 1607 | removeClass([domCache.popup, domCache.actions], swalClasses.loading); |
| 1608 | domCache.popup.removeAttribute('aria-busy'); |
| 1609 | domCache.popup.removeAttribute('data-loading'); |
| 1610 | domCache.confirmButton.disabled = false; |
| 1611 | domCache.cancelButton.disabled = false; |
| 1612 | } |
| 1613 | function getInput$1(instance) { |
| 1614 | var innerParams = privateProps.innerParams.get(instance || this); |
| 1615 | var domCache = privateProps.domCache.get(instance || this); |
| 1616 | if (!domCache) { |
| 1617 | return null; |
| 1618 | } |
| 1619 | return getInput(domCache.content, innerParams.input); |
| 1620 | } |
| 1621 | var fixScrollbar = function fixScrollbar() { |
| 1622 | // for queues, do not do this more than once |
| 1623 | if (states.previousBodyPadding !== null) { |
| 1624 | return; |
| 1625 | } // if the body has overflow |
| 1626 | |
| 1627 | if (document.body.scrollHeight > window.innerHeight) { |
| 1628 | // add padding so the content doesn't shift after removal of scrollbar |
| 1629 | states.previousBodyPadding = parseInt(window.getComputedStyle(document.body).getPropertyValue('padding-right')); |
| 1630 | document.body.style.paddingRight = ''.concat(states.previousBodyPadding + measureScrollbar(), 'px'); |
| 1631 | } |
| 1632 | }; |
| 1633 | var undoScrollbar = function undoScrollbar() { |
| 1634 | if (states.previousBodyPadding !== null) { |
| 1635 | document.body.style.paddingRight = ''.concat(states.previousBodyPadding, 'px'); |
| 1636 | states.previousBodyPadding = null; |
| 1637 | } |
| 1638 | }; |
| 1639 | |
| 1640 | /* istanbul ignore file */ |
| 1641 | |
| 1642 | var iOSfix = function iOSfix() { |
| 1643 | var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream || navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1; |
| 1644 | if (iOS && !hasClass(document.body, swalClasses.iosfix)) { |
| 1645 | var offset = document.body.scrollTop; |
| 1646 | document.body.style.top = ''.concat(offset * -1, 'px'); |
| 1647 | addClass(document.body, swalClasses.iosfix); |
| 1648 | lockBodyScroll(); |
| 1649 | } |
| 1650 | }; |
| 1651 | var lockBodyScroll = function lockBodyScroll() { |
| 1652 | // #1246 |
| 1653 | var container = getContainer(); |
| 1654 | var preventTouchMove; |
| 1655 | container.ontouchstart = function (e) { |
| 1656 | preventTouchMove = shouldPreventTouchMove(e.target); |
| 1657 | }; |
| 1658 | container.ontouchmove = function (e) { |
| 1659 | if (preventTouchMove) { |
| 1660 | e.preventDefault(); |
| 1661 | e.stopPropagation(); |
| 1662 | } |
| 1663 | }; |
| 1664 | }; |
| 1665 | var shouldPreventTouchMove = function shouldPreventTouchMove(target) { |
| 1666 | var container = getContainer(); |
| 1667 | if (target === container) { |
| 1668 | return true; |
| 1669 | } |
| 1670 | if (!isScrollable(container) && target.tagName !== 'INPUT' && |
| 1671 | // #1603 |
| 1672 | !(isScrollable(getContent()) && |
| 1673 | // #1944 |
| 1674 | getContent().contains(target))) { |
| 1675 | return true; |
| 1676 | } |
| 1677 | return false; |
| 1678 | }; |
| 1679 | var undoIOSfix = function undoIOSfix() { |
| 1680 | if (hasClass(document.body, swalClasses.iosfix)) { |
| 1681 | var offset = parseInt(document.body.style.top, 10); |
| 1682 | removeClass(document.body, swalClasses.iosfix); |
| 1683 | document.body.style.top = ''; |
| 1684 | document.body.scrollTop = offset * -1; |
| 1685 | } |
| 1686 | }; |
| 1687 | |
| 1688 | /* istanbul ignore file */ |
| 1689 | |
| 1690 | var isIE11 = function isIE11() { |
| 1691 | return !!window.MSInputMethodContext && !!document.documentMode; |
| 1692 | }; // Fix IE11 centering sweetalert2/issues/933 |
| 1693 | |
| 1694 | var fixVerticalPositionIE = function fixVerticalPositionIE() { |
| 1695 | var container = getContainer(); |
| 1696 | var popup = getPopup(); |
| 1697 | container.style.removeProperty('align-items'); |
| 1698 | if (popup.offsetTop < 0) { |
| 1699 | container.style.alignItems = 'flex-start'; |
| 1700 | } |
| 1701 | }; |
| 1702 | var IEfix = function IEfix() { |
| 1703 | if (typeof window !== 'undefined' && isIE11()) { |
| 1704 | fixVerticalPositionIE(); |
| 1705 | window.addEventListener('resize', fixVerticalPositionIE); |
| 1706 | } |
| 1707 | }; |
| 1708 | var undoIEfix = function undoIEfix() { |
| 1709 | if (typeof window !== 'undefined' && isIE11()) { |
| 1710 | window.removeEventListener('resize', fixVerticalPositionIE); |
| 1711 | } |
| 1712 | }; |
| 1713 | |
| 1714 | // Adding aria-hidden="true" to elements outside of the active modal dialog ensures that |
| 1715 | // elements not within the active modal dialog will not be surfaced if a user opens a screen |
| 1716 | // reader’s list of elements (headings, form controls, landmarks, etc.) in the document. |
| 1717 | |
| 1718 | var setAriaHidden = function setAriaHidden() { |
| 1719 | var bodyChildren = toArray(document.body.children); |
| 1720 | bodyChildren.forEach(function (el) { |
| 1721 | if (el === getContainer() || contains(el, getContainer())) { |
| 1722 | return; |
| 1723 | } |
| 1724 | if (el.hasAttribute('aria-hidden')) { |
| 1725 | el.setAttribute('data-previous-aria-hidden', el.getAttribute('aria-hidden')); |
| 1726 | } |
| 1727 | el.setAttribute('aria-hidden', 'true'); |
| 1728 | }); |
| 1729 | }; |
| 1730 | var unsetAriaHidden = function unsetAriaHidden() { |
| 1731 | var bodyChildren = toArray(document.body.children); |
| 1732 | bodyChildren.forEach(function (el) { |
| 1733 | if (el.hasAttribute('data-previous-aria-hidden')) { |
| 1734 | el.setAttribute('aria-hidden', el.getAttribute('data-previous-aria-hidden')); |
| 1735 | el.removeAttribute('data-previous-aria-hidden'); |
| 1736 | } else { |
| 1737 | el.removeAttribute('aria-hidden'); |
| 1738 | } |
| 1739 | }); |
| 1740 | }; |
| 1741 | |
| 1742 | /** |
| 1743 | * This module containts `WeakMap`s for each effectively-"private property" that a `Swal` has. |
| 1744 | * For example, to set the private property "foo" of `this` to "bar", you can `privateProps.foo.set(this, 'bar')` |
| 1745 | * This is the approach that Babel will probably take to implement private methods/fields |
| 1746 | * https://github.com/tc39/proposal-private-methods |
| 1747 | * https://github.com/babel/babel/pull/7555 |
| 1748 | * Once we have the changes from that PR in Babel, and our core class fits reasonable in *one module* |
| 1749 | * then we can use that language feature. |
| 1750 | */ |
| 1751 | var privateMethods = { |
| 1752 | swalPromiseResolve: new WeakMap() |
| 1753 | }; |
| 1754 | |
| 1755 | /* |
| 1756 | * Instance method to close sweetAlert |
| 1757 | */ |
| 1758 | |
| 1759 | function removePopupAndResetState(instance, container, isToast$$1, onAfterClose) { |
| 1760 | if (isToast$$1) { |
| 1761 | triggerOnAfterCloseAndDispose(instance, onAfterClose); |
| 1762 | } else { |
| 1763 | restoreActiveElement().then(function () { |
| 1764 | return triggerOnAfterCloseAndDispose(instance, onAfterClose); |
| 1765 | }); |
| 1766 | globalState.keydownTarget.removeEventListener('keydown', globalState.keydownHandler, { |
| 1767 | capture: globalState.keydownListenerCapture |
| 1768 | }); |
| 1769 | globalState.keydownHandlerAdded = false; |
| 1770 | } |
| 1771 | if (container.parentNode && !document.body.getAttribute('data-swal2-queue-step')) { |
| 1772 | container.parentNode.removeChild(container); |
| 1773 | } |
| 1774 | if (isModal()) { |
| 1775 | undoScrollbar(); |
| 1776 | undoIOSfix(); |
| 1777 | undoIEfix(); |
| 1778 | unsetAriaHidden(); |
| 1779 | } |
| 1780 | removeBodyClasses(); |
| 1781 | } |
| 1782 | function removeBodyClasses() { |
| 1783 | removeClass([document.documentElement, document.body], [swalClasses.shown, swalClasses['height-auto'], swalClasses['no-backdrop'], swalClasses['toast-shown'], swalClasses['toast-column']]); |
| 1784 | } |
| 1785 | function close(resolveValue) { |
| 1786 | var popup = getPopup(); |
| 1787 | if (!popup) { |
| 1788 | return; |
| 1789 | } |
| 1790 | var innerParams = privateProps.innerParams.get(this); |
| 1791 | if (!innerParams || hasClass(popup, innerParams.hideClass.popup)) { |
| 1792 | return; |
| 1793 | } |
| 1794 | var swalPromiseResolve = privateMethods.swalPromiseResolve.get(this); |
| 1795 | removeClass(popup, innerParams.showClass.popup); |
| 1796 | addClass(popup, innerParams.hideClass.popup); |
| 1797 | var backdrop = getContainer(); |
| 1798 | removeClass(backdrop, innerParams.showClass.backdrop); |
| 1799 | addClass(backdrop, innerParams.hideClass.backdrop); |
| 1800 | handlePopupAnimation(this, popup, innerParams); |
| 1801 | if (typeof resolveValue !== 'undefined') { |
| 1802 | resolveValue.isDismissed = typeof resolveValue.dismiss !== 'undefined'; |
| 1803 | resolveValue.isConfirmed = typeof resolveValue.dismiss === 'undefined'; |
| 1804 | } else { |
| 1805 | resolveValue = { |
| 1806 | isDismissed: true, |
| 1807 | isConfirmed: false |
| 1808 | }; |
| 1809 | } // Resolve Swal promise |
| 1810 | |
| 1811 | swalPromiseResolve(resolveValue || {}); |
| 1812 | } |
| 1813 | var handlePopupAnimation = function handlePopupAnimation(instance, popup, innerParams) { |
| 1814 | var container = getContainer(); // If animation is supported, animate |
| 1815 | |
| 1816 | var animationIsSupported = animationEndEvent && hasCssAnimation(popup); |
| 1817 | var onClose = innerParams.onClose; |
| 1818 | var onAfterClose = innerParams.onAfterClose; |
| 1819 | if (onClose !== null && typeof onClose === 'function') { |
| 1820 | onClose(popup); |
| 1821 | } |
| 1822 | if (animationIsSupported) { |
| 1823 | animatePopup(instance, popup, container, onAfterClose); |
| 1824 | } else { |
| 1825 | // Otherwise, remove immediately |
| 1826 | removePopupAndResetState(instance, container, isToast(), onAfterClose); |
| 1827 | } |
| 1828 | }; |
| 1829 | var animatePopup = function animatePopup(instance, popup, container, onAfterClose) { |
| 1830 | globalState.swalCloseEventFinishedCallback = removePopupAndResetState.bind(null, instance, container, isToast(), onAfterClose); |
| 1831 | popup.addEventListener(animationEndEvent, function (e) { |
| 1832 | if (e.target === popup) { |
| 1833 | globalState.swalCloseEventFinishedCallback(); |
| 1834 | delete globalState.swalCloseEventFinishedCallback; |
| 1835 | } |
| 1836 | }); |
| 1837 | }; |
| 1838 | var triggerOnAfterCloseAndDispose = function triggerOnAfterCloseAndDispose(instance, onAfterClose) { |
| 1839 | setTimeout(function () { |
| 1840 | if (typeof onAfterClose === 'function') { |
| 1841 | onAfterClose(); |
| 1842 | } |
| 1843 | instance._destroy(); |
| 1844 | }); |
| 1845 | }; |
| 1846 | function setButtonsDisabled(instance, buttons, disabled) { |
| 1847 | var domCache = privateProps.domCache.get(instance); |
| 1848 | buttons.forEach(function (button) { |
| 1849 | domCache[button].disabled = disabled; |
| 1850 | }); |
| 1851 | } |
| 1852 | function setInputDisabled(input, disabled) { |
| 1853 | if (!input) { |
| 1854 | return false; |
| 1855 | } |
| 1856 | if (input.type === 'radio') { |
| 1857 | var radiosContainer = input.parentNode.parentNode; |
| 1858 | var radios = radiosContainer.querySelectorAll('input'); |
| 1859 | for (var i = 0; i < radios.length; i++) { |
| 1860 | radios[i].disabled = disabled; |
| 1861 | } |
| 1862 | } else { |
| 1863 | input.disabled = disabled; |
| 1864 | } |
| 1865 | } |
| 1866 | function enableButtons() { |
| 1867 | setButtonsDisabled(this, ['confirmButton', 'cancelButton'], false); |
| 1868 | } |
| 1869 | function disableButtons() { |
| 1870 | setButtonsDisabled(this, ['confirmButton', 'cancelButton'], true); |
| 1871 | } |
| 1872 | function enableInput() { |
| 1873 | return setInputDisabled(this.getInput(), false); |
| 1874 | } |
| 1875 | function disableInput() { |
| 1876 | return setInputDisabled(this.getInput(), true); |
| 1877 | } |
| 1878 | function showValidationMessage(error) { |
| 1879 | var domCache = privateProps.domCache.get(this); |
| 1880 | setInnerHtml(domCache.validationMessage, error); |
| 1881 | var popupComputedStyle = window.getComputedStyle(domCache.popup); |
| 1882 | domCache.validationMessage.style.marginLeft = '-'.concat(popupComputedStyle.getPropertyValue('padding-left')); |
| 1883 | domCache.validationMessage.style.marginRight = '-'.concat(popupComputedStyle.getPropertyValue('padding-right')); |
| 1884 | show(domCache.validationMessage); |
| 1885 | var input = this.getInput(); |
| 1886 | if (input) { |
| 1887 | input.setAttribute('aria-invalid', true); |
| 1888 | input.setAttribute('aria-describedBy', swalClasses['validation-message']); |
| 1889 | focusInput(input); |
| 1890 | addClass(input, swalClasses.inputerror); |
| 1891 | } |
| 1892 | } // Hide block with validation message |
| 1893 | |
| 1894 | function resetValidationMessage$1() { |
| 1895 | var domCache = privateProps.domCache.get(this); |
| 1896 | if (domCache.validationMessage) { |
| 1897 | hide(domCache.validationMessage); |
| 1898 | } |
| 1899 | var input = this.getInput(); |
| 1900 | if (input) { |
| 1901 | input.removeAttribute('aria-invalid'); |
| 1902 | input.removeAttribute('aria-describedBy'); |
| 1903 | removeClass(input, swalClasses.inputerror); |
| 1904 | } |
| 1905 | } |
| 1906 | function getProgressSteps$1() { |
| 1907 | var domCache = privateProps.domCache.get(this); |
| 1908 | return domCache.progressSteps; |
| 1909 | } |
| 1910 | var Timer = /* #__PURE__*/function () { |
| 1911 | function Timer(callback, delay) { |
| 1912 | _classCallCheck(this, Timer); |
| 1913 | this.callback = callback; |
| 1914 | this.remaining = delay; |
| 1915 | this.running = false; |
| 1916 | this.start(); |
| 1917 | } |
| 1918 | _createClass(Timer, [{ |
| 1919 | key: 'start', |
| 1920 | value: function start() { |
| 1921 | if (!this.running) { |
| 1922 | this.running = true; |
| 1923 | this.started = new Date(); |
| 1924 | this.id = setTimeout(this.callback, this.remaining); |
| 1925 | } |
| 1926 | return this.remaining; |
| 1927 | } |
| 1928 | }, { |
| 1929 | key: 'stop', |
| 1930 | value: function stop() { |
| 1931 | if (this.running) { |
| 1932 | this.running = false; |
| 1933 | clearTimeout(this.id); |
| 1934 | this.remaining -= new Date() - this.started; |
| 1935 | } |
| 1936 | return this.remaining; |
| 1937 | } |
| 1938 | }, { |
| 1939 | key: 'increase', |
| 1940 | value: function increase(n) { |
| 1941 | var running = this.running; |
| 1942 | if (running) { |
| 1943 | this.stop(); |
| 1944 | } |
| 1945 | this.remaining += n; |
| 1946 | if (running) { |
| 1947 | this.start(); |
| 1948 | } |
| 1949 | return this.remaining; |
| 1950 | } |
| 1951 | }, { |
| 1952 | key: 'getTimerLeft', |
| 1953 | value: function getTimerLeft() { |
| 1954 | if (this.running) { |
| 1955 | this.stop(); |
| 1956 | this.start(); |
| 1957 | } |
| 1958 | return this.remaining; |
| 1959 | } |
| 1960 | }, { |
| 1961 | key: 'isRunning', |
| 1962 | value: function isRunning() { |
| 1963 | return this.running; |
| 1964 | } |
| 1965 | }]); |
| 1966 | return Timer; |
| 1967 | }(); |
| 1968 | var defaultInputValidators = { |
| 1969 | email: function email(string, validationMessage) { |
| 1970 | 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'); |
| 1971 | }, |
| 1972 | url: function url(string, validationMessage) { |
| 1973 | // taken from https://stackoverflow.com/a/3809435 with a small change from #1306 |
| 1974 | return /^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,63}\b([-a-zA-Z0-9@:%_+.~#?&/=]*)$/.test(string) ? Promise.resolve() : Promise.resolve(validationMessage || 'Invalid URL'); |
| 1975 | } |
| 1976 | }; |
| 1977 | function setDefaultInputValidators(params) { |
| 1978 | // Use default `inputValidator` for supported input types if not provided |
| 1979 | if (!params.inputValidator) { |
| 1980 | Object.keys(defaultInputValidators).forEach(function (key) { |
| 1981 | if (params.input === key) { |
| 1982 | params.inputValidator = defaultInputValidators[key]; |
| 1983 | } |
| 1984 | }); |
| 1985 | } |
| 1986 | } |
| 1987 | function validateCustomTargetElement(params) { |
| 1988 | // Determine if the custom target element is valid |
| 1989 | if (!params.target || typeof params.target === 'string' && !document.querySelector(params.target) || typeof params.target !== 'string' && !params.target.appendChild) { |
| 1990 | warn('Target parameter is not valid, defaulting to "body"'); |
| 1991 | params.target = 'body'; |
| 1992 | } |
| 1993 | } |
| 1994 | /** |
| 1995 | * Set type, text and actions on popup |
| 1996 | * |
| 1997 | * @param params |
| 1998 | * @returns {boolean} |
| 1999 | */ |
| 2000 | |
| 2001 | function setParameters(params) { |
| 2002 | setDefaultInputValidators(params); // showLoaderOnConfirm && preConfirm |
| 2003 | |
| 2004 | if (params.showLoaderOnConfirm && !params.preConfirm) { |
| 2005 | 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'); |
| 2006 | } // params.animation will be actually used in renderPopup.js |
| 2007 | // but in case when params.animation is a function, we need to call that function |
| 2008 | // before popup (re)initialization, so it'll be possible to check Swal.isVisible() |
| 2009 | // inside the params.animation function |
| 2010 | |
| 2011 | params.animation = callIfFunction(params.animation); |
| 2012 | validateCustomTargetElement(params); // Replace newlines with <br> in title |
| 2013 | |
| 2014 | if (typeof params.title === 'string') { |
| 2015 | params.title = params.title.split('\n').join('<br />'); |
| 2016 | } |
| 2017 | init(params); |
| 2018 | } |
| 2019 | |
| 2020 | /** |
| 2021 | * Open popup, add necessary classes and styles, fix scrollbar |
| 2022 | * |
| 2023 | * @param {Array} params |
| 2024 | */ |
| 2025 | |
| 2026 | var openPopup = function openPopup(params) { |
| 2027 | var container = getContainer(); |
| 2028 | var popup = getPopup(); |
| 2029 | if (typeof params.onBeforeOpen === 'function') { |
| 2030 | params.onBeforeOpen(popup); |
| 2031 | } |
| 2032 | addClasses$1(container, popup, params); // scrolling is 'hidden' until animation is done, after that 'auto' |
| 2033 | |
| 2034 | setScrollingVisibility(container, popup); |
| 2035 | if (isModal()) { |
| 2036 | fixScrollContainer(container, params.scrollbarPadding); |
| 2037 | } |
| 2038 | if (!isToast() && !globalState.previousActiveElement) { |
| 2039 | globalState.previousActiveElement = document.activeElement; |
| 2040 | } |
| 2041 | if (typeof params.onOpen === 'function') { |
| 2042 | setTimeout(function () { |
| 2043 | return params.onOpen(popup); |
| 2044 | }); |
| 2045 | } |
| 2046 | removeClass(container, swalClasses['no-transition']); |
| 2047 | }; |
| 2048 | function swalOpenAnimationFinished(event) { |
| 2049 | var popup = getPopup(); |
| 2050 | if (event.target !== popup) { |
| 2051 | return; |
| 2052 | } |
| 2053 | var container = getContainer(); |
| 2054 | popup.removeEventListener(animationEndEvent, swalOpenAnimationFinished); |
| 2055 | container.style.overflowY = 'auto'; |
| 2056 | } |
| 2057 | var setScrollingVisibility = function setScrollingVisibility(container, popup) { |
| 2058 | if (animationEndEvent && hasCssAnimation(popup)) { |
| 2059 | container.style.overflowY = 'hidden'; |
| 2060 | popup.addEventListener(animationEndEvent, swalOpenAnimationFinished); |
| 2061 | } else { |
| 2062 | container.style.overflowY = 'auto'; |
| 2063 | } |
| 2064 | }; |
| 2065 | var fixScrollContainer = function fixScrollContainer(container, scrollbarPadding) { |
| 2066 | iOSfix(); |
| 2067 | IEfix(); |
| 2068 | setAriaHidden(); |
| 2069 | if (scrollbarPadding) { |
| 2070 | fixScrollbar(); |
| 2071 | } // sweetalert2/issues/1247 |
| 2072 | |
| 2073 | setTimeout(function () { |
| 2074 | container.scrollTop = 0; |
| 2075 | }); |
| 2076 | }; |
| 2077 | var addClasses$1 = function addClasses(container, popup, params) { |
| 2078 | addClass(container, params.showClass.backdrop); |
| 2079 | show(popup); // Animate popup right after showing it |
| 2080 | |
| 2081 | addClass(popup, params.showClass.popup); |
| 2082 | addClass([document.documentElement, document.body], swalClasses.shown); |
| 2083 | if (params.heightAuto && params.backdrop && !params.toast) { |
| 2084 | addClass([document.documentElement, document.body], swalClasses['height-auto']); |
| 2085 | } |
| 2086 | }; |
| 2087 | var handleInputOptionsAndValue = function handleInputOptionsAndValue(instance, params) { |
| 2088 | if (params.input === 'select' || params.input === 'radio') { |
| 2089 | handleInputOptions(instance, params); |
| 2090 | } else if (['text', 'email', 'number', 'tel', 'textarea'].indexOf(params.input) !== -1 && isPromise(params.inputValue)) { |
| 2091 | handleInputValue(instance, params); |
| 2092 | } |
| 2093 | }; |
| 2094 | var getInputValue = function getInputValue(instance, innerParams) { |
| 2095 | var input = instance.getInput(); |
| 2096 | if (!input) { |
| 2097 | return null; |
| 2098 | } |
| 2099 | switch (innerParams.input) { |
| 2100 | case 'checkbox': |
| 2101 | return getCheckboxValue(input); |
| 2102 | case 'radio': |
| 2103 | return getRadioValue(input); |
| 2104 | case 'file': |
| 2105 | return getFileValue(input); |
| 2106 | default: |
| 2107 | return innerParams.inputAutoTrim ? input.value.trim() : input.value; |
| 2108 | } |
| 2109 | }; |
| 2110 | var getCheckboxValue = function getCheckboxValue(input) { |
| 2111 | return input.checked ? 1 : 0; |
| 2112 | }; |
| 2113 | var getRadioValue = function getRadioValue(input) { |
| 2114 | return input.checked ? input.value : null; |
| 2115 | }; |
| 2116 | var getFileValue = function getFileValue(input) { |
| 2117 | return input.files.length ? input.getAttribute('multiple') !== null ? input.files : input.files[0] : null; |
| 2118 | }; |
| 2119 | var handleInputOptions = function handleInputOptions(instance, params) { |
| 2120 | var content = getContent(); |
| 2121 | var processInputOptions = function processInputOptions(inputOptions) { |
| 2122 | return populateInputOptions[params.input](content, formatInputOptions(inputOptions), params); |
| 2123 | }; |
| 2124 | if (isPromise(params.inputOptions)) { |
| 2125 | showLoading(); |
| 2126 | params.inputOptions.then(function (inputOptions) { |
| 2127 | instance.hideLoading(); |
| 2128 | processInputOptions(inputOptions); |
| 2129 | }); |
| 2130 | } else if (_typeof(params.inputOptions) === 'object') { |
| 2131 | processInputOptions(params.inputOptions); |
| 2132 | } else { |
| 2133 | error('Unexpected type of inputOptions! Expected object, Map or Promise, got '.concat(_typeof(params.inputOptions))); |
| 2134 | } |
| 2135 | }; |
| 2136 | var handleInputValue = function handleInputValue(instance, params) { |
| 2137 | var input = instance.getInput(); |
| 2138 | hide(input); |
| 2139 | params.inputValue.then(function (inputValue) { |
| 2140 | input.value = params.input === 'number' ? parseFloat(inputValue) || 0 : ''.concat(inputValue); |
| 2141 | show(input); |
| 2142 | input.focus(); |
| 2143 | instance.hideLoading(); |
| 2144 | })['catch'](function (err) { |
| 2145 | error('Error in inputValue promise: '.concat(err)); |
| 2146 | input.value = ''; |
| 2147 | show(input); |
| 2148 | input.focus(); |
| 2149 | instance.hideLoading(); |
| 2150 | }); |
| 2151 | }; |
| 2152 | var populateInputOptions = { |
| 2153 | select: function select(content, inputOptions, params) { |
| 2154 | var select = getChildByClass(content, swalClasses.select); |
| 2155 | var renderOption = function renderOption(parent, optionLabel, optionValue) { |
| 2156 | var option = document.createElement('option'); |
| 2157 | option.value = optionValue; |
| 2158 | setInnerHtml(option, optionLabel); |
| 2159 | if (params.inputValue.toString() === optionValue.toString()) { |
| 2160 | option.selected = true; |
| 2161 | } |
| 2162 | parent.appendChild(option); |
| 2163 | }; |
| 2164 | inputOptions.forEach(function (inputOption) { |
| 2165 | var optionValue = inputOption[0]; |
| 2166 | var optionLabel = inputOption[1]; // <optgroup> spec: |
| 2167 | // https://www.w3.org/TR/html401/interact/forms.html#h-17.6 |
| 2168 | // "...all OPTGROUP elements must be specified directly within a SELECT element (i.e., groups may not be nested)..." |
| 2169 | // check whether this is a <optgroup> |
| 2170 | |
| 2171 | if (Array.isArray(optionLabel)) { |
| 2172 | // if it is an array, then it is an <optgroup> |
| 2173 | var optgroup = document.createElement('optgroup'); |
| 2174 | optgroup.label = optionValue; |
| 2175 | optgroup.disabled = false; // not configurable for now |
| 2176 | |
| 2177 | select.appendChild(optgroup); |
| 2178 | optionLabel.forEach(function (o) { |
| 2179 | return renderOption(optgroup, o[1], o[0]); |
| 2180 | }); |
| 2181 | } else { |
| 2182 | // case of <option> |
| 2183 | renderOption(select, optionLabel, optionValue); |
| 2184 | } |
| 2185 | }); |
| 2186 | select.focus(); |
| 2187 | }, |
| 2188 | radio: function radio(content, inputOptions, params) { |
| 2189 | var radio = getChildByClass(content, swalClasses.radio); |
| 2190 | inputOptions.forEach(function (inputOption) { |
| 2191 | var radioValue = inputOption[0]; |
| 2192 | var radioLabel = inputOption[1]; |
| 2193 | var radioInput = document.createElement('input'); |
| 2194 | var radioLabelElement = document.createElement('label'); |
| 2195 | radioInput.type = 'radio'; |
| 2196 | radioInput.name = swalClasses.radio; |
| 2197 | radioInput.value = radioValue; |
| 2198 | if (params.inputValue.toString() === radioValue.toString()) { |
| 2199 | radioInput.checked = true; |
| 2200 | } |
| 2201 | var label = document.createElement('span'); |
| 2202 | setInnerHtml(label, radioLabel); |
| 2203 | label.className = swalClasses.label; |
| 2204 | radioLabelElement.appendChild(radioInput); |
| 2205 | radioLabelElement.appendChild(label); |
| 2206 | radio.appendChild(radioLabelElement); |
| 2207 | }); |
| 2208 | var radios = radio.querySelectorAll('input'); |
| 2209 | if (radios.length) { |
| 2210 | radios[0].focus(); |
| 2211 | } |
| 2212 | } |
| 2213 | }; |
| 2214 | /** |
| 2215 | * Converts `inputOptions` into an array of `[value, label]`s |
| 2216 | * @param inputOptions |
| 2217 | */ |
| 2218 | |
| 2219 | var formatInputOptions = function formatInputOptions(inputOptions) { |
| 2220 | var result = []; |
| 2221 | if (typeof Map !== 'undefined' && inputOptions instanceof Map) { |
| 2222 | inputOptions.forEach(function (value, key) { |
| 2223 | var valueFormatted = value; |
| 2224 | if (_typeof(valueFormatted) === 'object') { |
| 2225 | // case of <optgroup> |
| 2226 | valueFormatted = formatInputOptions(valueFormatted); |
| 2227 | } |
| 2228 | result.push([key, valueFormatted]); |
| 2229 | }); |
| 2230 | } else { |
| 2231 | Object.keys(inputOptions).forEach(function (key) { |
| 2232 | var valueFormatted = inputOptions[key]; |
| 2233 | if (_typeof(valueFormatted) === 'object') { |
| 2234 | // case of <optgroup> |
| 2235 | valueFormatted = formatInputOptions(valueFormatted); |
| 2236 | } |
| 2237 | result.push([key, valueFormatted]); |
| 2238 | }); |
| 2239 | } |
| 2240 | return result; |
| 2241 | }; |
| 2242 | var handleConfirmButtonClick = function handleConfirmButtonClick(instance, innerParams) { |
| 2243 | instance.disableButtons(); |
| 2244 | if (innerParams.input) { |
| 2245 | handleConfirmWithInput(instance, innerParams); |
| 2246 | } else { |
| 2247 | confirm(instance, innerParams, true); |
| 2248 | } |
| 2249 | }; |
| 2250 | var handleCancelButtonClick = function handleCancelButtonClick(instance, dismissWith) { |
| 2251 | instance.disableButtons(); |
| 2252 | dismissWith(DismissReason.cancel); |
| 2253 | }; |
| 2254 | var handleConfirmWithInput = function handleConfirmWithInput(instance, innerParams) { |
| 2255 | var inputValue = getInputValue(instance, innerParams); |
| 2256 | if (innerParams.inputValidator) { |
| 2257 | instance.disableInput(); |
| 2258 | var validationPromise = Promise.resolve().then(function () { |
| 2259 | return innerParams.inputValidator(inputValue, innerParams.validationMessage); |
| 2260 | }); |
| 2261 | validationPromise.then(function (validationMessage) { |
| 2262 | instance.enableButtons(); |
| 2263 | instance.enableInput(); |
| 2264 | if (validationMessage) { |
| 2265 | instance.showValidationMessage(validationMessage); |
| 2266 | } else { |
| 2267 | confirm(instance, innerParams, inputValue); |
| 2268 | } |
| 2269 | }); |
| 2270 | } else if (!instance.getInput().checkValidity()) { |
| 2271 | instance.enableButtons(); |
| 2272 | instance.showValidationMessage(innerParams.validationMessage); |
| 2273 | } else { |
| 2274 | confirm(instance, innerParams, inputValue); |
| 2275 | } |
| 2276 | }; |
| 2277 | var succeedWith = function succeedWith(instance, value) { |
| 2278 | instance.closePopup({ |
| 2279 | value: value |
| 2280 | }); |
| 2281 | }; |
| 2282 | var confirm = function confirm(instance, innerParams, value) { |
| 2283 | if (innerParams.showLoaderOnConfirm) { |
| 2284 | showLoading(); // TODO: make showLoading an *instance* method |
| 2285 | } |
| 2286 | |
| 2287 | if (innerParams.preConfirm) { |
| 2288 | instance.resetValidationMessage(); |
| 2289 | var preConfirmPromise = Promise.resolve().then(function () { |
| 2290 | return innerParams.preConfirm(value, innerParams.validationMessage); |
| 2291 | }); |
| 2292 | preConfirmPromise.then(function (preConfirmValue) { |
| 2293 | if (isVisible(getValidationMessage()) || preConfirmValue === false) { |
| 2294 | instance.hideLoading(); |
| 2295 | } else { |
| 2296 | succeedWith(instance, typeof preConfirmValue === 'undefined' ? value : preConfirmValue); |
| 2297 | } |
| 2298 | }); |
| 2299 | } else { |
| 2300 | succeedWith(instance, value); |
| 2301 | } |
| 2302 | }; |
| 2303 | var addKeydownHandler = function addKeydownHandler(instance, globalState, innerParams, dismissWith) { |
| 2304 | if (globalState.keydownTarget && globalState.keydownHandlerAdded) { |
| 2305 | globalState.keydownTarget.removeEventListener('keydown', globalState.keydownHandler, { |
| 2306 | capture: globalState.keydownListenerCapture |
| 2307 | }); |
| 2308 | globalState.keydownHandlerAdded = false; |
| 2309 | } |
| 2310 | if (!innerParams.toast) { |
| 2311 | globalState.keydownHandler = function (e) { |
| 2312 | return keydownHandler(instance, e, dismissWith); |
| 2313 | }; |
| 2314 | globalState.keydownTarget = innerParams.keydownListenerCapture ? window : getPopup(); |
| 2315 | globalState.keydownListenerCapture = innerParams.keydownListenerCapture; |
| 2316 | globalState.keydownTarget.addEventListener('keydown', globalState.keydownHandler, { |
| 2317 | capture: globalState.keydownListenerCapture |
| 2318 | }); |
| 2319 | globalState.keydownHandlerAdded = true; |
| 2320 | } |
| 2321 | }; // Focus handling |
| 2322 | |
| 2323 | var setFocus = function setFocus(innerParams, index, increment) { |
| 2324 | var focusableElements = getFocusableElements(); // search for visible elements and select the next possible match |
| 2325 | |
| 2326 | for (var i = 0; i < focusableElements.length; i++) { |
| 2327 | index = index + increment; // rollover to first item |
| 2328 | |
| 2329 | if (index === focusableElements.length) { |
| 2330 | index = 0; // go to last item |
| 2331 | } else if (index === -1) { |
| 2332 | index = focusableElements.length - 1; |
| 2333 | } |
| 2334 | return focusableElements[index].focus(); |
| 2335 | } // no visible focusable elements, focus the popup |
| 2336 | |
| 2337 | getPopup().focus(); |
| 2338 | }; |
| 2339 | var arrowKeys = ['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'Left', 'Right', 'Up', 'Down' // IE11 |
| 2340 | ]; |
| 2341 | |
| 2342 | var escKeys = ['Escape', 'Esc' // IE11 |
| 2343 | ]; |
| 2344 | |
| 2345 | var keydownHandler = function keydownHandler(instance, e, dismissWith) { |
| 2346 | var innerParams = privateProps.innerParams.get(instance); |
| 2347 | if (innerParams.stopKeydownPropagation) { |
| 2348 | e.stopPropagation(); |
| 2349 | } // ENTER |
| 2350 | |
| 2351 | if (e.key === 'Enter') { |
| 2352 | handleEnter(instance, e, innerParams); // TAB |
| 2353 | } else if (e.key === 'Tab') { |
| 2354 | handleTab(e, innerParams); // ARROWS - switch focus between buttons |
| 2355 | } else if (arrowKeys.indexOf(e.key) !== -1) { |
| 2356 | handleArrows(); // ESC |
| 2357 | } else if (escKeys.indexOf(e.key) !== -1) { |
| 2358 | handleEsc(e, innerParams, dismissWith); |
| 2359 | } |
| 2360 | }; |
| 2361 | var handleEnter = function handleEnter(instance, e, innerParams) { |
| 2362 | // #720 #721 |
| 2363 | if (e.isComposing) { |
| 2364 | return; |
| 2365 | } |
| 2366 | if (e.target && instance.getInput() && e.target.outerHTML === instance.getInput().outerHTML) { |
| 2367 | if (['textarea', 'file'].indexOf(innerParams.input) !== -1) { |
| 2368 | return; // do not submit |
| 2369 | } |
| 2370 | |
| 2371 | clickConfirm(); |
| 2372 | e.preventDefault(); |
| 2373 | } |
| 2374 | }; |
| 2375 | var handleTab = function handleTab(e, innerParams) { |
| 2376 | var targetElement = e.target; |
| 2377 | var focusableElements = getFocusableElements(); |
| 2378 | var btnIndex = -1; |
| 2379 | for (var i = 0; i < focusableElements.length; i++) { |
| 2380 | if (targetElement === focusableElements[i]) { |
| 2381 | btnIndex = i; |
| 2382 | break; |
| 2383 | } |
| 2384 | } |
| 2385 | if (!e.shiftKey) { |
| 2386 | // Cycle to the next button |
| 2387 | setFocus(innerParams, btnIndex, 1); |
| 2388 | } else { |
| 2389 | // Cycle to the prev button |
| 2390 | setFocus(innerParams, btnIndex, -1); |
| 2391 | } |
| 2392 | e.stopPropagation(); |
| 2393 | e.preventDefault(); |
| 2394 | }; |
| 2395 | var handleArrows = function handleArrows() { |
| 2396 | var confirmButton = getConfirmButton(); |
| 2397 | var cancelButton = getCancelButton(); // focus Cancel button if Confirm button is currently focused |
| 2398 | |
| 2399 | if (document.activeElement === confirmButton && isVisible(cancelButton)) { |
| 2400 | cancelButton.focus(); // and vice versa |
| 2401 | } else if (document.activeElement === cancelButton && isVisible(confirmButton)) { |
| 2402 | confirmButton.focus(); |
| 2403 | } |
| 2404 | }; |
| 2405 | var handleEsc = function handleEsc(e, innerParams, dismissWith) { |
| 2406 | if (callIfFunction(innerParams.allowEscapeKey)) { |
| 2407 | e.preventDefault(); |
| 2408 | dismissWith(DismissReason.esc); |
| 2409 | } |
| 2410 | }; |
| 2411 | var handlePopupClick = function handlePopupClick(instance, domCache, dismissWith) { |
| 2412 | var innerParams = privateProps.innerParams.get(instance); |
| 2413 | if (innerParams.toast) { |
| 2414 | handleToastClick(instance, domCache, dismissWith); |
| 2415 | } else { |
| 2416 | // Ignore click events that had mousedown on the popup but mouseup on the container |
| 2417 | // This can happen when the user drags a slider |
| 2418 | handleModalMousedown(domCache); // Ignore click events that had mousedown on the container but mouseup on the popup |
| 2419 | |
| 2420 | handleContainerMousedown(domCache); |
| 2421 | handleModalClick(instance, domCache, dismissWith); |
| 2422 | } |
| 2423 | }; |
| 2424 | var handleToastClick = function handleToastClick(instance, domCache, dismissWith) { |
| 2425 | // Closing toast by internal click |
| 2426 | domCache.popup.onclick = function () { |
| 2427 | var innerParams = privateProps.innerParams.get(instance); |
| 2428 | if (innerParams.showConfirmButton || innerParams.showCancelButton || innerParams.showCloseButton || innerParams.input) { |
| 2429 | return; |
| 2430 | } |
| 2431 | dismissWith(DismissReason.close); |
| 2432 | }; |
| 2433 | }; |
| 2434 | var ignoreOutsideClick = false; |
| 2435 | var handleModalMousedown = function handleModalMousedown(domCache) { |
| 2436 | domCache.popup.onmousedown = function () { |
| 2437 | domCache.container.onmouseup = function (e) { |
| 2438 | domCache.container.onmouseup = undefined; // We only check if the mouseup target is the container because usually it doesn't |
| 2439 | // have any other direct children aside of the popup |
| 2440 | |
| 2441 | if (e.target === domCache.container) { |
| 2442 | ignoreOutsideClick = true; |
| 2443 | } |
| 2444 | }; |
| 2445 | }; |
| 2446 | }; |
| 2447 | var handleContainerMousedown = function handleContainerMousedown(domCache) { |
| 2448 | domCache.container.onmousedown = function () { |
| 2449 | domCache.popup.onmouseup = function (e) { |
| 2450 | domCache.popup.onmouseup = undefined; // We also need to check if the mouseup target is a child of the popup |
| 2451 | |
| 2452 | if (e.target === domCache.popup || domCache.popup.contains(e.target)) { |
| 2453 | ignoreOutsideClick = true; |
| 2454 | } |
| 2455 | }; |
| 2456 | }; |
| 2457 | }; |
| 2458 | var handleModalClick = function handleModalClick(instance, domCache, dismissWith) { |
| 2459 | domCache.container.onclick = function (e) { |
| 2460 | var innerParams = privateProps.innerParams.get(instance); |
| 2461 | if (ignoreOutsideClick) { |
| 2462 | ignoreOutsideClick = false; |
| 2463 | return; |
| 2464 | } |
| 2465 | if (e.target === domCache.container && callIfFunction(innerParams.allowOutsideClick)) { |
| 2466 | dismissWith(DismissReason.backdrop); |
| 2467 | } |
| 2468 | }; |
| 2469 | }; |
| 2470 | function _main(userParams) { |
| 2471 | showWarningsForParams(userParams); |
| 2472 | if (globalState.currentInstance) { |
| 2473 | globalState.currentInstance._destroy(); |
| 2474 | } |
| 2475 | globalState.currentInstance = this; |
| 2476 | var innerParams = prepareParams(userParams); |
| 2477 | setParameters(innerParams); |
| 2478 | Object.freeze(innerParams); // clear the previous timer |
| 2479 | |
| 2480 | if (globalState.timeout) { |
| 2481 | globalState.timeout.stop(); |
| 2482 | delete globalState.timeout; |
| 2483 | } // clear the restore focus timeout |
| 2484 | |
| 2485 | clearTimeout(globalState.restoreFocusTimeout); |
| 2486 | var domCache = populateDomCache(this); |
| 2487 | render(this, innerParams); |
| 2488 | privateProps.innerParams.set(this, innerParams); |
| 2489 | return swalPromise(this, domCache, innerParams); |
| 2490 | } |
| 2491 | var prepareParams = function prepareParams(userParams) { |
| 2492 | var showClass = _extends({}, defaultParams.showClass, userParams.showClass); |
| 2493 | var hideClass = _extends({}, defaultParams.hideClass, userParams.hideClass); |
| 2494 | var params = _extends({}, defaultParams, userParams); |
| 2495 | params.showClass = showClass; |
| 2496 | params.hideClass = hideClass; // @deprecated |
| 2497 | |
| 2498 | if (userParams.animation === false) { |
| 2499 | params.showClass = { |
| 2500 | popup: 'wpstg--swal2-noanimation', |
| 2501 | backdrop: 'wpstg--swal2-noanimation' |
| 2502 | }; |
| 2503 | params.hideClass = {}; |
| 2504 | } |
| 2505 | return params; |
| 2506 | }; |
| 2507 | var swalPromise = function swalPromise(instance, domCache, innerParams) { |
| 2508 | return new Promise(function (resolve) { |
| 2509 | // functions to handle all closings/dismissals |
| 2510 | var dismissWith = function dismissWith(dismiss) { |
| 2511 | instance.closePopup({ |
| 2512 | dismiss: dismiss |
| 2513 | }); |
| 2514 | }; |
| 2515 | privateMethods.swalPromiseResolve.set(instance, resolve); |
| 2516 | domCache.confirmButton.onclick = function () { |
| 2517 | return handleConfirmButtonClick(instance, innerParams); |
| 2518 | }; |
| 2519 | domCache.cancelButton.onclick = function () { |
| 2520 | return handleCancelButtonClick(instance, dismissWith); |
| 2521 | }; |
| 2522 | domCache.closeButton.onclick = function () { |
| 2523 | return dismissWith(DismissReason.close); |
| 2524 | }; |
| 2525 | handlePopupClick(instance, domCache, dismissWith); |
| 2526 | addKeydownHandler(instance, globalState, innerParams, dismissWith); |
| 2527 | if (innerParams.toast && (innerParams.input || innerParams.footer || innerParams.showCloseButton)) { |
| 2528 | addClass(document.body, swalClasses['toast-column']); |
| 2529 | } else { |
| 2530 | removeClass(document.body, swalClasses['toast-column']); |
| 2531 | } |
| 2532 | handleInputOptionsAndValue(instance, innerParams); |
| 2533 | openPopup(innerParams); |
| 2534 | setupTimer(globalState, innerParams, dismissWith); |
| 2535 | initFocus(domCache, innerParams); // Scroll container to top on open (#1247, #1946) |
| 2536 | |
| 2537 | setTimeout(function () { |
| 2538 | domCache.container.scrollTop = 0; |
| 2539 | }); |
| 2540 | }); |
| 2541 | }; |
| 2542 | var populateDomCache = function populateDomCache(instance) { |
| 2543 | var domCache = { |
| 2544 | popup: getPopup(), |
| 2545 | container: getContainer(), |
| 2546 | content: getContent(), |
| 2547 | actions: getActions(), |
| 2548 | confirmButton: getConfirmButton(), |
| 2549 | cancelButton: getCancelButton(), |
| 2550 | closeButton: getCloseButton(), |
| 2551 | validationMessage: getValidationMessage(), |
| 2552 | progressSteps: getProgressSteps() |
| 2553 | }; |
| 2554 | privateProps.domCache.set(instance, domCache); |
| 2555 | return domCache; |
| 2556 | }; |
| 2557 | var setupTimer = function setupTimer(globalState$$1, innerParams, dismissWith) { |
| 2558 | var timerProgressBar = getTimerProgressBar(); |
| 2559 | hide(timerProgressBar); |
| 2560 | if (innerParams.timer) { |
| 2561 | globalState$$1.timeout = new Timer(function () { |
| 2562 | dismissWith('timer'); |
| 2563 | delete globalState$$1.timeout; |
| 2564 | }, innerParams.timer); |
| 2565 | if (innerParams.timerProgressBar) { |
| 2566 | show(timerProgressBar); |
| 2567 | setTimeout(function () { |
| 2568 | if (globalState$$1.timeout.running) { |
| 2569 | // timer can be already stopped at this point |
| 2570 | animateTimerProgressBar(innerParams.timer); |
| 2571 | } |
| 2572 | }); |
| 2573 | } |
| 2574 | } |
| 2575 | }; |
| 2576 | var initFocus = function initFocus(domCache, innerParams) { |
| 2577 | if (innerParams.toast) { |
| 2578 | return; |
| 2579 | } |
| 2580 | if (!callIfFunction(innerParams.allowEnterKey)) { |
| 2581 | return blurActiveElement(); |
| 2582 | } |
| 2583 | if (innerParams.focusCancel && isVisible(domCache.cancelButton)) { |
| 2584 | return domCache.cancelButton.focus(); |
| 2585 | } |
| 2586 | if (innerParams.focusConfirm && isVisible(domCache.confirmButton)) { |
| 2587 | return domCache.confirmButton.focus(); |
| 2588 | } |
| 2589 | setFocus(innerParams, -1, 1); |
| 2590 | }; |
| 2591 | var blurActiveElement = function blurActiveElement() { |
| 2592 | if (document.activeElement && typeof document.activeElement.blur === 'function') { |
| 2593 | document.activeElement.blur(); |
| 2594 | } |
| 2595 | }; |
| 2596 | |
| 2597 | /** |
| 2598 | * Updates popup parameters. |
| 2599 | */ |
| 2600 | |
| 2601 | function update(params) { |
| 2602 | var popup = getPopup(); |
| 2603 | var innerParams = privateProps.innerParams.get(this); |
| 2604 | if (!popup || hasClass(popup, innerParams.hideClass.popup)) { |
| 2605 | 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.'); |
| 2606 | } |
| 2607 | var validUpdatableParams = {}; // assign valid params from `params` to `defaults` |
| 2608 | |
| 2609 | Object.keys(params).forEach(function (param) { |
| 2610 | if (wpstgSwal.isUpdatableParameter(param)) { |
| 2611 | validUpdatableParams[param] = params[param]; |
| 2612 | } else { |
| 2613 | warn('Invalid parameter to update: "'.concat(param, '". Updatable params are listed here: https://github.com/sweetalert2/sweetalert2/blob/master/src/utils/params.js')); |
| 2614 | } |
| 2615 | }); |
| 2616 | var updatedParams = _extends({}, innerParams, validUpdatableParams); |
| 2617 | render(this, updatedParams); |
| 2618 | privateProps.innerParams.set(this, updatedParams); |
| 2619 | Object.defineProperties(this, { |
| 2620 | params: { |
| 2621 | value: _extends({}, this.params, params), |
| 2622 | writable: false, |
| 2623 | enumerable: true |
| 2624 | } |
| 2625 | }); |
| 2626 | } |
| 2627 | function _destroy() { |
| 2628 | var domCache = privateProps.domCache.get(this); |
| 2629 | var innerParams = privateProps.innerParams.get(this); |
| 2630 | if (!innerParams) { |
| 2631 | return; // This instance has already been destroyed |
| 2632 | } // Check if there is another Swal closing |
| 2633 | |
| 2634 | if (domCache.popup && globalState.swalCloseEventFinishedCallback) { |
| 2635 | globalState.swalCloseEventFinishedCallback(); |
| 2636 | delete globalState.swalCloseEventFinishedCallback; |
| 2637 | } // Check if there is a swal disposal defer timer |
| 2638 | |
| 2639 | if (globalState.deferDisposalTimer) { |
| 2640 | clearTimeout(globalState.deferDisposalTimer); |
| 2641 | delete globalState.deferDisposalTimer; |
| 2642 | } |
| 2643 | if (typeof innerParams.onDestroy === 'function') { |
| 2644 | innerParams.onDestroy(); |
| 2645 | } |
| 2646 | disposeSwal(this); |
| 2647 | } |
| 2648 | var disposeSwal = function disposeSwal(instance) { |
| 2649 | // Unset this.params so GC will dispose it (#1569) |
| 2650 | delete instance.params; // Unset globalState props so GC will dispose globalState (#1569) |
| 2651 | |
| 2652 | delete globalState.keydownHandler; |
| 2653 | delete globalState.keydownTarget; // Unset WeakMaps so GC will be able to dispose them (#1569) |
| 2654 | |
| 2655 | unsetWeakMaps(privateProps); |
| 2656 | unsetWeakMaps(privateMethods); |
| 2657 | }; |
| 2658 | var unsetWeakMaps = function unsetWeakMaps(obj) { |
| 2659 | for (var i in obj) { |
| 2660 | obj[i] = new WeakMap(); |
| 2661 | } |
| 2662 | }; |
| 2663 | var instanceMethods = /* #__PURE__*/Object.freeze({ |
| 2664 | hideLoading: hideLoading, |
| 2665 | disableLoading: hideLoading, |
| 2666 | getInput: getInput$1, |
| 2667 | close: close, |
| 2668 | closePopup: close, |
| 2669 | closeModal: close, |
| 2670 | closeToast: close, |
| 2671 | enableButtons: enableButtons, |
| 2672 | disableButtons: disableButtons, |
| 2673 | enableInput: enableInput, |
| 2674 | disableInput: disableInput, |
| 2675 | showValidationMessage: showValidationMessage, |
| 2676 | resetValidationMessage: resetValidationMessage$1, |
| 2677 | getProgressSteps: getProgressSteps$1, |
| 2678 | _main: _main, |
| 2679 | update: update, |
| 2680 | _destroy: _destroy |
| 2681 | }); |
| 2682 | var currentInstance; |
| 2683 | var wpstgSweetAlert = /* #__PURE__*/function () { |
| 2684 | function wpstgSweetAlert() { |
| 2685 | _classCallCheck(this, wpstgSweetAlert); |
| 2686 | |
| 2687 | // Prevent run in Node env |
| 2688 | if (typeof window === 'undefined') { |
| 2689 | return; |
| 2690 | } // Check for the existence of Promise |
| 2691 | |
| 2692 | if (typeof Promise === 'undefined') { |
| 2693 | 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)'); |
| 2694 | } |
| 2695 | currentInstance = this; |
| 2696 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { |
| 2697 | args[_key] = arguments[_key]; |
| 2698 | } |
| 2699 | var outerParams = Object.freeze(this.constructor.argsToParams(args)); |
| 2700 | Object.defineProperties(this, { |
| 2701 | params: { |
| 2702 | value: outerParams, |
| 2703 | writable: false, |
| 2704 | enumerable: true, |
| 2705 | configurable: true |
| 2706 | } |
| 2707 | }); |
| 2708 | var promise = this._main(this.params); |
| 2709 | privateProps.promise.set(this, promise); |
| 2710 | } // `catch` cannot be the name of a module export, so we define our thenable methods here instead |
| 2711 | |
| 2712 | _createClass(wpstgSweetAlert, [{ |
| 2713 | key: 'then', |
| 2714 | value: function then(onFulfilled) { |
| 2715 | var promise = privateProps.promise.get(this); |
| 2716 | return promise.then(onFulfilled); |
| 2717 | } |
| 2718 | }, { |
| 2719 | key: 'finally', |
| 2720 | value: function _finally(onFinally) { |
| 2721 | var promise = privateProps.promise.get(this); |
| 2722 | return promise['finally'](onFinally); |
| 2723 | } |
| 2724 | }]); |
| 2725 | return wpstgSweetAlert; |
| 2726 | }(); // Assign instance methods from src/instanceMethods/*.js to prototype |
| 2727 | |
| 2728 | _extends(wpstgSweetAlert.prototype, instanceMethods); // Assign static methods from src/staticMethods/*.js to constructor |
| 2729 | |
| 2730 | _extends(wpstgSweetAlert, staticMethods); // Proxy to instance methods to constructor, for now, for backwards compatibility |
| 2731 | |
| 2732 | Object.keys(instanceMethods).forEach(function (key) { |
| 2733 | wpstgSweetAlert[key] = function () { |
| 2734 | if (currentInstance) { |
| 2735 | var _currentInstance; |
| 2736 | return (_currentInstance = currentInstance)[key].apply(_currentInstance, arguments); |
| 2737 | } |
| 2738 | }; |
| 2739 | }); |
| 2740 | wpstgSweetAlert.DismissReason = DismissReason; |
| 2741 | wpstgSweetAlert.version = '9.14.0'; |
| 2742 | var wpstgSwal = wpstgSweetAlert; |
| 2743 | wpstgSwal['default'] = wpstgSwal; |
| 2744 | window.wpstgSwal = wpstgSwal; |
| 2745 | }); |
| 2746 | |
| 2747 | })(); |
| 2748 | //# sourceMappingURL=wpstg-sweetalert2.js.map |
| 2749 |