1/*! 2 * sweetalert2 v6.11.1 3 * Released under the MIT License. 4 */ 5(function (global, factory) { 6 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : 7 typeof define === 'function' && define.amd ? define(factory) : 8 (global.Sweetalert2 = factory()); 9}(this, (function () { 'use strict'; 10 11function __$styleInject(css, returnValue) { 12 if (typeof document === 'undefined') { 13 return returnValue; 14 } 15 css = css || ''; 16 var head = document.head || document.getElementsByTagName('head')[0]; 17 var style = document.createElement('style'); 18 style.type = 'text/css'; 19 head.appendChild(style); 20 21 if (style.styleSheet){ 22 style.styleSheet.cssText = css; 23 } else { 24 style.appendChild(document.createTextNode(css)); 25 } 26 return returnValue; 27} 28 29var defaultParams = { 30 title: '', 31 titleText: '', 32 text: '', 33 html: '', 34 type: null, 35 customClass: '', 36 target: 'body', 37 animation: true, 38 allowOutsideClick: true, 39 allowEscapeKey: true, 40 allowEnterKey: true, 41 showConfirmButton: true,
42 showCancelButton: false, 43 preConfirm: null, 44 confirmButtonText: 'OK', 45 confirmButtonAriaLabel: '', 46 confirmButtonColor: '#3085d6', 47 confirmButtonClass: null, 48 cancelButtonText: 'Cancel', 49 cancelButtonAriaLabel: '', 50 cancelButtonColor: '#aaa', 51 cancelButtonClass: null, 52 buttonsStyling: true, 53 reverseButtons: false, 54 focusConfirm: true, 55 focusCancel: false, 56 showCloseButton: false, 57 closeButtonAriaLabel: 'Close this dialog', 58 showLoaderOnConfirm: false, 59 imageUrl: null, 60 imageWidth: null, 61 imageHeight: null, 62 imageAlt: '', 63 imageClass: null, 64 timer: null, 65 width: 500, 66 padding: 20, 67 background: '#fff', 68 input: null, 69 inputPlaceholder: '', 70 inputValue: '', 71 inputOptions: {}, 72 inputAutoTrim: true, 73 inputClass: null, 74 inputAttributes: {}, 75 inputValidator: null, 76 grow: false, 77 position: 'center', 78 progressSteps: [], 79 currentProgressStep: null, 80 progressStepsDistance: '40px', 81 onBeforeOpen: null, 82 onOpen: null, 83 onClose: null, 84 useRejections: true 85}; 86 87var swalPrefix = 'swal2-'; 88 89var prefix = function prefix(items) { 90 var result = {}; 91 for (var i in items) { 92 result[items[i]] = swalPrefix + items[i]; 93 } 94 return result; 95}; 96 97var swalClasses = prefix(['container', 'shown', 'iosfix', 'modal', 'overlay', 'fade', 'show', 'hide', 'noanimation', 'close', 'title', 'content', 'buttonswrapper', 'confirm', 'cancel', 'icon', 'image', 'input', 'file', 'range', 'select', 'radio', 'checkbox', 'textarea', 'inputerror', 'validationerror', 'progresssteps', 'activeprogressstep', 'progresscircle', 'progressline', 'loading', 'styled', 'top', 'top-left', 'top-right', 'center', 'center-left', 'center-right', 'bottom', 'bottom-left', 'bottom-right', 'grow-row', 'grow-column', 'grow-fullscreen']); 98 99var iconTypes = prefix(['success', 'warning', 'info', 'question', 'error']); 100 101var consolePrefix = 'SweetAlert2:'; 102 103/* 104 * Set hover, active and focus-states for buttons (source: http://www.sitepoint.com/javascript-generate-lighter-darker-color) 105 */ 106var colorLuminance = function colorLuminance(hex, lum) { 107 // Validate hex string 108 hex = String(hex).replace(/[^0-9a-f]/gi, ''); 109 if (hex.length < 6) { 110 hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]; 111 } 112 lum = lum || 0; 113 114 // Convert to decimal and change luminosity 115 var rgb = '#'; 116 for (var i = 0; i < 3; i++) { 117 var c = parseInt(hex.substr(i * 2, 2), 16); 118 c = Math.round(Math.min(Math.max(0, c + c * lum), 255)).toString(16); 119 rgb += ('00' + c).substr(c.length); 120 } 121 122 return rgb; 123}; 124 125var uniqueArray = function uniqueArray(arr) { 126 var result = []; 127 for (var i in arr) { 128 if (result.indexOf(arr[i]) === -1) { 129 result.push(arr[i]); 130 } 131 } 132 return result; 133}; 134 135/** 136 * Standardise console warnings 137 * @param message 138 */ 139var warn = function warn(message) { 140 console.warn(consolePrefix + ' ' + message); 141}; 142 143/** 144 * Standardise console errors 145 * @param message 146 */ 147var error = function error(message) { 148 console.error(consolePrefix + ' ' + message); 149}; 150 151// Remember state in cases where opening and handling a modal will fiddle with it. 152var states = { 153 previousWindowKeyDown: null, 154 previousActiveElement: null, 155 previousBodyPadding: null 156 157 /* 158 * Add modal + overlay to DOM 159 */ 160};var init = function init(params) { 161 // Clean up the old modal if it exists 162 var c = getContainer(); 163 if (c) { 164 c.parentNode.removeChild(c); 165 } 166 167 if (typeof document === 'undefined') { 168 error('SweetAlert2 requires document to initialize'); 169 return; 170 } 171 172 var container = document.createElement('div'); 173 container.className = swalClasses.container; 174 container.innerHTML = sweetHTML; 175 176 var targetElement = typeof params.target === 'string' ? document.querySelector(params.target) : params.target; 177 targetElement.appendChild(container); 178 179 var modal = getModal(); 180 var input = getChildByClass(modal, swalClasses.input); 181 var file = getChildByClass(modal, swalClasses.file); 182 var range = modal.querySelector('.' + swalClasses.range + ' input'); 183 var rangeOutput = modal.querySelector('.' + swalClasses.range + ' output'); 184 var select = getChildByClass(modal, swalClasses.select); 185 var checkbox = modal.querySelector('.' + swalClasses.checkbox + ' input'); 186 var textarea = getChildByClass(modal, swalClasses.textarea); 187 188 input.oninput = function () { 189 sweetAlert.resetValidationError(); 190 }; 191 192 file.onchange = function () { 193 sweetAlert.resetValidationError(); 194 }; 195 196 range.oninput = function () { 197 sweetAlert.resetValidationError(); 198 rangeOutput.value = range.value; 199 }; 200 201 range.onchange = function () { 202 sweetAlert.resetValidationError(); 203 range.previousSibling.value = range.value; 204 }; 205 206 select.onchange = function () { 207 sweetAlert.resetValidationError(); 208 }; 209 210 checkbox.onchange = function () { 211 sweetAlert.resetValidationError(); 212 }; 213 214 textarea.oninput = function () { 215 sweetAlert.resetValidationError(); 216 }; 217 218 return modal; 219}; 220 221/* 222 * Manipulate DOM 223 */ 224 225var sweetHTML = ('\n <div role="dialog" aria-modal="true" aria-labelledby="' + swalClasses.title + '" aria-describedby="' + swalClasses.content + '" class="' + swalClasses.modal + '" tabindex="-1">\n <ul class="' + swalClasses.progresssteps + '"></ul>\n <div class="' + swalClasses.icon + ' ' + iconTypes.error + '">\n <span class="swal2-x-mark"><span class="swal2-x-mark-line-left"></span><span class="swal2-x-mark-line-right"></span></span>\n </div>\n <div class="' + swalClasses.icon + ' ' + iconTypes.question + '">?</div>\n <div class="' + swalClasses.icon + ' ' + iconTypes.warning + '">!</div>\n <div class="' + swalClasses.icon + ' ' + iconTypes.info + '">i</div>\n <div class="' + swalClasses.icon + ' ' + iconTypes.success + '">\n <div class="swal2-success-circular-line-left"></div>\n <span class="swal2-success-line-tip"></span> <span class="swal2-success-line-long"></span>\n <div class="swal2-success-ring"></div> <div class="swal2-success-fix"></div>\n <div class="swal2-success-circular-line-right"></div>\n </div>\n <img class="' + swalClasses.image + '" />\n <h2 class="' + swalClasses.title + '" id="' + swalClasses.title + '"></h2>\n <div id="' + swalClasses.content + '" class="' + swalClasses.content + '"></div>\n <input class="' + swalClasses.input + '" />\n <input type="file" class="' + swalClasses.file + '" />\n <div class="' + swalClasses.range + '">\n <output></output>\n <input type="range" />\n </div>\n <select class="' + swalClasses.select + '"></select>\n <div class="' + swalClasses.radio + '"></div>\n <label for="' + swalClasses.checkbox + '" class="' + swalClasses.checkbox + '">\n <input type="checkbox" />\n </label>\n <textarea class="' + swalClasses.textarea + '"></textarea>\n <div class="' + swalClasses.validationerror + '" id="' + swalClasses.validationerror + '"></div>\n <div class="' + swalClasses.buttonswrapper + '">\n <button type="button" class="' + swalClasses.confirm + '">OK</button>\n <button type="button" class="' + swalClasses.cancel + '">Cancel</button>\n </div>\n <button type="button" class="' + swalClasses.close + '">\xD7</button>\n </div>\n').replace(/(^|\n)\s*/g, ''); 226 227var getContainer = function getContainer() { 228 return document.body.querySelector('.' + swalClasses.container); 229};
230 231var getModal = function getModal() { 232 return getContainer() ? getContainer().querySelector('.' + swalClasses.modal) : null; 233}; 234 235var getIcons = function getIcons() { 236 var modal = getModal(); 237 return modal.querySelectorAll('.' + swalClasses.icon); 238}; 239 240var elementByClass = function elementByClass(className) { 241 return getContainer() ? getContainer().querySelector('.' + className) : null; 242}; 243 244var getTitle = function getTitle() { 245 return elementByClass(swalClasses.title); 246}; 247 248var getContent = function getContent() { 249 return elementByClass(swalClasses.content); 250}; 251 252var getImage = function getImage() { 253 return elementByClass(swalClasses.image); 254}; 255 256var getProgressSteps = function getProgressSteps() { 257 return elementByClass(swalClasses.progresssteps); 258}; 259 260var getValidationError = function getValidationError() { 261 return elementByClass(swalClasses.validationerror); 262}; 263 264var getConfirmButton = function getConfirmButton() { 265 return elementByClass(swalClasses.confirm); 266}; 267 268var getCancelButton = function getCancelButton() { 269 return elementByClass(swalClasses.cancel); 270}; 271 272var getButtonsWrapper = function getButtonsWrapper() { 273 return elementByClass(swalClasses.buttonswrapper); 274}; 275 276var getCloseButton = function getCloseButton() { 277 return elementByClass(swalClasses.close); 278}; 279 280var getFocusableElements = function getFocusableElements() { 281 var focusableElementsWithTabindex = Array.from(getModal().querySelectorAll('[tabindex]:not([tabindex="-1"]):not([tabindex="0"])')) 282 // sort according to tabindex 283 .sort(function (a, b) { 284 a = parseInt(a.getAttribute('tabindex')); 285 b = parseInt(b.getAttribute('tabindex')); 286 if (a > b) { 287 return 1; 288 } else if (a < b) { 289 return -1; 290 } 291 return 0; 292 }); 293 294 var otherFocusableElements = Array.prototype.slice.call(getModal().querySelectorAll('button, input:not([type=hidden]), textarea, select, a, [tabindex="0"]')); 295 296 return uniqueArray(focusableElementsWithTabindex.concat(otherFocusableElements)); 297}; 298 299var hasClass = function hasClass(elem, className) { 300 if (elem.classList) { 301 return elem.classList.contains(className); 302 } 303 return false; 304}; 305 306var focusInput = function focusInput(input) { 307 input.focus(); 308 309 // place cursor at end of text in text input 310 if (input.type !== 'file') { 311 // http://stackoverflow.com/a/2345915/1331425 312 var val = input.value; 313 input.value = ''; 314 input.value = val; 315 } 316}; 317 318var addClass = function addClass(elem, className) { 319 if (!elem || !className) { 320 return; 321 } 322 var classes = className.split(/\s+/).filter(Boolean); 323 classes.forEach(function (className) { 324 elem.classList.add(className); 325 }); 326}; 327 328var removeClass = function removeClass(elem, className) { 329 if (!elem || !className) { 330 return; 331 } 332 var classes = className.split(/\s+/).filter(Boolean); 333 classes.forEach(function (className) { 334 elem.classList.remove(className); 335 }); 336}; 337 338var getChildByClass = function getChildByClass(elem, className) { 339 for (var i = 0; i < elem.childNodes.length; i++) { 340 if (hasClass(elem.childNodes[i], className)) { 341 return elem.childNodes[i]; 342 } 343 } 344}; 345 346var show = function show(elem, display) { 347 if (!display) { 348 display = 'block'; 349 } 350 elem.style.opacity = ''; 351 elem.style.display = display; 352}; 353 354var hide = function hide(elem) { 355 elem.style.opacity = ''; 356 elem.style.display = 'none'; 357}; 358 359var empty = function empty(elem) { 360 while (elem.firstChild) { 361 elem.removeChild(elem.firstChild); 362 } 363}; 364 365// borrowed from jqeury $(elem).is(':visible') implementation 366var isVisible = function isVisible(elem) { 367 return elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length; 368}; 369 370var removeStyleProperty = function removeStyleProperty(elem, property) { 371 if (elem.style.removeProperty) { 372 elem.style.removeProperty(property); 373 } else { 374 elem.style.removeAttribute(property); 375 } 376}; 377 378var animationEndEvent = function () { 379 var testEl = document.createElement('div'); 380 var transEndEventNames = { 381 'WebkitAnimation': 'webkitAnimationEnd', 382 'OAnimation': 'oAnimationEnd oanimationend', 383 'animation': 'animationend' 384 }; 385 for (var i in transEndEventNames) { 386 if (transEndEventNames.hasOwnProperty(i) && testEl.style[i] !== undefined) { 387 return transEndEventNames[i]; 388 } 389 } 390 391 return false; 392}();
vendor: 5,017 bytes, lines 393-595
393 394// Reset previous window keydown handler and focued element 395var resetPrevState = function resetPrevState() { 396 window.onkeydown = states.previousWindowKeyDown; 397 if (states.previousActiveElement && states.previousActiveElement.focus) { 398 var x = window.scrollX; 399 var y = window.scrollY; 400 states.previousActiveElement.focus(); 401 if (x && y) { 402 // IE has no scrollX/scrollY support 403 window.scrollTo(x, y); 404 } 405 } 406}; 407 408// Measure width of scrollbar 409// https://github.com/twbs/bootstrap/blob/master/js/modal.js#L279-L286 410var measureScrollbar = function measureScrollbar() { 411 var supportsTouch = 'ontouchstart' in window || navigator.msMaxTouchPoints; 412 if (supportsTouch) { 413 return 0; 414 } 415 var scrollDiv = document.createElement('div'); 416 scrollDiv.style.width = '50px'; 417 scrollDiv.style.height = '50px'; 418 scrollDiv.style.overflow = 'scroll'; 419 document.body.appendChild(scrollDiv); 420 var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth; 421 document.body.removeChild(scrollDiv); 422 return scrollbarWidth; 423}; 424 425// JavaScript Debounce Function 426// Simplivied version of https://davidwalsh.name/javascript-debounce-function 427 428var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { 429 return typeof obj; 430} : function (obj) { 431 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; 432}; 433 434 435 436 437 438var asyncGenerator = function () { 439 function AwaitValue(value) { 440 this.value = value; 441 } 442 443 function AsyncGenerator(gen) { 444 var front, back; 445 446 function send(key, arg) { 447 return new Promise(function (resolve, reject) { 448 var request = { 449 key: key, 450 arg: arg, 451 resolve: resolve, 452 reject: reject, 453 next: null 454 }; 455 456 if (back) { 457 back = back.next = request; 458 } else { 459 front = back = request; 460 resume(key, arg); 461 } 462 }); 463 } 464 465 function resume(key, arg) { 466 try { 467 var result = gen[key](arg); 468 var value = result.value; 469 470 if (value instanceof AwaitValue) { 471 Promise.resolve(value.value).then(function (arg) { 472 resume("next", arg); 473 }, function (arg) { 474 resume("throw", arg); 475 }); 476 } else { 477 settle(result.done ? "return" : "normal", result.value); 478 } 479 } catch (err) { 480 settle("throw", err); 481 } 482 } 483 484 function settle(type, value) { 485 switch (type) { 486 case "return": 487 front.resolve({ 488 value: value, 489 done: true 490 }); 491 break; 492 493 case "throw": 494 front.reject(value); 495 break; 496 497 default: 498 front.resolve({ 499 value: value, 500 done: false 501 }); 502 break; 503 } 504 505 front = front.next; 506 507 if (front) { 508 resume(front.key, front.arg); 509 } else { 510 back = null; 511 } 512 } 513 514 this._invoke = send; 515 516 if (typeof gen.return !== "function") { 517 this.return = undefined; 518 } 519 } 520 521 if (typeof Symbol === "function" && Symbol.asyncIterator) { 522 AsyncGenerator.prototype[Symbol.asyncIterator] = function () { 523 return this; 524 }; 525 } 526 527 AsyncGenerator.prototype.next = function (arg) { 528 return this._invoke("next", arg); 529 }; 530 531 AsyncGenerator.prototype.throw = function (arg) { 532 return this._invoke("throw", arg); 533 }; 534 535 AsyncGenerator.prototype.return = function (arg) { 536 return this._invoke("return", arg); 537 }; 538 539 return { 540 wrap: function (fn) { 541 return function () { 542 return new AsyncGenerator(fn.apply(this, arguments)); 543 }; 544 }, 545 await: function (value) { 546 return new AwaitValue(value); 547 } 548 }; 549}(); 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565var _extends = Object.assign || function (target) { 566 for (var i = 1; i < arguments.length; i++) { 567 var source = arguments[i]; 568 569 for (var key in source) { 570 if (Object.prototype.hasOwnProperty.call(source, key)) { 571 target[key] = source[key]; 572 } 573 } 574 } 575 576 return target; 577}; 578 579var modalParams = _extends({}, defaultParams); 580var queue = []; 581 582/* 583 * Check for the existence of Promise 584 * Hopefully to avoid many github issues 585 */ 586if (typeof Promise === 'undefined') { 587 error('This package requires a Promise library, please include a shim to enable it in this browser (See: https://github.com/limonte/sweetalert2/wiki/Migration-from-SweetAlert-to-SweetAlert2#1-ie-support)'); 588} 589 590/* 591 * Set type, text and actions on modal 592 */ 593var setParameters = function setParameters(params) { 594 // If a custom element is set, determine if it is valid 595 if (typeof params.target === 'string' && !document.querySelector(params.target) || typeof params.target !== 'string' && !params.target.appendChild) {
596 warn('Target parameter is not valid, defaulting to "body"'); 597 params.target = 'body'; 598 } 599 600 var modal = void 0; 601 var oldModal = getModal(); 602 var targetElement = typeof params.target === 'string' ? document.querySelector(params.target) : params.target; 603 // If the model target has changed, refresh the modal 604 if (oldModal && targetElement && oldModal.parentNode !== targetElement.parentNode) { 605 modal = init(params); 606 } else { 607 modal = oldModal || init(params); 608 } 609 610 for (var param in params) { 611 if (!sweetAlert.isValidParameter(param)) { 612 warn('Unknown parameter "' + param + '"'); 613 } 614 } 615 616 // Set modal width 617 modal.style.width = typeof params.width === 'number' ? params.width + 'px' : params.width; 618 619 modal.style.padding = params.padding + 'px'; 620 modal.style.background = params.background; 621 var successIconParts = modal.querySelectorAll('[class^=swal2-success-circular-line], .swal2-success-fix'); 622 for (var i = 0; i < successIconParts.length; i++) { 623 successIconParts[i].style.background = params.background; 624 } 625 626 var container = getContainer(); 627 var title = getTitle(); 628 var content = getContent(); 629 var buttonsWrapper = getButtonsWrapper(); 630 var confirmButton = getConfirmButton(); 631 var cancelButton = getCancelButton(); 632 var closeButton = getCloseButton(); 633 634 // Title 635 if (params.titleText) { 636 title.innerText = params.titleText; 637 } else { 638 title.innerHTML = params.title.split('\n').join('<br />'); 639 } 640 641 // Content 642 if (params.text || params.html) { 643 if (_typeof(params.html) === 'object') { 644 content.innerHTML = ''; 645 if (0 in params.html) { 646 for (var _i = 0; _i in params.html; _i++) { 647 content.appendChild(params.html[_i].cloneNode(true)); 648 } 649 } else { 650 content.appendChild(params.html.cloneNode(true)); 651 } 652 } else if (params.html) { 653 content.innerHTML = params.html; 654 } else if (params.text) { 655 content.textContent = params.text; 656 } 657 show(content); 658 } else { 659 hide(content); 660 } 661 662 // Position 663 if (params.position in swalClasses) { 664 addClass(container, swalClasses[params.position]); 665 } 666 667 // Grow 668 if (params.grow && typeof params.grow === 'string') { 669 var growClass = 'grow-' + params.grow; 670 if (growClass in swalClasses) { 671 addClass(container, swalClasses[growClass]); 672 } 673 } 674 675 // Close button 676 if (params.showCloseButton) { 677 closeButton.setAttribute('aria-label', params.closeButtonAriaLabel); 678 show(closeButton); 679 } else { 680 hide(closeButton); 681 } 682 683 // Custom Class 684 modal.className = swalClasses.modal; 685 if (params.customClass) { 686 addClass(modal, params.customClass); 687 } 688 689 // Progress steps 690 var progressStepsContainer = getProgressSteps(); 691 var currentProgressStep = parseInt(params.currentProgressStep === null ? sweetAlert.getQueueStep() : params.currentProgressStep, 10); 692 if (params.progressSteps.length) { 693 show(progressStepsContainer); 694 empty(progressStepsContainer); 695 if (currentProgressStep >= params.progressSteps.length) { 696 warn('Invalid currentProgressStep parameter, it should be less than progressSteps.length ' + '(currentProgressStep like JS arrays starts from 0)'); 697 } 698 params.progressSteps.forEach(function (step, index) { 699 var circle = document.createElement('li'); 700 addClass(circle, swalClasses.progresscircle); 701 circle.innerHTML = step; 702 if (index === currentProgressStep) { 703 addClass(circle, swalClasses.activeprogressstep); 704 } 705 progressStepsContainer.appendChild(circle); 706 if (index !== params.progressSteps.length - 1) { 707 var line = document.createElement('li'); 708 addClass(line, swalClasses.progressline); 709 line.style.width = params.progressStepsDistance; 710 progressStepsContainer.appendChild(line); 711 } 712 }); 713 } else { 714 hide(progressStepsContainer); 715 } 716 717 // Icon 718 var icons = getIcons(); 719 for (var _i2 = 0; _i2 < icons.length; _i2++) { 720 hide(icons[_i2]); 721 } 722 if (params.type) {
723 var validType = false; 724 for (var iconType in iconTypes) { 725 if (params.type === iconType) { 726 validType = true; 727 break; 728 } 729 } 730 if (!validType) { 731 error('Unknown alert type: ' + params.type); 732 return false; 733 } 734 var icon = modal.querySelector('.' + swalClasses.icon + '.' + iconTypes[params.type]); 735 show(icon); 736 737 // Animate icon 738 if (params.animation) { 739 switch (params.type) { 740 case 'success': 741 addClass(icon, 'swal2-animate-success-icon'); 742 addClass(icon.querySelector('.swal2-success-line-tip'), 'swal2-animate-success-line-tip'); 743 addClass(icon.querySelector('.swal2-success-line-long'), 'swal2-animate-success-line-long'); 744 break; 745 case 'error': 746 addClass(icon, 'swal2-animate-error-icon'); 747 addClass(icon.querySelector('.swal2-x-mark'), 'swal2-animate-x-mark'); 748 break; 749 default: 750 break; 751 } 752 } 753 } 754 755 // Custom image 756 var image = getImage(); 757 if (params.imageUrl) { 758 image.setAttribute('src', params.imageUrl); 759 image.setAttribute('alt', params.imageAlt); 760 show(image); 761 762 if (params.imageWidth) { 763 image.setAttribute('width', params.imageWidth); 764 } else { 765 image.removeAttribute('width'); 766 } 767 768 if (params.imageHeight) { 769 image.setAttribute('height', params.imageHeight); 770 } else { 771 image.removeAttribute('height'); 772 } 773 774 image.className = swalClasses.image; 775 if (params.imageClass) { 776 addClass(image, params.imageClass); 777 } 778 } else { 779 hide(image); 780 } 781 782 // Cancel button 783 if (params.showCancelButton) { 784 cancelButton.style.display = 'inline-block'; 785 } else { 786 hide(cancelButton); 787 } 788 789 // Confirm button 790 if (params.showConfirmButton) { 791 removeStyleProperty(confirmButton, 'display'); 792 } else { 793 hide(confirmButton); 794 } 795 796 // Buttons wrapper 797 if (!params.showConfirmButton && !params.showCancelButton) { 798 hide(buttonsWrapper); 799 } else { 800 show(buttonsWrapper); 801 } 802 803 // Edit text on confirm and cancel buttons 804 confirmButton.innerHTML = params.confirmButtonText; 805 cancelButton.innerHTML = params.cancelButtonText; 806 807 // ARIA labels for confirm and cancel buttons 808 confirmButton.setAttribute('aria-label', params.confirmButtonAriaLabel); 809 cancelButton.setAttribute('aria-label', params.cancelButtonAriaLabel); 810 811 // Set buttons to selected background colors 812 if (params.buttonsStyling) { 813 confirmButton.style.backgroundColor = params.confirmButtonColor; 814 cancelButton.style.backgroundColor = params.cancelButtonColor; 815 } 816 817 // Add buttons custom classes 818 confirmButton.className = swalClasses.confirm; 819 addClass(confirmButton, params.confirmButtonClass); 820 cancelButton.className = swalClasses.cancel; 821 addClass(cancelButton, params.cancelButtonClass); 822 823 // Buttons styling 824 if (params.buttonsStyling) { 825 addClass(confirmButton, swalClasses.styled); 826 addClass(cancelButton, swalClasses.styled); 827 } else { 828 removeClass(confirmButton, swalClasses.styled); 829 removeClass(cancelButton, swalClasses.styled); 830 831 confirmButton.style.backgroundColor = confirmButton.style.borderLeftColor = confirmButton.style.borderRightColor = ''; 832 cancelButton.style.backgroundColor = cancelButton.style.borderLeftColor = cancelButton.style.borderRightColor = ''; 833 } 834 835 // CSS animation 836 if (params.animation === true) { 837 removeClass(modal, swalClasses.noanimation); 838 } else { 839 addClass(modal, swalClasses.noanimation); 840 } 841 842 // showLoaderOnConfirm && preConfirm 843 if (params.showLoaderOnConfirm && !params.preConfirm) { 844 warn('showLoaderOnConfirm is set to true, but preConfirm is not defined.\n' + 'showLoaderOnConfirm should be used together with preConfirm, see usage example:\n' + 'https://limonte.github.io/sweetalert2/#ajax-request'); 845 } 846}; 847 848/* 849 * Animations 850 */ 851var openModal = function openModal(animation, onBeforeOpen, onComplete) { 852 var container = getContainer(); 853 var modal = getModal(); 854 855 if (onBeforeOpen !== null && typeof onBeforeOpen === 'function') { 856 onBeforeOpen(modal); 857 } 858 859 if (animation) { 860 addClass(modal, swalClasses.show); 861 addClass(container, swalClasses.fade); 862 removeClass(modal, swalClasses.hide); 863 } else { 864 removeClass(modal, swalClasses.fade); 865 } 866 show(modal); 867 868 // scrolling is 'hidden' until animation is done, after that 'auto' 869 container.style.overflowY = 'hidden'; 870 if (animationEndEvent && !hasClass(modal, swalClasses.noanimation)) { 871 modal.addEventListener(animationEndEvent, function swalCloseEventFinished() { 872 modal.removeEventListener(animationEndEvent, swalCloseEventFinished); 873 container.style.overflowY = 'auto'; 874 });
875 } else { 876 container.style.overflowY = 'auto'; 877 } 878 879 addClass(document.documentElement, swalClasses.shown); 880 addClass(document.body, swalClasses.shown); 881 addClass(container, swalClasses.shown); 882 fixScrollbar(); 883 iOSfix(); 884 states.previousActiveElement = document.activeElement; 885 if (onComplete !== null && typeof onComplete === 'function') { 886 setTimeout(function () { 887 onComplete(modal); 888 }); 889 } 890}; 891 892var fixScrollbar = function fixScrollbar() { 893 // for queues, do not do this more than once 894 if (states.previousBodyPadding !== null) { 895 return; 896 } 897 // if the body has overflow 898 if (document.body.scrollHeight > window.innerHeight) { 899 // add padding so the content doesn't shift after removal of scrollbar 900 states.previousBodyPadding = document.body.style.paddingRight; 901 document.body.style.paddingRight = measureScrollbar() + 'px'; 902 } 903}; 904 905var undoScrollbar = function undoScrollbar() { 906 if (states.previousBodyPadding !== null) { 907 document.body.style.paddingRight = states.previousBodyPadding; 908 states.previousBodyPadding = null; 909 } 910}; 911 912// Fix iOS scrolling http://stackoverflow.com/q/39626302/1331425 913var iOSfix = function iOSfix() { 914 var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream; 915 if (iOS && !hasClass(document.body, swalClasses.iosfix)) { 916 var offset = document.body.scrollTop; 917 document.body.style.top = offset * -1 + 'px'; 918 addClass(document.body, swalClasses.iosfix); 919 } 920}; 921 922var undoIOSfix = function undoIOSfix() { 923 if (hasClass(document.body, swalClasses.iosfix)) { 924 var offset = parseInt(document.body.style.top, 10); 925 removeClass(document.body, swalClasses.iosfix); 926 document.body.style.top = ''; 927 document.body.scrollTop = offset * -1; 928 } 929}; 930 931// SweetAlert entry point 932var sweetAlert = function sweetAlert() { 933 for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { 934 args[_key] = arguments[_key]; 935 } 936 937 if (args[0] === undefined) { 938 error('SweetAlert2 expects at least 1 attribute!'); 939 return false; 940 } 941 942 var params = _extends({}, modalParams); 943 944 switch (_typeof(args[0])) { 945 case 'string': 946 params.title = args[0]; 947 params.html = args[1]; 948 params.type = args[2]; 949 950 break; 951 952 case 'object': 953 _extends(params, args[0]); 954 params.extraParams = args[0].extraParams; 955 956 if (params.input === 'email' && params.inputValidator === null) { 957 params.inputValidator = function (email) { 958 return new Promise(function (resolve, reject) { 959 var emailRegex = /^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/; 960 if (emailRegex.test(email)) { 961 resolve(); 962 } else { 963 reject('Invalid email address'); 964 } 965 }); 966 }; 967 } 968 969 if (params.input === 'url' && params.inputValidator === null) { 970 params.inputValidator = function (url) { 971 return new Promise(function (resolve, reject) { 972 // taken from https://stackoverflow.com/a/3809435/1331425 973 var urlRegex = /^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)$/; 974 if (urlRegex.test(url)) { 975 resolve(); 976 } else { 977 reject('Invalid URL'); 978 } 979 }); 980 }; 981 } 982 break; 983 984 default: 985 error('Unexpected type of argument! Expected "string" or "object", got ' + _typeof(args[0])); 986 return false; 987 } 988 989 setParameters(params); 990 991 var container = getContainer(); 992 var modal = getModal(); 993 994 return new Promise(function (resolve, reject) { 995 // Close on timer 996 if (params.timer) { 997 modal.timeout = setTimeout(function () { 998 sweetAlert.closeModal(params.onClose); 999 if (params.useRejections) { 1000 reject('timer'); 1001 } else { 1002 resolve({ dismiss: 'timer' }); 1003 } 1004 }, params.timer); 1005 } 1006 1007 // Get input element by specified type or, if type isn't specified, by params.input 1008 var getInput = function getInput(inputType) { 1009 inputType = inputType || params.input; 1010 if (!inputType) { 1011 return null; 1012 } 1013 switch (inputType) { 1014 case 'select': 1015 case 'textarea': 1016 case 'file': 1017 return getChildByClass(modal, swalClasses[inputType]); 1018 case 'checkbox': 1019 return modal.querySelector('.' + swalClasses.checkbox + ' input'); 1020 case 'radio': 1021 return modal.querySelector('.' + swalClasses.radio + ' input:checked') || modal.querySelector('.' + swalClasses.radio + ' input:first-child'); 1022 case 'range': 1023 return modal.querySelector('.' + swalClasses.range + ' input'); 1024 default: 1025 return getChildByClass(modal, swalClasses.input); 1026 } 1027 }; 1028 1029 // Get the value of the modal input 1030 var getInputValue = function getInputValue() { 1031 var input = getInput(); 1032 if (!input) { 1033 return null; 1034 } 1035 switch (params.input) { 1036 case 'checkbox': 1037 return input.checked ? 1 : 0; 1038 case 'radio': 1039 return input.checked ? input.value : null; 1040 case 'file': 1041 return input.files.length ? input.files[0] : null; 1042 default: 1043 return params.inputAutoTrim ? input.value.trim() : input.value; 1044 } 1045 }; 1046 1047 // input autofocus 1048 if (params.input) { 1049 setTimeout(function () { 1050 var input = getInput(); 1051 if (input) { 1052 focusInput(input); 1053 } 1054 }, 0); 1055 } 1056 1057 var confirm = function confirm(value) { 1058 if (params.showLoaderOnConfirm) { 1059 sweetAlert.showLoading(); 1060 } 1061 1062 if (params.preConfirm) { 1063 params.preConfirm(value, params.extraParams).then(function (preConfirmValue) { 1064 sweetAlert.closeModal(params.onClose); 1065 resolve(preConfirmValue || value); 1066 }, function (error$$1) { 1067 sweetAlert.hideLoading(); 1068 if (error$$1) { 1069 sweetAlert.showValidationError(error$$1); 1070 } 1071 }); 1072 } else { 1073 sweetAlert.closeModal(params.onClose); 1074 if (params.useRejections) { 1075 resolve(value); 1076 } else { 1077 resolve({ value: value });
1078 } 1079 } 1080 }; 1081 1082 // Mouse interactions 1083 var onButtonEvent = function onButtonEvent(event) { 1084 var e = event || window.event; 1085 var target = e.target || e.srcElement; 1086 var confirmButton = getConfirmButton(); 1087 var cancelButton = getCancelButton(); 1088 var targetedConfirm = confirmButton && (confirmButton === target || confirmButton.contains(target)); 1089 var targetedCancel = cancelButton && (cancelButton === target || cancelButton.contains(target)); 1090 1091 switch (e.type) { 1092 case 'mouseover': 1093 case 'mouseup': 1094 if (params.buttonsStyling) { 1095 if (targetedConfirm) { 1096 confirmButton.style.backgroundColor = colorLuminance(params.confirmButtonColor, -0.1); 1097 } else if (targetedCancel) { 1098 cancelButton.style.backgroundColor = colorLuminance(params.cancelButtonColor, -0.1); 1099 } 1100 } 1101 break; 1102 case 'mouseout': 1103 if (params.buttonsStyling) { 1104 if (targetedConfirm) { 1105 confirmButton.style.backgroundColor = params.confirmButtonColor; 1106 } else if (targetedCancel) { 1107 cancelButton.style.backgroundColor = params.cancelButtonColor; 1108 } 1109 } 1110 break; 1111 case 'mousedown': 1112 if (params.buttonsStyling) { 1113 if (targetedConfirm) { 1114 confirmButton.style.backgroundColor = colorLuminance(params.confirmButtonColor, -0.2); 1115 } else if (targetedCancel) { 1116 cancelButton.style.backgroundColor = colorLuminance(params.cancelButtonColor, -0.2); 1117 } 1118 } 1119 break; 1120 case 'click': 1121 // Clicked 'confirm' 1122 if (targetedConfirm && sweetAlert.isVisible()) { 1123 sweetAlert.disableButtons(); 1124 if (params.input) { 1125 var inputValue = getInputValue(); 1126 1127 if (params.inputValidator) { 1128 sweetAlert.disableInput(); 1129 params.inputValidator(inputValue, params.extraParams).then(function () { 1130 sweetAlert.enableButtons(); 1131 sweetAlert.enableInput(); 1132 confirm(inputValue); 1133 }, function (error$$1) { 1134 sweetAlert.enableButtons(); 1135 sweetAlert.enableInput(); 1136 if (error$$1) { 1137 sweetAlert.showValidationError(error$$1); 1138 } 1139 }); 1140 } else { 1141 confirm(inputValue); 1142 } 1143 } else { 1144 confirm(true); 1145 } 1146 1147 // Clicked 'cancel' 1148 } else if (targetedCancel && sweetAlert.isVisible()) { 1149 sweetAlert.disableButtons(); 1150 sweetAlert.closeModal(params.onClose); 1151 if (params.useRejections) { 1152 reject('cancel'); 1153 } else { 1154 resolve({ dismiss: 'cancel' }); 1155 } 1156 } 1157 break; 1158 default: 1159 } 1160 }; 1161 1162 var buttons = modal.querySelectorAll('button'); 1163 for (var i = 0; i < buttons.length; i++) { 1164 buttons[i].onclick = onButtonEvent; 1165 buttons[i].onmouseover = onButtonEvent; 1166 buttons[i].onmouseout = onButtonEvent; 1167 buttons[i].onmousedown = onButtonEvent; 1168 } 1169 1170 // Closing modal by close button 1171 getCloseButton().onclick = function () { 1172 sweetAlert.closeModal(params.onClose); 1173 if (params.useRejections) { 1174 reject('close'); 1175 } else { 1176 resolve({ dismiss: 'close' }); 1177 } 1178 }; 1179 1180 // Closing modal by overlay click 1181 container.onclick = function (e) { 1182 if (e.target !== container) { 1183 return; 1184 } 1185 if (params.allowOutsideClick) { 1186 sweetAlert.closeModal(params.onClose); 1187 if (params.useRejections) { 1188 reject('overlay'); 1189 } else { 1190 resolve({ dismiss: 'overlay' }); 1191 } 1192 } 1193 }; 1194 1195 var buttonsWrapper = getButtonsWrapper(); 1196 var confirmButton = getConfirmButton(); 1197 var cancelButton = getCancelButton(); 1198 1199 // Reverse buttons (Confirm on the right side) 1200 if (params.reverseButtons) { 1201 confirmButton.parentNode.insertBefore(cancelButton, confirmButton); 1202 } else { 1203 confirmButton.parentNode.insertBefore(confirmButton, cancelButton); 1204 } 1205 1206 // Focus handling 1207 var setFocus = function setFocus(index, increment) { 1208 var focusableElements = getFocusableElements(params.focusCancel); 1209 // search for visible elements and select the next possible match 1210 for (var _i3 = 0; _i3 < focusableElements.length; _i3++) { 1211 index = index + increment; 1212 1213 // rollover to first item 1214 if (index === focusableElements.length) { 1215 index = 0; 1216 1217 // go to last item 1218 } else if (index === -1) { 1219 index = focusableElements.length - 1; 1220 } 1221 1222 // determine if element is visible 1223 var el = focusableElements[index]; 1224 if (isVisible(el)) { 1225 return el.focus(); 1226 } 1227 } 1228 }; 1229 1230 var handleKeyDown = function handleKeyDown(event) { 1231 var e = event || window.event; 1232 1233 if (e.key === 'Enter') {
1234 if (e.target === getInput()) { 1235 sweetAlert.clickConfirm(); 1236 e.preventDefault(); 1237 } 1238 1239 // TAB 1240 } else if (e.key === 'Tab') { 1241 var targetElement = e.target || e.srcElement; 1242 1243 var focusableElements = getFocusableElements(params.focusCancel); 1244 var btnIndex = -1; // Find the button - note, this is a nodelist, not an array. 1245 for (var _i4 = 0; _i4 < focusableElements.length; _i4++) { 1246 if (targetElement === focusableElements[_i4]) { 1247 btnIndex = _i4; 1248 break; 1249 } 1250 } 1251 1252 if (!e.shiftKey) { 1253 // Cycle to the next button 1254 setFocus(btnIndex, 1); 1255 } else { 1256 // Cycle to the prev button 1257 setFocus(btnIndex, -1); 1258 } 1259 e.stopPropagation(); 1260 e.preventDefault(); 1261 1262 // ARROWS - switch focus between buttons 1263 } else if (['ArrowLeft', 'ArrowRight', 'ArrowUp', 'Arrowdown'].indexOf(e.key) !== -1) { 1264 // focus Cancel button if Confirm button is currently focused 1265 if (document.activeElement === confirmButton && isVisible(cancelButton)) { 1266 cancelButton.focus(); 1267 // and vice versa 1268 } else if (document.activeElement === cancelButton && isVisible(confirmButton)) { 1269 confirmButton.focus(); 1270 } 1271 1272 // ESC 1273 } else if (e.key === 'Escape' && params.allowEscapeKey === true) { 1274 sweetAlert.closeModal(params.onClose); 1275 if (params.useRejections) { 1276 reject('esc'); 1277 } else { 1278 resolve({ dismiss: 'esc' }); 1279 } 1280 } 1281 }; 1282 1283 if (!window.onkeydown || window.onkeydown.toString() !== handleKeyDown.toString()) { 1284 states.previousWindowKeyDown = window.onkeydown; 1285 window.onkeydown = handleKeyDown; 1286 } 1287 1288 // Loading state 1289 if (params.buttonsStyling) { 1290 confirmButton.style.borderLeftColor = params.confirmButtonColor; 1291 confirmButton.style.borderRightColor = params.confirmButtonColor; 1292 } 1293 1294 /** 1295 * Show spinner instead of Confirm button and disable Cancel button 1296 */ 1297 sweetAlert.hideLoading = sweetAlert.disableLoading = function () { 1298 if (!params.showConfirmButton) { 1299 hide(confirmButton); 1300 if (!params.showCancelButton) { 1301 hide(getButtonsWrapper()); 1302 } 1303 } 1304 removeClass(buttonsWrapper, swalClasses.loading); 1305 removeClass(modal, swalClasses.loading); 1306 modal.removeAttribute('aria-busy'); 1307 confirmButton.disabled = false; 1308 cancelButton.disabled = false; 1309 }; 1310 1311 sweetAlert.getTitle = function () { 1312 return getTitle(); 1313 }; 1314 sweetAlert.getContent = function () { 1315 return getContent(); 1316 }; 1317 sweetAlert.getInput = function () { 1318 return getInput(); 1319 }; 1320 sweetAlert.getImage = function () { 1321 return getImage(); 1322 }; 1323 sweetAlert.getButtonsWrapper = function () { 1324 return getButtonsWrapper(); 1325 }; 1326 sweetAlert.getConfirmButton = function () { 1327 return getConfirmButton(); 1328 }; 1329 sweetAlert.getCancelButton = function () { 1330 return getCancelButton(); 1331 }; 1332 1333 sweetAlert.enableButtons = function () { 1334 confirmButton.disabled = false; 1335 cancelButton.disabled = false; 1336 }; 1337 1338 sweetAlert.disableButtons = function () { 1339 confirmButton.disabled = true; 1340 cancelButton.disabled = true; 1341 }; 1342 1343 sweetAlert.enableConfirmButton = function () { 1344 confirmButton.disabled = false; 1345 }; 1346 1347 sweetAlert.disableConfirmButton = function () { 1348 confirmButton.disabled = true; 1349 }; 1350 1351 sweetAlert.enableInput = function () { 1352 var input = getInput(); 1353 if (!input) { 1354 return false; 1355 } 1356 if (input.type === 'radio') { 1357 var radiosContainer = input.parentNode.parentNode; 1358 var radios = radiosContainer.querySelectorAll('input'); 1359 for (var _i5 = 0; _i5 < radios.length; _i5++) { 1360 radios[_i5].disabled = false; 1361 } 1362 } else { 1363 input.disabled = false; 1364 } 1365 }; 1366 1367 sweetAlert.disableInput = function () { 1368 var input = getInput(); 1369 if (!input) { 1370 return false; 1371 } 1372 if (input && input.type === 'radio') { 1373 var radiosContainer = input.parentNode.parentNode; 1374 var radios = radiosContainer.querySelectorAll('input'); 1375 for (var _i6 = 0; _i6 < radios.length; _i6++) { 1376 radios[_i6].disabled = true; 1377 } 1378 } else { 1379 input.disabled = true; 1380 } 1381 }; 1382 1383 // Show block with validation error 1384 sweetAlert.showValidationError = function (error$$1) {
1385 var validationError = getValidationError(); 1386 validationError.innerHTML = error$$1; 1387 show(validationError); 1388 1389 var input = getInput(); 1390 if (input) { 1391 input.setAttribute('aria-invalid', true); 1392 input.setAttribute('aria-describedBy', swalClasses.validationerror); 1393 focusInput(input); 1394 addClass(input, swalClasses.inputerror); 1395 } 1396 }; 1397 1398 // Hide block with validation error 1399 sweetAlert.resetValidationError = function () { 1400 var validationError = getValidationError(); 1401 hide(validationError); 1402 1403 var input = getInput(); 1404 if (input) { 1405 input.removeAttribute('aria-invalid'); 1406 input.removeAttribute('aria-describedBy'); 1407 removeClass(input, swalClasses.inputerror); 1408 } 1409 }; 1410 1411 sweetAlert.getProgressSteps = function () { 1412 return params.progressSteps; 1413 }; 1414 1415 sweetAlert.setProgressSteps = function (progressSteps) { 1416 params.progressSteps = progressSteps; 1417 setParameters(params); 1418 }; 1419 1420 sweetAlert.showProgressSteps = function () { 1421 show(getProgressSteps()); 1422 }; 1423 1424 sweetAlert.hideProgressSteps = function () { 1425 hide(getProgressSteps()); 1426 }; 1427 1428 sweetAlert.enableButtons(); 1429 sweetAlert.hideLoading(); 1430 sweetAlert.resetValidationError(); 1431 1432 // inputs 1433 var inputTypes = ['input', 'file', 'range', 'select', 'radio', 'checkbox', 'textarea']; 1434 var input = void 0; 1435 for (var _i7 = 0; _i7 < inputTypes.length; _i7++) { 1436 var inputClass = swalClasses[inputTypes[_i7]]; 1437 var inputContainer = getChildByClass(modal, inputClass); 1438 input = getInput(inputTypes[_i7]); 1439 1440 // set attributes 1441 if (input) { 1442 for (var j in input.attributes) { 1443 if (input.attributes.hasOwnProperty(j)) { 1444 var attrName = input.attributes[j].name; 1445 if (attrName !== 'type' && attrName !== 'value') { 1446 input.removeAttribute(attrName); 1447 } 1448 } 1449 } 1450 for (var attr in params.inputAttributes) { 1451 input.setAttribute(attr, params.inputAttributes[attr]); 1452 } 1453 } 1454 1455 // set class 1456 inputContainer.className = inputClass; 1457 if (params.inputClass) { 1458 addClass(inputContainer, params.inputClass); 1459 } 1460 1461 hide(inputContainer); 1462 } 1463 1464 var populateInputOptions = void 0; 1465 switch (params.input) { 1466 case 'text': 1467 case 'email': 1468 case 'password': 1469 case 'number': 1470 case 'tel': 1471 case 'url': 1472 input = getChildByClass(modal, swalClasses.input); 1473 input.value = params.inputValue; 1474 input.placeholder = params.inputPlaceholder; 1475 input.type = params.input; 1476 show(input); 1477 break; 1478 case 'file': 1479 input = getChildByClass(modal, swalClasses.file); 1480 input.placeholder = params.inputPlaceholder; 1481 input.type = params.input; 1482 show(input); 1483 break; 1484 case 'range': 1485 var range = getChildByClass(modal, swalClasses.range); 1486 var rangeInput = range.querySelector('input'); 1487 var rangeOutput = range.querySelector('output'); 1488 rangeInput.value = params.inputValue; 1489 rangeInput.type = params.input; 1490 rangeOutput.value = params.inputValue; 1491 show(range); 1492 break; 1493 case 'select': 1494 var select = getChildByClass(modal, swalClasses.select); 1495 select.innerHTML = ''; 1496 if (params.inputPlaceholder) { 1497 var placeholder = document.createElement('option'); 1498 placeholder.innerHTML = params.inputPlaceholder; 1499 placeholder.value = ''; 1500 placeholder.disabled = true; 1501 placeholder.selected = true; 1502 select.appendChild(placeholder); 1503 } 1504 populateInputOptions = function populateInputOptions(inputOptions) { 1505 for (var optionValue in inputOptions) { 1506 var option = document.createElement('option'); 1507 option.value = optionValue; 1508 option.innerHTML = inputOptions[optionValue]; 1509 if (params.inputValue.toString() === optionValue) { 1510 option.selected = true; 1511 } 1512 select.appendChild(option); 1513 } 1514 show(select); 1515 select.focus(); 1516 }; 1517 break; 1518 case 'radio': 1519 var radio = getChildByClass(modal, swalClasses.radio); 1520 radio.innerHTML = ''; 1521 populateInputOptions = function populateInputOptions(inputOptions) { 1522 for (var radioValue in inputOptions) { 1523 var radioInput = document.createElement('input'); 1524 var radioLabel = document.createElement('label'); 1525 var radioLabelSpan = document.createElement('span'); 1526 radioInput.type = 'radio'; 1527 radioInput.name = swalClasses.radio; 1528 radioInput.value = radioValue; 1529 if (params.inputValue.toString() === radioValue) { 1530 radioInput.checked = true; 1531 } 1532 radioLabelSpan.innerHTML = inputOptions[radioValue]; 1533 radioLabel.appendChild(radioInput); 1534 radioLabel.appendChild(radioLabelSpan); 1535 radioLabel.for = radioInput.id; 1536 radio.appendChild(radioLabel); 1537 } 1538 show(radio); 1539 var radios = radio.querySelectorAll('input'); 1540 if (radios.length) { 1541 radios[0].focus(); 1542 } 1543 }; 1544 break; 1545 case 'checkbox': 1546 var checkbox = getChildByClass(modal, swalClasses.checkbox); 1547 var checkboxInput = getInput('checkbox'); 1548 checkboxInput.type = 'checkbox'; 1549 checkboxInput.value = 1; 1550 checkboxInput.id = swalClasses.checkbox; 1551 checkboxInput.checked = Boolean(params.inputValue); 1552 var label = checkbox.getElementsByTagName('span'); 1553 if (label.length) { 1554 checkbox.removeChild(label[0]); 1555 } 1556 label = document.createElement('span'); 1557 label.innerHTML = params.inputPlaceholder; 1558 checkbox.appendChild(label); 1559 show(checkbox); 1560 break; 1561 case 'textarea': 1562 var textarea = getChildByClass(modal, swalClasses.textarea); 1563 textarea.value = params.inputValue; 1564 textarea.placeholder = params.inputPlaceholder; 1565 show(textarea); 1566 break; 1567 case null: 1568 break; 1569 default: 1570 error('Unexpected type of input! Expected "text", "email", "password", "number", "tel", "select", "radio", "checkbox", "textarea", "file" or "url", got "' + params.input + '"'); 1571 break; 1572 } 1573 1574 if (params.input === 'select' || params.input === 'radio') { 1575 if (params.inputOptions instanceof Promise) { 1576 sweetAlert.showLoading(); 1577 params.inputOptions.then(function (inputOptions) { 1578 sweetAlert.hideLoading(); 1579 populateInputOptions(inputOptions); 1580 }); 1581 } else if (_typeof(params.inputOptions) === 'object') { 1582 populateInputOptions(params.inputOptions); 1583 } else { 1584 error('Unexpected type of inputOptions! Expected object or Promise, got ' + _typeof(params.inputOptions)); 1585 } 1586 } 1587 1588 openModal(params.animation, params.onBeforeOpen, params.onOpen); 1589 1590 if (!params.allowEnterKey) { 1591 if (document.activeElement) { 1592 document.activeElement.blur(); 1593 } 1594 } else if (params.focusCancel && isVisible(cancelButton)) { 1595 cancelButton.focus(); 1596 } else if (params.focusConfirm && isVisible(confirmButton)) { 1597 confirmButton.focus(); 1598 } else { 1599 setFocus(-1, 1); 1600 } 1601 1602 // fix scroll 1603 getContainer().scrollTop = 0; 1604 }); 1605}; 1606 1607/* 1608 * Global function to determine if swal2 modal is shown 1609 */ 1610sweetAlert.isVisible = function () { 1611 return !!getModal(); 1612}; 1613 1614/* 1615 * Global function for chaining sweetAlert modals 1616 */ 1617sweetAlert.queue = function (steps) { 1618 queue = steps; 1619 var resetQueue = function resetQueue() { 1620 queue = []; 1621 document.body.removeAttribute('data-swal2-queue-step'); 1622 }; 1623 var queueResult = []; 1624 return new Promise(function (resolve, reject) { 1625 (function step(i, callback) { 1626 if (i < queue.length) { 1627 document.body.setAttribute('data-swal2-queue-step', i); 1628 1629 sweetAlert(queue[i]).then(function (result) { 1630 queueResult.push(result); 1631 step(i + 1, callback); 1632 }, function (dismiss) { 1633 resetQueue(); 1634 reject(dismiss); 1635 }); 1636 } else { 1637 resetQueue(); 1638 resolve(queueResult); 1639 } 1640 })(0); 1641 }); 1642}; 1643 1644/* 1645 * Global function for getting the index of current modal in queue 1646 */ 1647sweetAlert.getQueueStep = function () { 1648 return document.body.getAttribute('data-swal2-queue-step'); 1649}; 1650 1651/* 1652 * Global function for inserting a modal to the queue 1653 */ 1654sweetAlert.insertQueueStep = function (step, index) { 1655 if (index && index < queue.length) { 1656 return queue.splice(index, 0, step); 1657 } 1658 return queue.push(step); 1659}; 1660 1661/* 1662 * Global function for deleting a modal from the queue 1663 */ 1664sweetAlert.deleteQueueStep = function (index) { 1665 if (typeof queue[index] !== 'undefined') { 1666 queue.splice(index, 1); 1667 } 1668}; 1669 1670/* 1671 * Global function to close sweetAlert 1672 */ 1673sweetAlert.close = sweetAlert.closeModal = function (onComplete) { 1674 var container = getContainer(); 1675 var modal = getModal(); 1676 if (!modal) { 1677 return; 1678 } 1679 removeClass(modal, swalClasses.show); 1680 addClass(modal, swalClasses.hide); 1681 clearTimeout(modal.timeout); 1682 1683 resetPrevState(); 1684 1685 var removeModalAndResetState = function removeModalAndResetState() { 1686 if (container.parentNode) { 1687 container.parentNode.removeChild(container); 1688 } 1689 removeClass(document.documentElement, swalClasses.shown); 1690 removeClass(document.body, swalClasses.shown); 1691 undoScrollbar(); 1692 undoIOSfix(); 1693 }; 1694 1695 // If animation is supported, animate 1696 if (animationEndEvent && !hasClass(modal, swalClasses.noanimation)) { 1697 modal.addEventListener(animationEndEvent, function swalCloseEventFinished() { 1698 modal.removeEventListener(animationEndEvent, swalCloseEventFinished); 1699 if (hasClass(modal, swalClasses.hide)) { 1700 removeModalAndResetState(); 1701 } 1702 });
1703 } else { 1704 // Otherwise, remove immediately 1705 removeModalAndResetState(); 1706 } 1707 if (onComplete !== null && typeof onComplete === 'function') { 1708 setTimeout(function () { 1709 onComplete(modal); 1710 }); 1711 } 1712}; 1713 1714/* 1715 * Global function to click 'Confirm' button 1716 */ 1717sweetAlert.clickConfirm = function () { 1718 return getConfirmButton().click(); 1719}; 1720 1721/* 1722 * Global function to click 'Cancel' button 1723 */ 1724sweetAlert.clickCancel = function () { 1725 return getCancelButton().click(); 1726}; 1727 1728/** 1729 * Show spinner instead of Confirm button and disable Cancel button 1730 */ 1731sweetAlert.showLoading = sweetAlert.enableLoading = function () { 1732 var modal = getModal(); 1733 if (!modal) { 1734 sweetAlert(''); 1735 } 1736 modal = getModal(); 1737 var buttonsWrapper = getButtonsWrapper(); 1738 var confirmButton = getConfirmButton(); 1739 var cancelButton = getCancelButton(); 1740 1741 show(buttonsWrapper); 1742 show(confirmButton, 'inline-block'); 1743 addClass(buttonsWrapper, swalClasses.loading); 1744 addClass(modal, swalClasses.loading); 1745 confirmButton.disabled = true; 1746 cancelButton.disabled = true; 1747 1748 modal.setAttribute('aria-busy', true); 1749 modal.focus(); 1750}; 1751 1752/** 1753 * Is valid parameter 1754 * @param {String} paramName 1755 */ 1756sweetAlert.isValidParameter = function (paramName) { 1757 return defaultParams.hasOwnProperty(paramName) || paramName === 'extraParams'; 1758}; 1759 1760/** 1761* Set default params for each popup 1762* @param {Object} userParams 1763*/ 1764sweetAlert.setDefaults = function (userParams) { 1765 if (!userParams || (typeof userParams === 'undefined' ? 'undefined' : _typeof(userParams)) !== 'object') { 1766 return error('the argument for setDefaults() is required and has to be a object'); 1767 } 1768 1769 for (var param in userParams) { 1770 if (!sweetAlert.isValidParameter(param)) { 1771 warn('Unknown parameter "' + param + '"'); 1772 delete userParams[param]; 1773 } 1774 } 1775 1776 _extends(modalParams, userParams); 1777}; 1778 1779/** 1780 * Reset default params for each popup 1781 */ 1782sweetAlert.resetDefaults = function () { 1783 modalParams = _extends({}, defaultParams); 1784}; 1785 1786sweetAlert.noop = function () {}; 1787 1788sweetAlert.version = '6.11.1'; 1789 1790sweetAlert.default = sweetAlert; 1791 1792return sweetAlert; 1793 1794}))); 1795if (window.Sweetalert2) window.sweetAlert = window.swal = window.Sweetalert2;
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.