| 1 |
/*! |
| 2 |
* sweetalert2 v6.6.6 |
| 3 |
* Released under the MIT License. |
| 4 |
*/ |
| 5 |
(function (global, factory) { |
| 6 |
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
| 7 |
typeof define === 'function' && define.amd ? define(factory) : |
| 8 |
(global.Sweetalert2 = factory()); |
| 9 |
}(this, (function () { 'use strict'; |
| 10 |
|
| 11 |
var 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 |
|
| 61 |
var swalPrefix = 'swal2-'; |
| 62 |
|
| 63 |
var 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 |
|
| 71 |
var 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 |
|
| 73 |
var 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 |
*/ |
| 78 |
var 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 |
|
| 97 |
var 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. |
| 110 |
var states = { |
| 111 |
previousWindowKeyDown: null, |
| 112 |
previousActiveElement: null, |
| 113 |
previousBodyPadding: null |
| 114 |
|
| 115 |
/* |
| 116 |
* Add modal + overlay to DOM |
| 117 |
*/ |
| 118 |
};var init = function init(params) { |
| 119 |
if (typeof document === 'undefined') { |
| 120 |
console.error('SweetAlert2 requires document to initialize'); |
| 121 |
return; |
| 122 |
} |
| 123 |
|
| 124 |
var container = document.createElement('div'); |
| 125 |
container.className = swalClasses.container; |
| 126 |
container.innerHTML = sweetHTML; |
| 127 |
|
| 128 |
var targetElement = document.querySelector(params.target); |
| 129 |
if (!targetElement) { |
| 130 |
console.warn('SweetAlert2: Can\'t find the target "' + params.target + '"'); |
| 131 |
targetElement = document.body; |
| 132 |
} |
| 133 |
targetElement.appendChild(container); |
| 134 |
|
| 135 |
var modal = getModal(); |
| 136 |
var input = getChildByClass(modal, swalClasses.input); |
| 137 |
var file = getChildByClass(modal, swalClasses.file); |
| 138 |
var range = modal.querySelector('.' + swalClasses.range + ' input'); |
| 139 |
var rangeOutput = modal.querySelector('.' + swalClasses.range + ' output'); |
| 140 |
var select = getChildByClass(modal, swalClasses.select); |
| 141 |
var checkbox = modal.querySelector('.' + swalClasses.checkbox + ' input'); |
| 142 |
var textarea = getChildByClass(modal, swalClasses.textarea); |
| 143 |
|
| 144 |
input.oninput = function () { |
| 145 |
sweetAlert.resetValidationError(); |
| 146 |
}; |
| 147 |
|
| 148 |
input.onkeydown = function (event) { |
| 149 |
setTimeout(function () { |
| 150 |
if (event.keyCode === 13 && params.allowEnterKey) { |
| 151 |
event.stopPropagation(); |
| 152 |
sweetAlert.clickConfirm(); |
| 153 |
} |
| 154 |
}, 0); |
| 155 |
}; |
| 156 |
|
| 157 |
file.onchange = function () { |
| 158 |
sweetAlert.resetValidationError(); |
| 159 |
}; |
| 160 |
|
| 161 |
range.oninput = function () { |
| 162 |
sweetAlert.resetValidationError(); |
| 163 |
rangeOutput.value = range.value; |
| 164 |
}; |
| 165 |
|
| 166 |
range.onchange = function () { |
| 167 |
sweetAlert.resetValidationError(); |
| 168 |
range.previousSibling.value = range.value; |
| 169 |
}; |
| 170 |
|
| 171 |
select.onchange = function () { |
| 172 |
sweetAlert.resetValidationError(); |
| 173 |
}; |
| 174 |
|
| 175 |
checkbox.onchange = function () { |
| 176 |
sweetAlert.resetValidationError(); |
| 177 |
}; |
| 178 |
|
| 179 |
textarea.oninput = function () { |
| 180 |
sweetAlert.resetValidationError(); |
| 181 |
}; |
| 182 |
|
| 183 |
return modal; |
| 184 |
}; |
| 185 |
|
| 186 |
/* |
| 187 |
* Manipulate DOM |
| 188 |
*/ |
| 189 |
|
| 190 |
var 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">\xD7</button>\n </div>\n').replace(/(^|\n)\s*/g, ''); |
| 191 |
|
| 192 |
var getContainer = function getContainer() { |
| 193 |
return document.body.querySelector('.' + swalClasses.container); |
| 194 |
}; |
| 195 |
|
| 196 |
var getModal = function getModal() { |
| 197 |
return getContainer() ? getContainer().querySelector('.' + swalClasses.modal) : null; |
| 198 |
}; |
| 199 |
|
| 200 |
var getIcons = function getIcons() { |
| 201 |
var modal = getModal(); |
| 202 |
return modal.querySelectorAll('.' + swalClasses.icon); |
| 203 |
}; |
| 204 |
|
| 205 |
var elementByClass = function elementByClass(className) { |
| 206 |
return getContainer() ? getContainer().querySelector('.' + className) : null; |
| 207 |
}; |
| 208 |
|
| 209 |
var getTitle = function getTitle() { |
| 210 |
return elementByClass(swalClasses.title); |
| 211 |
}; |
| 212 |
|
| 213 |
var getContent = function getContent() { |
| 214 |
return elementByClass(swalClasses.content); |
| 215 |
}; |
| 216 |
|
| 217 |
var getImage = function getImage() { |
| 218 |
return elementByClass(swalClasses.image); |
| 219 |
}; |
| 220 |
|
| 221 |
var getButtonsWrapper = function getButtonsWrapper() { |
| 222 |
return elementByClass(swalClasses.buttonswrapper); |
| 223 |
}; |
| 224 |
|
| 225 |
var getProgressSteps = function getProgressSteps() { |
| 226 |
return elementByClass(swalClasses.progresssteps); |
| 227 |
}; |
| 228 |
|
| 229 |
var getValidationError = function getValidationError() { |
| 230 |
return elementByClass(swalClasses.validationerror); |
| 231 |
}; |
| 232 |
|
| 233 |
var getConfirmButton = function getConfirmButton() { |
| 234 |
return elementByClass(swalClasses.confirm); |
| 235 |
}; |
| 236 |
|
| 237 |
var getCancelButton = function getCancelButton() { |
| 238 |
return elementByClass(swalClasses.cancel); |
| 239 |
}; |
| 240 |
|
| 241 |
var getCloseButton = function getCloseButton() { |
| 242 |
return elementByClass(swalClasses.close); |
| 243 |
}; |
| 244 |
|
| 245 |
var getFocusableElements = function getFocusableElements(focusCancel) { |
| 246 |
var buttons = [getConfirmButton(), getCancelButton()]; |
| 247 |
if (focusCancel) { |
| 248 |
buttons.reverse(); |
| 249 |
} |
| 250 |
var focusableElements = buttons.concat(Array.prototype.slice.call(getModal().querySelectorAll('button, input:not([type=hidden]), textarea, select, a, *[tabindex]:not([tabindex="-1"])'))); |
| 251 |
return uniqueArray(focusableElements); |
| 252 |
}; |
| 253 |
|
| 254 |
var hasClass = function hasClass(elem, className) { |
| 255 |
if (elem.classList) { |
| 256 |
return elem.classList.contains(className); |
| 257 |
} |
| 258 |
return false; |
| 259 |
}; |
| 260 |
|
| 261 |
var focusInput = function focusInput(input) { |
| 262 |
input.focus(); |
| 263 |
|
| 264 |
// place cursor at end of text in text input |
| 265 |
if (input.type !== 'file') { |
| 266 |
// http://stackoverflow.com/a/2345915/1331425 |
| 267 |
var val = input.value; |
| 268 |
input.value = ''; |
| 269 |
input.value = val; |
| 270 |
} |
| 271 |
}; |
| 272 |
|
| 273 |
var addClass = function addClass(elem, className) { |
| 274 |
if (!elem || !className) { |
| 275 |
return; |
| 276 |
} |
| 277 |
var classes = className.split(/\s+/).filter(Boolean); |
| 278 |
classes.forEach(function (className) { |
| 279 |
elem.classList.add(className); |
| 280 |
}); |
| 281 |
}; |
| 282 |
|
| 283 |
var removeClass = function removeClass(elem, className) { |
| 284 |
if (!elem || !className) { |
| 285 |
return; |
| 286 |
} |
| 287 |
var classes = className.split(/\s+/).filter(Boolean); |
| 288 |
classes.forEach(function (className) { |
| 289 |
elem.classList.remove(className); |
| 290 |
}); |
| 291 |
}; |
| 292 |
|
| 293 |
var getChildByClass = function getChildByClass(elem, className) { |
| 294 |
for (var i = 0; i < elem.childNodes.length; i++) { |
| 295 |
if (hasClass(elem.childNodes[i], className)) { |
| 296 |
return elem.childNodes[i]; |
| 297 |
} |
| 298 |
} |
| 299 |
}; |
| 300 |
|
| 301 |
var show = function show(elem, display) { |
| 302 |
if (!display) { |
| 303 |
display = 'block'; |
| 304 |
} |
| 305 |
elem.style.opacity = ''; |
| 306 |
elem.style.display = display; |
| 307 |
}; |
| 308 |
|
| 309 |
var hide = function hide(elem) { |
| 310 |
elem.style.opacity = ''; |
| 311 |
elem.style.display = 'none'; |
| 312 |
}; |
| 313 |
|
| 314 |
var empty = function empty(elem) { |
| 315 |
while (elem.firstChild) { |
| 316 |
elem.removeChild(elem.firstChild); |
| 317 |
} |
| 318 |
}; |
| 319 |
|
| 320 |
// borrowed from jqeury $(elem).is(':visible') implementation |
| 321 |
var isVisible = function isVisible(elem) { |
| 322 |
return elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length; |
| 323 |
}; |
| 324 |
|
| 325 |
var removeStyleProperty = function removeStyleProperty(elem, property) { |
| 326 |
if (elem.style.removeProperty) { |
| 327 |
elem.style.removeProperty(property); |
| 328 |
} else { |
| 329 |
elem.style.removeAttribute(property); |
| 330 |
} |
| 331 |
}; |
| 332 |
|
| 333 |
var fireClick = function fireClick(node) { |
| 334 |
if (!isVisible(node)) { |
| 335 |
return false; |
| 336 |
} |
| 337 |
|
| 338 |
// Taken from http://www.nonobtrusive.com/2011/11/29/programatically-fire-crossbrowser-click-event-with-javascript/ |
| 339 |
// Then fixed for today's Chrome browser. |
| 340 |
if (typeof MouseEvent === 'function') { |
| 341 |
// Up-to-date approach |
| 342 |
var mevt = new MouseEvent('click', { |
| 343 |
view: window, |
| 344 |
bubbles: false, |
| 345 |
cancelable: true |
| 346 |
}); |
| 347 |
node.dispatchEvent(mevt); |
| 348 |
} else if (document.createEvent) { |
| 349 |
// Fallback |
| 350 |
var evt = document.createEvent('MouseEvents'); |
| 351 |
evt.initEvent('click', false, false); |
| 352 |
node.dispatchEvent(evt); |
| 353 |
} else if (document.createEventObject) { |
| 354 |
node.fireEvent('onclick'); |
| 355 |
} else if (typeof node.onclick === 'function') { |
| 356 |
node.onclick(); |
| 357 |
} |
| 358 |
}; |
| 359 |
|
| 360 |
var animationEndEvent = function () { |
| 361 |
var testEl = document.createElement('div'); |
| 362 |
var transEndEventNames = { |
| 363 |
'WebkitAnimation': 'webkitAnimationEnd', |
| 364 |
'OAnimation': 'oAnimationEnd oanimationend', |
| 365 |
'msAnimation': 'MSAnimationEnd', |
| 366 |
'animation': 'animationend' |
| 367 |
}; |
| 368 |
for (var i in transEndEventNames) { |
| 369 |
if (transEndEventNames.hasOwnProperty(i) && testEl.style[i] !== undefined) { |
| 370 |
return transEndEventNames[i]; |
| 371 |
} |
| 372 |
} |
| 373 |
|
| 374 |
return false; |
| 375 |
}(); |
| 376 |
|
| 377 |
// Reset previous window keydown handler and focued element |
| 378 |
var resetPrevState = function resetPrevState() { |
| 379 |
window.onkeydown = states.previousWindowKeyDown; |
| 380 |
if (states.previousActiveElement && states.previousActiveElement.focus) { |
| 381 |
var x = window.scrollX; |
| 382 |
var y = window.scrollY; |
| 383 |
states.previousActiveElement.focus(); |
| 384 |
if (x && y) { |
| 385 |
// IE has no scrollX/scrollY support |
| 386 |
window.scrollTo(x, y); |
| 387 |
} |
| 388 |
} |
| 389 |
}; |
| 390 |
|
| 391 |
// Measure width of scrollbar |
| 392 |
// https://github.com/twbs/bootstrap/blob/master/js/modal.js#L279-L286 |
| 393 |
var measureScrollbar = function measureScrollbar() { |
| 394 |
var supportsTouch = 'ontouchstart' in window || navigator.msMaxTouchPoints; |
| 395 |
if (supportsTouch) { |
| 396 |
return 0; |
| 397 |
} |
| 398 |
var scrollDiv = document.createElement('div'); |
| 399 |
scrollDiv.style.width = '50px'; |
| 400 |
scrollDiv.style.height = '50px'; |
| 401 |
scrollDiv.style.overflow = 'scroll'; |
| 402 |
document.body.appendChild(scrollDiv); |
| 403 |
var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth; |
| 404 |
document.body.removeChild(scrollDiv); |
| 405 |
return scrollbarWidth; |
| 406 |
}; |
| 407 |
|
| 408 |
// JavaScript Debounce Function |
| 409 |
// Simplivied version of https://davidwalsh.name/javascript-debounce-function |
| 410 |
var debounce = function debounce(func, wait) { |
| 411 |
var timeout = void 0; |
| 412 |
return function () { |
| 413 |
var later = function later() { |
| 414 |
timeout = null; |
| 415 |
func(); |
| 416 |
}; |
| 417 |
clearTimeout(timeout); |
| 418 |
timeout = setTimeout(later, wait); |
| 419 |
}; |
| 420 |
}; |
| 421 |
|
| 422 |
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { |
| 423 |
return typeof obj; |
| 424 |
} : function (obj) { |
| 425 |
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; |
| 426 |
}; |
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
var _extends = Object.assign || function (target) { |
| 449 |
for (var i = 1; i < arguments.length; i++) { |
| 450 |
var source = arguments[i]; |
| 451 |
|
| 452 |
for (var key in source) { |
| 453 |
if (Object.prototype.hasOwnProperty.call(source, key)) { |
| 454 |
target[key] = source[key]; |
| 455 |
} |
| 456 |
} |
| 457 |
} |
| 458 |
|
| 459 |
return target; |
| 460 |
}; |
| 461 |
|
| 462 |
var modalParams = _extends({}, defaultParams); |
| 463 |
var queue = []; |
| 464 |
var swal2Observer = void 0; |
| 465 |
|
| 466 |
/* |
| 467 |
* Set type, text and actions on modal |
| 468 |
*/ |
| 469 |
var setParameters = function setParameters(params) { |
| 470 |
var modal = getModal() || init(params); |
| 471 |
|
| 472 |
for (var param in params) { |
| 473 |
if (!defaultParams.hasOwnProperty(param) && param !== 'extraParams') { |
| 474 |
console.warn('SweetAlert2: Unknown parameter "' + param + '"'); |
| 475 |
} |
| 476 |
} |
| 477 |
|
| 478 |
// Set modal width |
| 479 |
modal.style.width = typeof params.width === 'number' ? params.width + 'px' : params.width; |
| 480 |
|
| 481 |
modal.style.padding = params.padding + 'px'; |
| 482 |
modal.style.background = params.background; |
| 483 |
var successIconParts = modal.querySelectorAll('[class^=swal2-success-circular-line], .swal2-success-fix'); |
| 484 |
for (var i = 0; i < successIconParts.length; i++) { |
| 485 |
successIconParts[i].style.background = params.background; |
| 486 |
} |
| 487 |
|
| 488 |
var title = getTitle(); |
| 489 |
var content = getContent(); |
| 490 |
var buttonsWrapper = getButtonsWrapper(); |
| 491 |
var confirmButton = getConfirmButton(); |
| 492 |
var cancelButton = getCancelButton(); |
| 493 |
var closeButton = getCloseButton(); |
| 494 |
|
| 495 |
// Title |
| 496 |
if (params.titleText) { |
| 497 |
title.innerText = params.titleText; |
| 498 |
} else { |
| 499 |
title.innerHTML = params.title.split('\n').join('<br />'); |
| 500 |
} |
| 501 |
|
| 502 |
// Content |
| 503 |
if (params.text || params.html) { |
| 504 |
if (_typeof(params.html) === 'object') { |
| 505 |
content.innerHTML = ''; |
| 506 |
if (0 in params.html) { |
| 507 |
for (var _i = 0; _i in params.html; _i++) { |
| 508 |
content.appendChild(params.html[_i].cloneNode(true)); |
| 509 |
} |
| 510 |
} else { |
| 511 |
content.appendChild(params.html.cloneNode(true)); |
| 512 |
} |
| 513 |
} else if (params.html) { |
| 514 |
content.innerHTML = params.html; |
| 515 |
} else if (params.text) { |
| 516 |
content.textContent = params.text; |
| 517 |
} |
| 518 |
show(content); |
| 519 |
} else { |
| 520 |
hide(content); |
| 521 |
} |
| 522 |
|
| 523 |
// Close button |
| 524 |
if (params.showCloseButton) { |
| 525 |
show(closeButton); |
| 526 |
} else { |
| 527 |
hide(closeButton); |
| 528 |
} |
| 529 |
|
| 530 |
// Custom Class |
| 531 |
modal.className = swalClasses.modal; |
| 532 |
if (params.customClass) { |
| 533 |
addClass(modal, params.customClass); |
| 534 |
} |
| 535 |
|
| 536 |
// Progress steps |
| 537 |
var progressStepsContainer = getProgressSteps(); |
| 538 |
var currentProgressStep = parseInt(params.currentProgressStep === null ? sweetAlert.getQueueStep() : params.currentProgressStep, 10); |
| 539 |
if (params.progressSteps.length) { |
| 540 |
show(progressStepsContainer); |
| 541 |
empty(progressStepsContainer); |
| 542 |
if (currentProgressStep >= params.progressSteps.length) { |
| 543 |
console.warn('SweetAlert2: Invalid currentProgressStep parameter, it should be less than progressSteps.length ' + '(currentProgressStep like JS arrays starts from 0)'); |
| 544 |
} |
| 545 |
params.progressSteps.forEach(function (step, index) { |
| 546 |
var circle = document.createElement('li'); |
| 547 |
addClass(circle, swalClasses.progresscircle); |
| 548 |
circle.innerHTML = step; |
| 549 |
if (index === currentProgressStep) { |
| 550 |
addClass(circle, swalClasses.activeprogressstep); |
| 551 |
} |
| 552 |
progressStepsContainer.appendChild(circle); |
| 553 |
if (index !== params.progressSteps.length - 1) { |
| 554 |
var line = document.createElement('li'); |
| 555 |
addClass(line, swalClasses.progressline); |
| 556 |
line.style.width = params.progressStepsDistance; |
| 557 |
progressStepsContainer.appendChild(line); |
| 558 |
} |
| 559 |
}); |
| 560 |
} else { |
| 561 |
hide(progressStepsContainer); |
| 562 |
} |
| 563 |
|
| 564 |
// Icon |
| 565 |
var icons = getIcons(); |
| 566 |
for (var _i2 = 0; _i2 < icons.length; _i2++) { |
| 567 |
hide(icons[_i2]); |
| 568 |
} |
| 569 |
if (params.type) { |
| 570 |
var validType = false; |
| 571 |
for (var iconType in iconTypes) { |
| 572 |
if (params.type === iconType) { |
| 573 |
validType = true; |
| 574 |
break; |
| 575 |
} |
| 576 |
} |
| 577 |
if (!validType) { |
| 578 |
console.error('SweetAlert2: Unknown alert type: ' + params.type); |
| 579 |
return false; |
| 580 |
} |
| 581 |
var icon = modal.querySelector('.' + swalClasses.icon + '.' + iconTypes[params.type]); |
| 582 |
show(icon); |
| 583 |
|
| 584 |
// Animate icon |
| 585 |
if (params.animation) { |
| 586 |
switch (params.type) { |
| 587 |
case 'success': |
| 588 |
addClass(icon, 'swal2-animate-success-icon'); |
| 589 |
addClass(icon.querySelector('.swal2-success-line-tip'), 'swal2-animate-success-line-tip'); |
| 590 |
addClass(icon.querySelector('.swal2-success-line-long'), 'swal2-animate-success-line-long'); |
| 591 |
break; |
| 592 |
case 'error': |
| 593 |
addClass(icon, 'swal2-animate-error-icon'); |
| 594 |
addClass(icon.querySelector('.swal2-x-mark'), 'swal2-animate-x-mark'); |
| 595 |
break; |
| 596 |
default: |
| 597 |
break; |
| 598 |
} |
| 599 |
} |
| 600 |
} |
| 601 |
|
| 602 |
// Custom image |
| 603 |
var image = getImage(); |
| 604 |
if (params.imageUrl) { |
| 605 |
image.setAttribute('src', params.imageUrl); |
| 606 |
show(image); |
| 607 |
|
| 608 |
if (params.imageWidth) { |
| 609 |
image.setAttribute('width', params.imageWidth); |
| 610 |
} else { |
| 611 |
image.removeAttribute('width'); |
| 612 |
} |
| 613 |
|
| 614 |
if (params.imageHeight) { |
| 615 |
image.setAttribute('height', params.imageHeight); |
| 616 |
} else { |
| 617 |
image.removeAttribute('height'); |
| 618 |
} |
| 619 |
|
| 620 |
image.className = swalClasses.image; |
| 621 |
if (params.imageClass) { |
| 622 |
addClass(image, params.imageClass); |
| 623 |
} |
| 624 |
} else { |
| 625 |
hide(image); |
| 626 |
} |
| 627 |
|
| 628 |
// Cancel button |
| 629 |
if (params.showCancelButton) { |
| 630 |
cancelButton.style.display = 'inline-block'; |
| 631 |
} else { |
| 632 |
hide(cancelButton); |
| 633 |
} |
| 634 |
|
| 635 |
// Confirm button |
| 636 |
if (params.showConfirmButton) { |
| 637 |
removeStyleProperty(confirmButton, 'display'); |
| 638 |
} else { |
| 639 |
hide(confirmButton); |
| 640 |
} |
| 641 |
|
| 642 |
// Buttons wrapper |
| 643 |
if (!params.showConfirmButton && !params.showCancelButton) { |
| 644 |
hide(buttonsWrapper); |
| 645 |
} else { |
| 646 |
show(buttonsWrapper); |
| 647 |
} |
| 648 |
|
| 649 |
// Edit text on cancel and confirm buttons |
| 650 |
confirmButton.innerHTML = params.confirmButtonText; |
| 651 |
cancelButton.innerHTML = params.cancelButtonText; |
| 652 |
|
| 653 |
// Set buttons to selected background colors |
| 654 |
if (params.buttonsStyling) { |
| 655 |
confirmButton.style.backgroundColor = params.confirmButtonColor; |
| 656 |
cancelButton.style.backgroundColor = params.cancelButtonColor; |
| 657 |
} |
| 658 |
|
| 659 |
// Add buttons custom classes |
| 660 |
confirmButton.className = swalClasses.confirm; |
| 661 |
addClass(confirmButton, params.confirmButtonClass); |
| 662 |
cancelButton.className = swalClasses.cancel; |
| 663 |
addClass(cancelButton, params.cancelButtonClass); |
| 664 |
|
| 665 |
// Buttons styling |
| 666 |
if (params.buttonsStyling) { |
| 667 |
addClass(confirmButton, swalClasses.styled); |
| 668 |
addClass(cancelButton, swalClasses.styled); |
| 669 |
} else { |
| 670 |
removeClass(confirmButton, swalClasses.styled); |
| 671 |
removeClass(cancelButton, swalClasses.styled); |
| 672 |
|
| 673 |
confirmButton.style.backgroundColor = confirmButton.style.borderLeftColor = confirmButton.style.borderRightColor = ''; |
| 674 |
cancelButton.style.backgroundColor = cancelButton.style.borderLeftColor = cancelButton.style.borderRightColor = ''; |
| 675 |
} |
| 676 |
|
| 677 |
// CSS animation |
| 678 |
if (params.animation === true) { |
| 679 |
removeClass(modal, swalClasses.noanimation); |
| 680 |
} else { |
| 681 |
addClass(modal, swalClasses.noanimation); |
| 682 |
} |
| 683 |
}; |
| 684 |
|
| 685 |
/* |
| 686 |
* Animations |
| 687 |
*/ |
| 688 |
var openModal = function openModal(animation, onComplete) { |
| 689 |
var container = getContainer(); |
| 690 |
var modal = getModal(); |
| 691 |
|
| 692 |
if (animation) { |
| 693 |
addClass(modal, swalClasses.show); |
| 694 |
addClass(container, swalClasses.fade); |
| 695 |
removeClass(modal, swalClasses.hide); |
| 696 |
} else { |
| 697 |
removeClass(modal, swalClasses.fade); |
| 698 |
} |
| 699 |
show(modal); |
| 700 |
|
| 701 |
// scrolling is 'hidden' until animation is done, after that 'auto' |
| 702 |
container.style.overflowY = 'hidden'; |
| 703 |
if (animationEndEvent && !hasClass(modal, swalClasses.noanimation)) { |
| 704 |
modal.addEventListener(animationEndEvent, function swalCloseEventFinished() { |
| 705 |
modal.removeEventListener(animationEndEvent, swalCloseEventFinished); |
| 706 |
container.style.overflowY = 'auto'; |
| 707 |
}); |
| 708 |
} else { |
| 709 |
container.style.overflowY = 'auto'; |
| 710 |
} |
| 711 |
|
| 712 |
addClass(document.documentElement, swalClasses.shown); |
| 713 |
addClass(document.body, swalClasses.shown); |
| 714 |
addClass(container, swalClasses.shown); |
| 715 |
fixScrollbar(); |
| 716 |
iOSfix(); |
| 717 |
states.previousActiveElement = document.activeElement; |
| 718 |
if (onComplete !== null && typeof onComplete === 'function') { |
| 719 |
setTimeout(function () { |
| 720 |
onComplete(modal); |
| 721 |
}); |
| 722 |
} |
| 723 |
}; |
| 724 |
|
| 725 |
var fixScrollbar = function fixScrollbar() { |
| 726 |
// for queues, do not do this more than once |
| 727 |
if (states.previousBodyPadding !== null) { |
| 728 |
return; |
| 729 |
} |
| 730 |
// if the body has overflow |
| 731 |
if (document.body.scrollHeight > window.innerHeight) { |
| 732 |
// add padding so the content doesn't shift after removal of scrollbar |
| 733 |
states.previousBodyPadding = document.body.style.paddingRight; |
| 734 |
document.body.style.paddingRight = measureScrollbar() + 'px'; |
| 735 |
} |
| 736 |
}; |
| 737 |
|
| 738 |
var undoScrollbar = function undoScrollbar() { |
| 739 |
if (states.previousBodyPadding !== null) { |
| 740 |
document.body.style.paddingRight = states.previousBodyPadding; |
| 741 |
states.previousBodyPadding = null; |
| 742 |
} |
| 743 |
}; |
| 744 |
|
| 745 |
// Fix iOS scrolling http://stackoverflow.com/q/39626302/1331425 |
| 746 |
var iOSfix = function iOSfix() { |
| 747 |
var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream; |
| 748 |
if (iOS && !hasClass(document.body, swalClasses.iosfix)) { |
| 749 |
var offset = document.body.scrollTop; |
| 750 |
document.body.style.top = offset * -1 + 'px'; |
| 751 |
addClass(document.body, swalClasses.iosfix); |
| 752 |
} |
| 753 |
}; |
| 754 |
|
| 755 |
var undoIOSfix = function undoIOSfix() { |
| 756 |
if (hasClass(document.body, swalClasses.iosfix)) { |
| 757 |
var offset = parseInt(document.body.style.top, 10); |
| 758 |
removeClass(document.body, swalClasses.iosfix); |
| 759 |
document.body.style.top = ''; |
| 760 |
document.body.scrollTop = offset * -1; |
| 761 |
} |
| 762 |
}; |
| 763 |
|
| 764 |
// SweetAlert entry point |
| 765 |
var sweetAlert = function sweetAlert() { |
| 766 |
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { |
| 767 |
args[_key] = arguments[_key]; |
| 768 |
} |
| 769 |
|
| 770 |
if (args[0] === undefined) { |
| 771 |
console.error('SweetAlert2 expects at least 1 attribute!'); |
| 772 |
return false; |
| 773 |
} |
| 774 |
|
| 775 |
var params = _extends({}, modalParams); |
| 776 |
|
| 777 |
switch (_typeof(args[0])) { |
| 778 |
case 'string': |
| 779 |
params.title = args[0]; |
| 780 |
params.html = args[1]; |
| 781 |
params.type = args[2]; |
| 782 |
|
| 783 |
break; |
| 784 |
|
| 785 |
case 'object': |
| 786 |
_extends(params, args[0]); |
| 787 |
params.extraParams = args[0].extraParams; |
| 788 |
|
| 789 |
if (params.input === 'email' && params.inputValidator === null) { |
| 790 |
params.inputValidator = function (email) { |
| 791 |
return new Promise(function (resolve, reject) { |
| 792 |
var emailRegex = /^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/; |
| 793 |
if (emailRegex.test(email)) { |
| 794 |
resolve(); |
| 795 |
} else { |
| 796 |
reject('Invalid email address'); |
| 797 |
} |
| 798 |
}); |
| 799 |
}; |
| 800 |
} |
| 801 |
|
| 802 |
if (params.input === 'url' && params.inputValidator === null) { |
| 803 |
params.inputValidator = function (url) { |
| 804 |
return new Promise(function (resolve, reject) { |
| 805 |
// taken from https://stackoverflow.com/a/3809435/1331425 |
| 806 |
var urlRegex = /^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)$/; |
| 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 |
*/ |
| 1468 |
sweetAlert.isVisible = function () { |
| 1469 |
return !!getModal(); |
| 1470 |
}; |
| 1471 |
|
| 1472 |
/* |
| 1473 |
* Global function for chaining sweetAlert modals |
| 1474 |
*/ |
| 1475 |
sweetAlert.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 |
*/ |
| 1505 |
sweetAlert.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 |
*/ |
| 1512 |
sweetAlert.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 |
*/ |
| 1522 |
sweetAlert.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 |
*/ |
| 1531 |
sweetAlert.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 |
*/ |
| 1575 |
sweetAlert.clickConfirm = function () { |
| 1576 |
return getConfirmButton().click(); |
| 1577 |
}; |
| 1578 |
|
| 1579 |
/* |
| 1580 |
* Global function to click 'Cancel' button |
| 1581 |
*/ |
| 1582 |
sweetAlert.clickCancel = function () { |
| 1583 |
return getCancelButton().click(); |
| 1584 |
}; |
| 1585 |
|
| 1586 |
/** |
| 1587 |
* Show spinner instead of Confirm button and disable Cancel button |
| 1588 |
*/ |
| 1589 |
sweetAlert.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 |
*/ |
| 1610 |
sweetAlert.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 |
*/ |
| 1628 |
sweetAlert.resetDefaults = function () { |
| 1629 |
modalParams = _extends({}, defaultParams); |
| 1630 |
}; |
| 1631 |
|
| 1632 |
sweetAlert.noop = function () {}; |
| 1633 |
|
| 1634 |
sweetAlert.version = '6.6.6'; |
| 1635 |
|
| 1636 |
sweetAlert.default = sweetAlert; |
| 1637 |
|
| 1638 |
return sweetAlert; |
| 1639 |
|
| 1640 |
}))); |
| 1641 |
if (window.Sweetalert2) window.sweetAlert = window.swal = window.Sweetalert2; |
| 1642 |
|