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