sweetalert2
Advanced tools
Comparing version 3.1.2 to 3.2.0
/*! | ||
* sweetalert2 v3.1.2 | ||
* sweetalert2 v3.2.0 | ||
* (c) 2016 Tristan Edwards <tristan.edwards@me.com> (http://tristanedwards.me) | ||
@@ -18,10 +18,29 @@ * Released under the MIT License. | ||
var swalClasses = prefix([ | ||
'container', 'modal', 'overlay', 'close', 'content', 'spacer', 'confirm', | ||
'cancel', 'icon', 'image', 'input', 'select', 'radio', 'checkbox', 'textarea', | ||
'container', | ||
'modal', | ||
'overlay', | ||
'close', | ||
'content', | ||
'spacer', | ||
'confirm', | ||
'cancel', | ||
'icon', | ||
'image', | ||
'input', | ||
'select', | ||
'radio', | ||
'checkbox', | ||
'textarea', | ||
'validationerror' | ||
]); | ||
var iconTypes = prefix([ | ||
'success', | ||
'warning', | ||
'info', | ||
'question', | ||
'error' | ||
]); | ||
swalClasses.iconTypes = prefix(['success', 'warning', 'info', 'question', 'error']); | ||
var mediaqueryId = swalPrefix + 'mediaquery'; | ||
var defaultParams = { | ||
@@ -65,3 +84,71 @@ title: '', | ||
var sweetHTML = '<div class="' + swalClasses.overlay + '" tabIndex="-1"></div>' + | ||
'<div class="' + swalClasses.modal + '" style="display: none" tabIndex="-1">' + | ||
'<div class="' + swalClasses.icon + ' ' + iconTypes.error + '">' + | ||
'<span class="x-mark"><span class="line left"></span><span class="line right"></span></span>' + | ||
'</div>' + | ||
'<div class="' + swalClasses.icon + ' ' + iconTypes.question + '">?</div>' + | ||
'<div class="' + swalClasses.icon + ' ' + iconTypes.warning + '">!</div>' + | ||
'<div class="' + swalClasses.icon + ' ' + iconTypes.info + '">i</div>' + | ||
'<div class="' + swalClasses.icon + ' ' + iconTypes.success + '">' + | ||
'<span class="line tip"></span> <span class="line long"></span>' + | ||
'<div class="placeholder"></div> <div class="fix"></div>' + | ||
'</div>' + | ||
'<img class="' + swalClasses.image + '">' + | ||
'<h2></h2>' + | ||
'<div class="' + swalClasses.content + '"></div>' + | ||
'<input class="' + swalClasses.input + '">' + | ||
'<select class="' + swalClasses.select + '"></select>' + | ||
'<div class="' + swalClasses.radio + '"></div>' + | ||
'<label for="' + swalClasses.checkbox + '" class="' + swalClasses.checkbox + '">' + | ||
'<input type="checkbox" id="' + swalClasses.checkbox + '">' + | ||
'</label>' + | ||
'<textarea class="' + swalClasses.textarea + '"></textarea>' + | ||
'<div class="' + swalClasses.validationerror + '"></div>' + | ||
'<hr class="' + swalClasses.spacer + '">' + | ||
'<button class="' + swalClasses.confirm + '">OK</button>' + | ||
'<button class="' + swalClasses.cancel + '">Cancel</button>' + | ||
'<span class="' + swalClasses.close + '">×</span>' + | ||
'</div>'; | ||
var extend = function(a, b) { | ||
for (var key in b) { | ||
if (b.hasOwnProperty(key)) { | ||
a[key] = b[key]; | ||
} | ||
} | ||
return a; | ||
}; | ||
/* | ||
* Set hover, active and focus-states for buttons (source: http://www.sitepoint.com/javascript-generate-lighter-darker-color) | ||
*/ | ||
var colorLuminance = function(hex, lum) { | ||
// Validate hex string | ||
hex = String(hex).replace(/[^0-9a-f]/gi, ''); | ||
if (hex.length < 6) { | ||
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]; | ||
} | ||
lum = lum || 0; | ||
// Convert to decimal and change luminosity | ||
var rgb = '#'; | ||
for (var i = 0; i < 3; i++) { | ||
var c = parseInt(hex.substr(i * 2, 2), 16); | ||
c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16); | ||
rgb += ('00' + c).substr(c.length); | ||
} | ||
return rgb; | ||
}; | ||
var mediaqueryId = swalPrefix + 'mediaquery'; | ||
var previousDocumentClick$1; | ||
var previousWindowKeyDown$1; | ||
var previousActiveElement$1; | ||
var lastFocusedButton$1; | ||
/* | ||
* Manipulate DOM | ||
@@ -206,45 +293,2 @@ */ | ||
var extend = function(a, b) { | ||
for (var key in b) { | ||
if (b.hasOwnProperty(key)) { | ||
a[key] = b[key]; | ||
} | ||
} | ||
return a; | ||
}; | ||
var fireClick = function(node) { | ||
// Taken from http://www.nonobtrusive.com/2011/11/29/programatically-fire-crossbrowser-click-event-with-javascript/ | ||
// Then fixed for today's Chrome browser. | ||
if (typeof MouseEvent === 'function') { | ||
// Up-to-date approach | ||
var mevt = new MouseEvent('click', { | ||
view: window, | ||
bubbles: false, | ||
cancelable: true | ||
}); | ||
node.dispatchEvent(mevt); | ||
} else if (document.createEvent) { | ||
// Fallback | ||
var evt = document.createEvent('MouseEvents'); | ||
evt.initEvent('click', false, false); | ||
node.dispatchEvent(evt); | ||
} else if (document.createEventObject) { | ||
node.fireEvent('onclick'); | ||
} else if (typeof node.onclick === 'function') { | ||
node.onclick(); | ||
} | ||
}; | ||
var stopEventPropagation = function(e) { | ||
// In particular, make sure the space bar doesn't scroll the main window. | ||
if (typeof e.stopPropagation === 'function') { | ||
e.stopPropagation(); | ||
e.preventDefault(); | ||
} else if (window.event && window.event.hasOwnProperty('cancelBubble')) { | ||
window.event.cancelBubble = true; | ||
} | ||
}; | ||
var animationEndEvent = (function() { | ||
@@ -269,7 +313,2 @@ var testEl = document.createElement('div'), | ||
// Remember state in cases where opening and handling a modal will fiddle with it. | ||
var previousDocumentClick; | ||
var previousWindowKeyDown; | ||
var previousActiveElement; | ||
var lastFocusedButton; | ||
@@ -279,8 +318,8 @@ // Reset the page to its previous state | ||
var modal = getModal(); | ||
window.onkeydown = previousWindowKeyDown; | ||
document.onclick = previousDocumentClick; | ||
if (previousActiveElement) { | ||
previousActiveElement.focus(); | ||
window.onkeydown = previousWindowKeyDown$1; | ||
document.onclick = previousDocumentClick$1; | ||
if (previousActiveElement$1) { | ||
previousActiveElement$1.focus(); | ||
} | ||
lastFocusedButton = undefined; | ||
lastFocusedButton$1 = undefined; | ||
clearTimeout(modal.timeout); | ||
@@ -296,25 +335,7 @@ | ||
var previousDocumentClick; | ||
var previousWindowKeyDown; | ||
var previousActiveElement; | ||
var lastFocusedButton; | ||
/* | ||
* Set hover, active and focus-states for buttons (source: http://www.sitepoint.com/javascript-generate-lighter-darker-color) | ||
*/ | ||
var colorLuminance = function(hex, lum) { | ||
// Validate hex string | ||
hex = String(hex).replace(/[^0-9a-f]/gi, ''); | ||
if (hex.length < 6) { | ||
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]; | ||
} | ||
lum = lum || 0; | ||
// Convert to decimal and change luminosity | ||
var rgb = '#'; | ||
for (var i = 0; i < 3; i++) { | ||
var c = parseInt(hex.substr(i * 2, 2), 16); | ||
c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16); | ||
rgb += ('00' + c).substr(c.length); | ||
} | ||
return rgb; | ||
}; | ||
/* | ||
* Set type, text and actions on modal | ||
@@ -396,3 +417,3 @@ */ | ||
var validType = false; | ||
for (var iconType in swalClasses.iconTypes) { | ||
for (var iconType in iconTypes) { | ||
if (params.type === iconType) { | ||
@@ -407,3 +428,3 @@ validType = true; | ||
} | ||
var $icon = modal.querySelector('.' + swalClasses.icon + '.' + swalClasses.iconTypes[params.type]); | ||
var $icon = modal.querySelector('.' + swalClasses.icon + '.' + iconTypes[params.type]); | ||
show($icon); | ||
@@ -657,43 +678,5 @@ | ||
case 'object': | ||
params.title = arguments[0].title || defaultParams.title; | ||
params.text = arguments[0].text || defaultParams.text; | ||
params.html = arguments[0].html || defaultParams.html; | ||
params.type = arguments[0].type || defaultParams.type; | ||
params.animation = arguments[0].animation !== undefined ? arguments[0].animation : defaultParams.animation; | ||
params.customClass = arguments[0].customClass || params.customClass; | ||
params.allowOutsideClick = arguments[0].allowOutsideClick !== undefined ? arguments[0].allowOutsideClick : defaultParams.allowOutsideClick; | ||
params.allowEscapeKey = arguments[0].allowEscapeKey !== undefined ? arguments[0].allowEscapeKey : defaultParams.allowEscapeKey; | ||
params.showConfirmButton = arguments[0].showConfirmButton !== undefined ? arguments[0].showConfirmButton : defaultParams.showConfirmButton; | ||
params.showCancelButton = arguments[0].showCancelButton !== undefined ? arguments[0].showCancelButton : defaultParams.showCancelButton; | ||
params.preConfirm = arguments[0].preConfirm || defaultParams.preConfirm; | ||
params.timer = parseInt(arguments[0].timer, 10) || defaultParams.timer; | ||
params.width = parseInt(arguments[0].width, 10) || defaultParams.width; | ||
params.padding = parseInt(arguments[0].padding, 10) || defaultParams.padding; | ||
params.background = arguments[0].background !== undefined ? arguments[0].background : defaultParams.background; | ||
extend(params, arguments[0]); | ||
params.extraParams = arguments[0].extraParams; | ||
params.confirmButtonText = arguments[0].confirmButtonText || defaultParams.confirmButtonText; | ||
params.confirmButtonColor = arguments[0].confirmButtonColor || defaultParams.confirmButtonColor; | ||
params.confirmButtonClass = arguments[0].confirmButtonClass || params.confirmButtonClass; | ||
params.cancelButtonText = arguments[0].cancelButtonText || defaultParams.cancelButtonText; | ||
params.cancelButtonColor = arguments[0].cancelButtonColor || defaultParams.cancelButtonColor; | ||
params.cancelButtonClass = arguments[0].cancelButtonClass || params.cancelButtonClass; | ||
params.buttonsStyling = arguments[0].buttonsStyling !== undefined ? arguments[0].buttonsStyling : defaultParams.buttonsStyling; | ||
params.reverseButtons = arguments[0].reverseButtons !== undefined ? arguments[0].reverseButtons : defaultParams.reverseButtons; | ||
params.showCloseButton = arguments[0].showCloseButton !== undefined ? arguments[0].showCloseButton : defaultParams.showCloseButton; | ||
params.imageUrl = arguments[0].imageUrl || defaultParams.imageUrl; | ||
params.imageWidth = arguments[0].imageWidth || defaultParams.imageWidth; | ||
params.imageHeight = arguments[0].imageHeight || defaultParams.imageHeight; | ||
params.imageClass = arguments[0].imageClass || defaultParams.imageClass; | ||
params.input = arguments[0].input || defaultParams.input; | ||
params.inputPlaceholder = arguments[0].inputPlaceholder || defaultParams.inputPlaceholder; | ||
params.inputValue = arguments[0].inputValue || defaultParams.inputValue; | ||
params.inputOptions = arguments[0].inputOptions || defaultParams.inputOptions; | ||
params.inputAutoTrim = arguments[0].inputAutoTrim !== undefined ? arguments[0].inputAutoTrim : defaultParams.inputAutoTrim; | ||
params.inputClass = arguments[0].inputClass || defaultParams.inputClass; | ||
params.inputAttributes = arguments[0].inputAttributes || defaultParams.inputAttributes; | ||
params.inputValidator = arguments[0].inputValidator || defaultParams.inputValidator; | ||
params.extraParams = arguments[0].extraParams; | ||
if (params.input === 'email' && params.inputValidator === null) { | ||
@@ -1090,3 +1073,3 @@ params.inputValidator = function(email) { | ||
// Reset icon animations | ||
var $successIcon = modal.querySelector('.' + swalClasses.icon + '.' + swalClasses.iconTypes.success); | ||
var $successIcon = modal.querySelector('.' + swalClasses.icon + '.' + iconTypes.success); | ||
removeClass($successIcon, 'animate'); | ||
@@ -1096,7 +1079,7 @@ removeClass($successIcon.querySelector('.tip'), 'animate-success-tip'); | ||
var $errorIcon = modal.querySelector('.' + swalClasses.icon + '.' + swalClasses.iconTypes.error); | ||
var $errorIcon = modal.querySelector('.' + swalClasses.icon + '.' + iconTypes.error); | ||
removeClass($errorIcon, 'animate-error-icon'); | ||
removeClass($errorIcon.querySelector('.x-mark'), 'animate-x-mark'); | ||
var $warningIcon = modal.querySelector('.' + swalClasses.icon + '.' + swalClasses.iconTypes.warning); | ||
var $warningIcon = modal.querySelector('.' + swalClasses.icon + '.' + iconTypes.warning); | ||
removeClass($warningIcon, 'pulse-warning'); | ||
@@ -1148,32 +1131,3 @@ | ||
} | ||
var sweetHTML = | ||
'<div class="' + swalClasses.overlay + '" tabIndex="-1"></div>' + | ||
'<div class="' + swalClasses.modal + '" style="display: none" tabIndex="-1">' + | ||
'<div class="' + swalClasses.icon + ' ' + swalClasses.iconTypes.error + '">' + | ||
'<span class="x-mark"><span class="line left"></span><span class="line right"></span></span>' + | ||
'</div>' + | ||
'<div class="' + swalClasses.icon + ' ' + swalClasses.iconTypes.question + '">?</div>' + | ||
'<div class="' + swalClasses.icon + ' ' + swalClasses.iconTypes.warning + '">!</div>' + | ||
'<div class="' + swalClasses.icon + ' ' + swalClasses.iconTypes.info + '">i</div>' + | ||
'<div class="' + swalClasses.icon + ' ' + swalClasses.iconTypes.success + '">' + | ||
'<span class="line tip"></span> <span class="line long"></span>' + | ||
'<div class="placeholder"></div> <div class="fix"></div>' + | ||
'</div>' + | ||
'<img class="' + swalClasses.image + '">' + | ||
'<h2></h2>' + | ||
'<div class="' + swalClasses.content + '"></div>' + | ||
'<input class="' + swalClasses.input + '">' + | ||
'<select class="' + swalClasses.select + '"></select>' + | ||
'<div class="' + swalClasses.radio + '"></div>' + | ||
'<label for="' + swalClasses.checkbox + '" class="' + swalClasses.checkbox + '">' + | ||
'<input type="checkbox" id="' + swalClasses.checkbox + '">' + | ||
'</label>' + | ||
'<textarea class="' + swalClasses.textarea + '"></textarea>' + | ||
'<div class="' + swalClasses.validationerror + '"></div>' + | ||
'<hr class="' + swalClasses.spacer + '">' + | ||
'<button class="' + swalClasses.confirm + '">OK</button>' + | ||
'<button class="' + swalClasses.cancel + '">Cancel</button>' + | ||
'<span class="' + swalClasses.close + '">×</span>' + | ||
'</div>'; | ||
var sweetWrap = document.createElement('div'); | ||
@@ -1231,3 +1185,3 @@ sweetWrap.className = swalClasses.container; | ||
sweetAlert.version = '3.1.2'; | ||
sweetAlert.version = '3.2.0'; | ||
@@ -1234,0 +1188,0 @@ window.sweetAlert = window.swal = sweetAlert; |
/*! | ||
* sweetalert2 v3.1.2 | ||
* sweetalert2 v3.2.0 | ||
* (c) 2016 Tristan Edwards <tristan.edwards@me.com> (http://tristanedwards.me) | ||
@@ -22,10 +22,29 @@ * Released under the MIT License. | ||
var swalClasses = prefix([ | ||
'container', 'modal', 'overlay', 'close', 'content', 'spacer', 'confirm', | ||
'cancel', 'icon', 'image', 'input', 'select', 'radio', 'checkbox', 'textarea', | ||
'container', | ||
'modal', | ||
'overlay', | ||
'close', | ||
'content', | ||
'spacer', | ||
'confirm', | ||
'cancel', | ||
'icon', | ||
'image', | ||
'input', | ||
'select', | ||
'radio', | ||
'checkbox', | ||
'textarea', | ||
'validationerror' | ||
]); | ||
var iconTypes = prefix([ | ||
'success', | ||
'warning', | ||
'info', | ||
'question', | ||
'error' | ||
]); | ||
swalClasses.iconTypes = prefix(['success', 'warning', 'info', 'question', 'error']); | ||
var mediaqueryId = swalPrefix + 'mediaquery'; | ||
var defaultParams = { | ||
@@ -69,3 +88,71 @@ title: '', | ||
var sweetHTML = '<div class="' + swalClasses.overlay + '" tabIndex="-1"></div>' + | ||
'<div class="' + swalClasses.modal + '" style="display: none" tabIndex="-1">' + | ||
'<div class="' + swalClasses.icon + ' ' + iconTypes.error + '">' + | ||
'<span class="x-mark"><span class="line left"></span><span class="line right"></span></span>' + | ||
'</div>' + | ||
'<div class="' + swalClasses.icon + ' ' + iconTypes.question + '">?</div>' + | ||
'<div class="' + swalClasses.icon + ' ' + iconTypes.warning + '">!</div>' + | ||
'<div class="' + swalClasses.icon + ' ' + iconTypes.info + '">i</div>' + | ||
'<div class="' + swalClasses.icon + ' ' + iconTypes.success + '">' + | ||
'<span class="line tip"></span> <span class="line long"></span>' + | ||
'<div class="placeholder"></div> <div class="fix"></div>' + | ||
'</div>' + | ||
'<img class="' + swalClasses.image + '">' + | ||
'<h2></h2>' + | ||
'<div class="' + swalClasses.content + '"></div>' + | ||
'<input class="' + swalClasses.input + '">' + | ||
'<select class="' + swalClasses.select + '"></select>' + | ||
'<div class="' + swalClasses.radio + '"></div>' + | ||
'<label for="' + swalClasses.checkbox + '" class="' + swalClasses.checkbox + '">' + | ||
'<input type="checkbox" id="' + swalClasses.checkbox + '">' + | ||
'</label>' + | ||
'<textarea class="' + swalClasses.textarea + '"></textarea>' + | ||
'<div class="' + swalClasses.validationerror + '"></div>' + | ||
'<hr class="' + swalClasses.spacer + '">' + | ||
'<button class="' + swalClasses.confirm + '">OK</button>' + | ||
'<button class="' + swalClasses.cancel + '">Cancel</button>' + | ||
'<span class="' + swalClasses.close + '">×</span>' + | ||
'</div>'; | ||
var extend = function(a, b) { | ||
for (var key in b) { | ||
if (b.hasOwnProperty(key)) { | ||
a[key] = b[key]; | ||
} | ||
} | ||
return a; | ||
}; | ||
/* | ||
* Set hover, active and focus-states for buttons (source: http://www.sitepoint.com/javascript-generate-lighter-darker-color) | ||
*/ | ||
var colorLuminance = function(hex, lum) { | ||
// Validate hex string | ||
hex = String(hex).replace(/[^0-9a-f]/gi, ''); | ||
if (hex.length < 6) { | ||
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]; | ||
} | ||
lum = lum || 0; | ||
// Convert to decimal and change luminosity | ||
var rgb = '#'; | ||
for (var i = 0; i < 3; i++) { | ||
var c = parseInt(hex.substr(i * 2, 2), 16); | ||
c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16); | ||
rgb += ('00' + c).substr(c.length); | ||
} | ||
return rgb; | ||
}; | ||
var mediaqueryId = swalPrefix + 'mediaquery'; | ||
var previousDocumentClick$1; | ||
var previousWindowKeyDown$1; | ||
var previousActiveElement$1; | ||
var lastFocusedButton$1; | ||
/* | ||
* Manipulate DOM | ||
@@ -210,45 +297,2 @@ */ | ||
var extend = function(a, b) { | ||
for (var key in b) { | ||
if (b.hasOwnProperty(key)) { | ||
a[key] = b[key]; | ||
} | ||
} | ||
return a; | ||
}; | ||
var fireClick = function(node) { | ||
// Taken from http://www.nonobtrusive.com/2011/11/29/programatically-fire-crossbrowser-click-event-with-javascript/ | ||
// Then fixed for today's Chrome browser. | ||
if (typeof MouseEvent === 'function') { | ||
// Up-to-date approach | ||
var mevt = new MouseEvent('click', { | ||
view: window, | ||
bubbles: false, | ||
cancelable: true | ||
}); | ||
node.dispatchEvent(mevt); | ||
} else if (document.createEvent) { | ||
// Fallback | ||
var evt = document.createEvent('MouseEvents'); | ||
evt.initEvent('click', false, false); | ||
node.dispatchEvent(evt); | ||
} else if (document.createEventObject) { | ||
node.fireEvent('onclick'); | ||
} else if (typeof node.onclick === 'function') { | ||
node.onclick(); | ||
} | ||
}; | ||
var stopEventPropagation = function(e) { | ||
// In particular, make sure the space bar doesn't scroll the main window. | ||
if (typeof e.stopPropagation === 'function') { | ||
e.stopPropagation(); | ||
e.preventDefault(); | ||
} else if (window.event && window.event.hasOwnProperty('cancelBubble')) { | ||
window.event.cancelBubble = true; | ||
} | ||
}; | ||
var animationEndEvent = (function() { | ||
@@ -273,7 +317,2 @@ var testEl = document.createElement('div'), | ||
// Remember state in cases where opening and handling a modal will fiddle with it. | ||
var previousDocumentClick; | ||
var previousWindowKeyDown; | ||
var previousActiveElement; | ||
var lastFocusedButton; | ||
@@ -283,8 +322,8 @@ // Reset the page to its previous state | ||
var modal = getModal(); | ||
window.onkeydown = previousWindowKeyDown; | ||
document.onclick = previousDocumentClick; | ||
if (previousActiveElement) { | ||
previousActiveElement.focus(); | ||
window.onkeydown = previousWindowKeyDown$1; | ||
document.onclick = previousDocumentClick$1; | ||
if (previousActiveElement$1) { | ||
previousActiveElement$1.focus(); | ||
} | ||
lastFocusedButton = undefined; | ||
lastFocusedButton$1 = undefined; | ||
clearTimeout(modal.timeout); | ||
@@ -300,25 +339,7 @@ | ||
var previousDocumentClick; | ||
var previousWindowKeyDown; | ||
var previousActiveElement; | ||
var lastFocusedButton; | ||
/* | ||
* Set hover, active and focus-states for buttons (source: http://www.sitepoint.com/javascript-generate-lighter-darker-color) | ||
*/ | ||
var colorLuminance = function(hex, lum) { | ||
// Validate hex string | ||
hex = String(hex).replace(/[^0-9a-f]/gi, ''); | ||
if (hex.length < 6) { | ||
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]; | ||
} | ||
lum = lum || 0; | ||
// Convert to decimal and change luminosity | ||
var rgb = '#'; | ||
for (var i = 0; i < 3; i++) { | ||
var c = parseInt(hex.substr(i * 2, 2), 16); | ||
c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16); | ||
rgb += ('00' + c).substr(c.length); | ||
} | ||
return rgb; | ||
}; | ||
/* | ||
* Set type, text and actions on modal | ||
@@ -400,3 +421,3 @@ */ | ||
var validType = false; | ||
for (var iconType in swalClasses.iconTypes) { | ||
for (var iconType in iconTypes) { | ||
if (params.type === iconType) { | ||
@@ -411,3 +432,3 @@ validType = true; | ||
} | ||
var $icon = modal.querySelector('.' + swalClasses.icon + '.' + swalClasses.iconTypes[params.type]); | ||
var $icon = modal.querySelector('.' + swalClasses.icon + '.' + iconTypes[params.type]); | ||
show($icon); | ||
@@ -661,43 +682,5 @@ | ||
case 'object': | ||
params.title = arguments[0].title || defaultParams.title; | ||
params.text = arguments[0].text || defaultParams.text; | ||
params.html = arguments[0].html || defaultParams.html; | ||
params.type = arguments[0].type || defaultParams.type; | ||
params.animation = arguments[0].animation !== undefined ? arguments[0].animation : defaultParams.animation; | ||
params.customClass = arguments[0].customClass || params.customClass; | ||
params.allowOutsideClick = arguments[0].allowOutsideClick !== undefined ? arguments[0].allowOutsideClick : defaultParams.allowOutsideClick; | ||
params.allowEscapeKey = arguments[0].allowEscapeKey !== undefined ? arguments[0].allowEscapeKey : defaultParams.allowEscapeKey; | ||
params.showConfirmButton = arguments[0].showConfirmButton !== undefined ? arguments[0].showConfirmButton : defaultParams.showConfirmButton; | ||
params.showCancelButton = arguments[0].showCancelButton !== undefined ? arguments[0].showCancelButton : defaultParams.showCancelButton; | ||
params.preConfirm = arguments[0].preConfirm || defaultParams.preConfirm; | ||
params.timer = parseInt(arguments[0].timer, 10) || defaultParams.timer; | ||
params.width = parseInt(arguments[0].width, 10) || defaultParams.width; | ||
params.padding = parseInt(arguments[0].padding, 10) || defaultParams.padding; | ||
params.background = arguments[0].background !== undefined ? arguments[0].background : defaultParams.background; | ||
extend(params, arguments[0]); | ||
params.extraParams = arguments[0].extraParams; | ||
params.confirmButtonText = arguments[0].confirmButtonText || defaultParams.confirmButtonText; | ||
params.confirmButtonColor = arguments[0].confirmButtonColor || defaultParams.confirmButtonColor; | ||
params.confirmButtonClass = arguments[0].confirmButtonClass || params.confirmButtonClass; | ||
params.cancelButtonText = arguments[0].cancelButtonText || defaultParams.cancelButtonText; | ||
params.cancelButtonColor = arguments[0].cancelButtonColor || defaultParams.cancelButtonColor; | ||
params.cancelButtonClass = arguments[0].cancelButtonClass || params.cancelButtonClass; | ||
params.buttonsStyling = arguments[0].buttonsStyling !== undefined ? arguments[0].buttonsStyling : defaultParams.buttonsStyling; | ||
params.reverseButtons = arguments[0].reverseButtons !== undefined ? arguments[0].reverseButtons : defaultParams.reverseButtons; | ||
params.showCloseButton = arguments[0].showCloseButton !== undefined ? arguments[0].showCloseButton : defaultParams.showCloseButton; | ||
params.imageUrl = arguments[0].imageUrl || defaultParams.imageUrl; | ||
params.imageWidth = arguments[0].imageWidth || defaultParams.imageWidth; | ||
params.imageHeight = arguments[0].imageHeight || defaultParams.imageHeight; | ||
params.imageClass = arguments[0].imageClass || defaultParams.imageClass; | ||
params.input = arguments[0].input || defaultParams.input; | ||
params.inputPlaceholder = arguments[0].inputPlaceholder || defaultParams.inputPlaceholder; | ||
params.inputValue = arguments[0].inputValue || defaultParams.inputValue; | ||
params.inputOptions = arguments[0].inputOptions || defaultParams.inputOptions; | ||
params.inputAutoTrim = arguments[0].inputAutoTrim !== undefined ? arguments[0].inputAutoTrim : defaultParams.inputAutoTrim; | ||
params.inputClass = arguments[0].inputClass || defaultParams.inputClass; | ||
params.inputAttributes = arguments[0].inputAttributes || defaultParams.inputAttributes; | ||
params.inputValidator = arguments[0].inputValidator || defaultParams.inputValidator; | ||
params.extraParams = arguments[0].extraParams; | ||
if (params.input === 'email' && params.inputValidator === null) { | ||
@@ -1094,3 +1077,3 @@ params.inputValidator = function(email) { | ||
// Reset icon animations | ||
var $successIcon = modal.querySelector('.' + swalClasses.icon + '.' + swalClasses.iconTypes.success); | ||
var $successIcon = modal.querySelector('.' + swalClasses.icon + '.' + iconTypes.success); | ||
removeClass($successIcon, 'animate'); | ||
@@ -1100,7 +1083,7 @@ removeClass($successIcon.querySelector('.tip'), 'animate-success-tip'); | ||
var $errorIcon = modal.querySelector('.' + swalClasses.icon + '.' + swalClasses.iconTypes.error); | ||
var $errorIcon = modal.querySelector('.' + swalClasses.icon + '.' + iconTypes.error); | ||
removeClass($errorIcon, 'animate-error-icon'); | ||
removeClass($errorIcon.querySelector('.x-mark'), 'animate-x-mark'); | ||
var $warningIcon = modal.querySelector('.' + swalClasses.icon + '.' + swalClasses.iconTypes.warning); | ||
var $warningIcon = modal.querySelector('.' + swalClasses.icon + '.' + iconTypes.warning); | ||
removeClass($warningIcon, 'pulse-warning'); | ||
@@ -1152,32 +1135,3 @@ | ||
} | ||
var sweetHTML = | ||
'<div class="' + swalClasses.overlay + '" tabIndex="-1"></div>' + | ||
'<div class="' + swalClasses.modal + '" style="display: none" tabIndex="-1">' + | ||
'<div class="' + swalClasses.icon + ' ' + swalClasses.iconTypes.error + '">' + | ||
'<span class="x-mark"><span class="line left"></span><span class="line right"></span></span>' + | ||
'</div>' + | ||
'<div class="' + swalClasses.icon + ' ' + swalClasses.iconTypes.question + '">?</div>' + | ||
'<div class="' + swalClasses.icon + ' ' + swalClasses.iconTypes.warning + '">!</div>' + | ||
'<div class="' + swalClasses.icon + ' ' + swalClasses.iconTypes.info + '">i</div>' + | ||
'<div class="' + swalClasses.icon + ' ' + swalClasses.iconTypes.success + '">' + | ||
'<span class="line tip"></span> <span class="line long"></span>' + | ||
'<div class="placeholder"></div> <div class="fix"></div>' + | ||
'</div>' + | ||
'<img class="' + swalClasses.image + '">' + | ||
'<h2></h2>' + | ||
'<div class="' + swalClasses.content + '"></div>' + | ||
'<input class="' + swalClasses.input + '">' + | ||
'<select class="' + swalClasses.select + '"></select>' + | ||
'<div class="' + swalClasses.radio + '"></div>' + | ||
'<label for="' + swalClasses.checkbox + '" class="' + swalClasses.checkbox + '">' + | ||
'<input type="checkbox" id="' + swalClasses.checkbox + '">' + | ||
'</label>' + | ||
'<textarea class="' + swalClasses.textarea + '"></textarea>' + | ||
'<div class="' + swalClasses.validationerror + '"></div>' + | ||
'<hr class="' + swalClasses.spacer + '">' + | ||
'<button class="' + swalClasses.confirm + '">OK</button>' + | ||
'<button class="' + swalClasses.cancel + '">Cancel</button>' + | ||
'<span class="' + swalClasses.close + '">×</span>' + | ||
'</div>'; | ||
var sweetWrap = document.createElement('div'); | ||
@@ -1235,3 +1189,3 @@ sweetWrap.className = swalClasses.container; | ||
sweetAlert.version = '3.1.2'; | ||
sweetAlert.version = '3.2.0'; | ||
@@ -1238,0 +1192,0 @@ window.sweetAlert = window.swal = sweetAlert; |
/*! | ||
* sweetalert2 v3.1.2 | ||
* sweetalert2 v3.2.0 | ||
* (c) 2016 Tristan Edwards <tristan.edwards@me.com> (http://tristanedwards.me) | ||
* Released under the MIT License. | ||
*/ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.Sweetalert2=t()}(this,function(){"use strict";function e(){if(void 0===arguments[0])return console.error("sweetAlert2 expects at least 1 attribute!"),!1;var e=T({},u);switch(typeof arguments[0]){case"string":e.title=arguments[0],e.text=arguments[1]||"",e.type=arguments[2]||"";break;case"object":e.title=arguments[0].title||u.title,e.text=arguments[0].text||u.text,e.html=arguments[0].html||u.html,e.type=arguments[0].type||u.type,e.animation=void 0!==arguments[0].animation?arguments[0].animation:u.animation,e.customClass=arguments[0].customClass||e.customClass,e.allowOutsideClick=void 0!==arguments[0].allowOutsideClick?arguments[0].allowOutsideClick:u.allowOutsideClick,e.allowEscapeKey=void 0!==arguments[0].allowEscapeKey?arguments[0].allowEscapeKey:u.allowEscapeKey,e.showConfirmButton=void 0!==arguments[0].showConfirmButton?arguments[0].showConfirmButton:u.showConfirmButton,e.showCancelButton=void 0!==arguments[0].showCancelButton?arguments[0].showCancelButton:u.showCancelButton,e.preConfirm=arguments[0].preConfirm||u.preConfirm,e.timer=parseInt(arguments[0].timer,10)||u.timer,e.width=parseInt(arguments[0].width,10)||u.width,e.padding=parseInt(arguments[0].padding,10)||u.padding,e.background=void 0!==arguments[0].background?arguments[0].background:u.background,e.confirmButtonText=arguments[0].confirmButtonText||u.confirmButtonText,e.confirmButtonColor=arguments[0].confirmButtonColor||u.confirmButtonColor,e.confirmButtonClass=arguments[0].confirmButtonClass||e.confirmButtonClass,e.cancelButtonText=arguments[0].cancelButtonText||u.cancelButtonText,e.cancelButtonColor=arguments[0].cancelButtonColor||u.cancelButtonColor,e.cancelButtonClass=arguments[0].cancelButtonClass||e.cancelButtonClass,e.buttonsStyling=void 0!==arguments[0].buttonsStyling?arguments[0].buttonsStyling:u.buttonsStyling,e.reverseButtons=void 0!==arguments[0].reverseButtons?arguments[0].reverseButtons:u.reverseButtons,e.showCloseButton=void 0!==arguments[0].showCloseButton?arguments[0].showCloseButton:u.showCloseButton,e.imageUrl=arguments[0].imageUrl||u.imageUrl,e.imageWidth=arguments[0].imageWidth||u.imageWidth,e.imageHeight=arguments[0].imageHeight||u.imageHeight,e.imageClass=arguments[0].imageClass||u.imageClass,e.input=arguments[0].input||u.input,e.inputPlaceholder=arguments[0].inputPlaceholder||u.inputPlaceholder,e.inputValue=arguments[0].inputValue||u.inputValue,e.inputOptions=arguments[0].inputOptions||u.inputOptions,e.inputAutoTrim=void 0!==arguments[0].inputAutoTrim?arguments[0].inputAutoTrim:u.inputAutoTrim,e.inputClass=arguments[0].inputClass||u.inputClass,e.inputAttributes=arguments[0].inputAttributes||u.inputAttributes,e.inputValidator=arguments[0].inputValidator||u.inputValidator,e.extraParams=arguments[0].extraParams,"email"===e.input&&null===e.inputValidator&&(e.inputValidator=function(e){return new Promise(function(t,n){var o=/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;o.test(e)?t():n("Invalid email address")})});break;default:return console.error('Unexpected type of argument! Expected "string" or "object", got '+typeof arguments[0]),!1}V(e),H(),O();var o=p();return new Promise(function(l){function s(e,t){for(var n=0;n<T.length;n++)if(e+=t,e===T.length?e=0:-1===e&&(e=T.length-1),T[e].offsetWidth||T[e].offsetHeight||T[e].getClientRects().length)return void T[e].focus()}function u(n){var o=n||window.event,i=o.keyCode||o.which;if(-1!==[9,13,32,27].indexOf(i)){for(var a=o.target||o.srcElement,r=-1,c=0;c<T.length;c++)if(a===T[c]){r=c;break}9===i?(o.shiftKey?s(r,-1):s(r,1),A(o)):13===i||32===i?-1===r&&q(E,o):27===i&&e.allowEscapeKey===!0&&(t.closeModal(),l(void 0))}}e.timer&&(o.timeout=setTimeout(function(){t.closeModal(),l(void 0)},e.timer));var d=function(){switch(e.input){case"select":return b(o,i.select);case"radio":return o.querySelector("."+i.radio+" input:checked")||o.querySelector("."+i.radio+" input:first-child");case"checkbox":return o.querySelector("#"+i.checkbox);case"textarea":return b(o,i.textarea);default:return b(o,i.input)}},p=function(){var t=d();switch(e.input){case"checkbox":return t.checked?1:0;case"radio":return t.checked?t.value:null;default:return e.inputAutoTrim?t.value.trim():t.value}};e.input&&setTimeout(function(){y(d())},0);var g,C=function(n){e.preConfirm?e.preConfirm(n,e.extraParams).then(function(e){l(e||n),t.closeModal()}):(l(n),t.closeModal())},x=function(n){var a=n||window.event,r=a.target||a.srcElement,c=f(r,i.confirm),s=f(r,i.cancel),u=f(o,"visible");switch(a.type){case"mouseover":case"mouseup":case"focus":e.buttonsStyling&&(c?r.style.backgroundColor=P(e.confirmButtonColor,-.1):s&&(r.style.backgroundColor=P(e.cancelButtonColor,-.1)));break;case"mouseout":case"blur":e.buttonsStyling&&(c?r.style.backgroundColor=e.confirmButtonColor:s&&(r.style.backgroundColor=e.cancelButtonColor));break;case"mousedown":e.buttonsStyling&&(c?r.style.backgroundColor=P(e.confirmButtonColor,-.2):s&&(r.style.backgroundColor=P(e.cancelButtonColor,-.2)));break;case"click":if(c&&u)if(e.input){var d=p();e.inputValidator?(t.disableInput(),e.inputValidator(d,e.extraParams).then(function(){t.enableInput(),C(d)},function(e){t.enableInput(),t.showValidationError(e)})):C(d)}else C(!0);else s&&u&&(t.closeModal(),l(!1))}},B=o.querySelectorAll("button");for(g=0;g<B.length;g++)B[g].onclick=x,B[g].onmouseover=x,B[g].onmouseout=x,B[g].onmousedown=x;a=document.onclick,document.onclick=function(n){var o=n||window.event,a=o.target||o.srcElement;(f(a,i.close)||a===m()&&e.allowOutsideClick)&&(t.closeModal(),l(void 0))};var E=o.querySelector("button."+i.confirm),S=o.querySelector("button."+i.cancel),T=[E,S].concat(Array.prototype.slice.call(o.querySelectorAll("button:not([class^="+n+"]), input:not([type=hidden]), textarea, select")));for(g=0;g<T.length;g++)T[g].onfocus=x,T[g].onblur=x;e.reverseButtons&&E.parentNode.insertBefore(S,E),s(-1,1),r=window.onkeydown,window.onkeydown=u,e.buttonsStyling&&(E.style.borderLeftColor=e.confirmButtonColor,E.style.borderRightColor=e.confirmButtonColor),t.enableLoading=function(){v(E,"loading"),v(o,"loading"),S.disabled=!0},t.disableLoading=function(){h(E,"loading"),h(o,"loading"),S.disabled=!1},t.enableButtons=function(){E.disabled=!1,S.disabled=!1},t.disableButtons=function(){E.disabled=!0,S.disabled=!0},t.enableInput=function(){var e=d();if("radio"===e.type)for(var t=e.parentNode.parentNode,n=t.querySelectorAll("input"),o=0;o<n.length;o++)n[o].disabled=!1;else e.disabled=!1},t.disableInput=function(){var e=d();if("radio"===e.type)for(var t=e.parentNode.parentNode,n=t.querySelectorAll("input"),o=0;o<n.length;o++)n[o].disabled=!0;else e.disabled=!0},t.showValidationError=function(e){var t=o.querySelector("."+i.validationerror);t.innerHTML=e,w(t);var n=d();y(n),v(n,"error")},t.resetValidationError=function(){var e=o.querySelector("."+i.validationerror);k(e);var t=d();h(t,"error")},t.enableButtons(),t.disableLoading(),t.resetValidationError(),window.onfocus=function(){window.setTimeout(function(){void 0!==c&&(c.focus(),c=void 0)},0)}})}function t(){var n=arguments,o=p();return null===o&&(t.init(),o=p()),f(o,"visible")&&L(),e.apply(this,n)}var n="swal2-",o=function(e){var t={};for(var o in e)t[e[o]]=n+e[o];return t},i=o(["container","modal","overlay","close","content","spacer","confirm","cancel","icon","image","input","select","radio","checkbox","textarea","validationerror"]);i.iconTypes=o(["success","warning","info","question","error"]);var a,r,l,c,s=n+"mediaquery",u={title:"",text:"",html:"",type:null,animation:!0,allowOutsideClick:!0,allowEscapeKey:!0,showConfirmButton:!0,showCancelButton:!1,preConfirm:null,confirmButtonText:"OK",confirmButtonColor:"#3085d6",confirmButtonClass:null,cancelButtonText:"Cancel",cancelButtonColor:"#aaa",cancelButtonClass:null,buttonsStyling:!0,reverseButtons:!1,showCloseButton:!1,imageUrl:null,imageWidth:null,imageHeight:null,imageClass:null,timer:null,width:500,padding:20,background:"#fff",input:null,inputPlaceholder:"",inputValue:"",inputOptions:{},inputAutoTrim:!0,inputClass:null,inputAttributes:{},inputValidator:null},d=function(e){return document.querySelector("."+e)},p=function(){return d(i.modal)},m=function(){return d(i.overlay)},f=function(e,t){return new RegExp(" "+t+" ").test(" "+e.className+" ")},y=function(e){e.focus();var t=e.value;e.value="",e.value=t},v=function(e,t){t&&!f(e,t)&&(e.className+=" "+t)},h=function(e,t){var n=" "+e.className.replace(/[\t\r\n]/g," ")+" ";if(f(e,t)){for(;n.indexOf(" "+t+" ")>=0;)n=n.replace(" "+t+" "," ");e.className=n.replace(/^\s+|\s+$/g,"")}},b=function(e,t){for(var n=0;n<e.childNodes.length;n++)if(e.childNodes[n].classList.contains(t))return e.childNodes[n]},g=function(e){e.style.opacity="",e.style.display="block"},w=function(e){if(e&&!e.length)return g(e);for(var t=0;t<e.length;++t)g(e[t])},C=function(e){e.style.opacity="",e.style.display="none"},k=function(e){if(e&&!e.length)return C(e);for(var t=0;t<e.length;++t)C(e[t])},x=function(e,t){e.style.removeProperty?e.style.removeProperty(t):e.style.removeAttribute(t)},B=function(e){e.style.left="-9999px",e.style.display="block";var t=e.clientHeight,n=parseInt(getComputedStyle(e).getPropertyValue("padding-top"),10);return e.style.left="",e.style.display="none","-"+parseInt(t/2+n,10)+"px"},E=function(e,t){if(+e.style.opacity<1){t=t||16,e.style.opacity=0,e.style.display="block";var n=+new Date,o=function(){var i=+e.style.opacity+(new Date-n)/100;e.style.opacity=i>1?1:i,n=+new Date,+e.style.opacity<1&&setTimeout(o,t)};o()}},S=function(e,t){if(+e.style.opacity>0){t=t||16;var n=e.style.opacity,o=+new Date,i=function(){var a=new Date-o,r=+e.style.opacity-a/(100*n);e.style.opacity=r,o=+new Date,+e.style.opacity>0?setTimeout(i,t):C(e)};i()}},T=function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n]);return e},q=function(e){if("function"==typeof MouseEvent){var t=new MouseEvent("click",{view:window,bubbles:!1,cancelable:!0});e.dispatchEvent(t)}else if(document.createEvent){var n=document.createEvent("MouseEvents");n.initEvent("click",!1,!1),e.dispatchEvent(n)}else document.createEventObject?e.fireEvent("onclick"):"function"==typeof e.onclick&&e.onclick()},A=function(e){"function"==typeof e.stopPropagation?(e.stopPropagation(),e.preventDefault()):window.event&&window.event.hasOwnProperty("cancelBubble")&&(window.event.cancelBubble=!0)},M=function(){var e=document.createElement("div"),t={WebkitAnimation:"webkitAnimationEnd",MozAnimation:"animationend",OAnimation:"oAnimationEnd oanimationend",msAnimation:"MSAnimationEnd",animation:"animationend"};for(var n in t)if(t.hasOwnProperty(n)&&void 0!==e.style[n])return t[n];return!1}(),L=function(){var e=p();window.onkeydown=r,document.onclick=a,l&&l.focus(),c=void 0,clearTimeout(e.timeout);var t=document.getElementsByTagName("head")[0],n=document.getElementById(s);n&&t.removeChild(n)},P=function(e,t){e=String(e).replace(/[^0-9a-f]/gi,""),e.length<6&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),t=t||0;for(var n="#",o=0;3>o;o++){var i=parseInt(e.substr(2*o,2),16);i=Math.round(Math.min(Math.max(0,i+i*t),255)).toString(16),n+=("00"+i).substr(i.length)}return n},V=function(e){var t,n=p();n.style.width=e.width+"px",n.style.padding=e.padding+"px",n.style.marginLeft=-e.width/2+"px",n.style.background=e.background;var o=document.getElementsByTagName("head")[0],a=document.createElement("style");a.type="text/css",a.id=s;var r=5,l=e.width+parseInt(e.width*(r/100)*2,10);a.innerHTML="@media screen and (max-width: "+l+"px) {."+i.modal+" {width: auto !important;left: "+r+"% !important;right: "+r+"% !important;margin-left: 0 !important;}}",o.appendChild(a);var c=n.querySelector("h2"),u=n.querySelector("."+i.content),d=n.querySelector("button."+i.confirm),m=n.querySelector("button."+i.cancel),f=n.querySelector("."+i.spacer),y=n.querySelector("."+i.close);if(c.innerHTML=e.title.split("\n").join("<br>"),e.text||e.html){if("object"==typeof e.html)if(u.innerHTML="",0 in e.html)for(t=0;t in e.html;t++)u.appendChild(e.html[t]);else u.appendChild(e.html);else u.innerHTML=e.html||e.text.split("\n").join("<br>");w(u)}else k(u);if(e.showCloseButton?w(y):k(y),n.className=i.modal,e.customClass&&v(n,e.customClass),k(n.querySelectorAll("."+i.icon)),e.type){var B=!1;for(var E in i.iconTypes)if(e.type===E){B=!0;break}if(!B)return console.error("Unknown alert type: "+e.type),!1;var S=n.querySelector("."+i.icon+"."+i.iconTypes[e.type]);switch(w(S),e.type){case"success":v(S,"animate"),v(S.querySelector(".tip"),"animate-success-tip"),v(S.querySelector(".long"),"animate-success-long");break;case"error":v(S,"animate-error-icon"),v(S.querySelector(".x-mark"),"animate-x-mark");break;case"warning":v(S,"pulse-warning")}}var T=n.querySelector("."+i.image);e.imageUrl?(T.setAttribute("src",e.imageUrl),w(T),e.imageWidth&&T.setAttribute("width",e.imageWidth),e.imageHeight&&T.setAttribute("height",e.imageHeight),e.imageClass&&v(T,e.imageClass)):k(T);var q,A=["input","select","radio","checkbox","textarea"];for(t=0;t<A.length;t++){var M=i[A[t]];for(q=b(n,M);q.attributes.length>0;)q.removeAttribute(q.attributes[0].name);for(var L in e.inputAttributes)q.setAttribute(L,e.inputAttributes[L]);q.className=M,e.inputClass&&v(q,e.inputClass),C(q)}switch(e.input){case"text":case"email":case"password":q=b(n,i.input),q.value=e.inputValue,q.placeholder=e.inputPlaceholder,q.type=e.input,g(q);break;case"select":var P=b(n,i.select);if(P.innerHTML="",e.inputPlaceholder){var V=document.createElement("option");V.innerHTML=e.inputPlaceholder,V.value="",V.disabled=!0,V.selected=!0,P.appendChild(V)}for(var O in e.inputOptions){var H=document.createElement("option");H.value=O,H.innerHTML=e.inputOptions[O],e.inputValue===O&&(H.selected=!0),P.appendChild(H)}g(P);break;case"radio":var N=b(n,i.radio);N.innerHTML="";for(var I in e.inputOptions){var D=1,j=document.createElement("input"),K=document.createElement("label"),U=document.createElement("span");j.type="radio",j.name=i.radio,j.value=I,j.id=i.radio+"-"+D++,e.inputValue===I&&(j.checked=!0),U.innerHTML=e.inputOptions[I],K.appendChild(j),K.appendChild(U),K["for"]=j.id,N.appendChild(K)}g(N);break;case"checkbox":var W=b(n,i.checkbox),z=n.querySelector("#"+i.checkbox);z.value=1,z.checked=Boolean(e.inputValue);var R=W.getElementsByTagName("span");R.length&&W.removeChild(R[0]),R=document.createElement("span"),R.innerHTML=e.inputPlaceholder,W.appendChild(R),g(W);break;case"textarea":var Z=b(n,i.textarea);Z.value=e.inputValue,Z.placeholder=e.inputPlaceholder,g(Z);break;case null:break;default:console.error('Unexpected type of input! Expected "text" or "email" or "password", "select", "checkbox" or "textarea", got '+typeof arguments[0])}e.showCancelButton?m.style.display="inline-block":k(m),e.showConfirmButton?x(d,"display"):k(d),e.showConfirmButton||e.showCancelButton?w(f):k(f),d.innerHTML=e.confirmButtonText,m.innerHTML=e.cancelButtonText,e.buttonsStyling&&(d.style.backgroundColor=e.confirmButtonColor,m.style.backgroundColor=e.cancelButtonColor),d.className=i.confirm,v(d,e.confirmButtonClass),m.className=i.cancel,v(m,e.cancelButtonClass),e.buttonsStyling?(v(d,"styled"),v(m,"styled")):(h(d,"styled"),h(m,"styled"),d.style.backgroundColor=d.style.borderLeftColor=d.style.borderRightColor="",m.style.backgroundColor=m.style.borderLeftColor=m.style.borderRightColor=""),e.animation===!0?h(n,"no-animation"):v(n,"no-animation")},O=function(){var e=p();E(m(),10),w(e),v(e,"show-swal2"),h(e,"hide-swal2"),l=document.activeElement,v(e,"visible")},H=function(){var e=p();e.style.marginTop=B(p())};return t.close=t.closeModal=function(){var e=p();h(e,"show-swal2"),v(e,"hide-swal2"),h(e,"visible");var t=e.querySelector("."+i.icon+"."+i.iconTypes.success);h(t,"animate"),h(t.querySelector(".tip"),"animate-success-tip"),h(t.querySelector(".long"),"animate-success-long");var n=e.querySelector("."+i.icon+"."+i.iconTypes.error);h(n,"animate-error-icon"),h(n.querySelector(".x-mark"),"animate-x-mark");var o=e.querySelector("."+i.icon+"."+i.iconTypes.warning);h(o,"pulse-warning"),L(),M&&!f(e,"no-animation")?e.addEventListener(M,function a(){e.removeEventListener(M,a),f(e,"hide-swal2")&&(C(e),S(m(),0))}):(C(e),S(m(),0))},t.clickConfirm=function(){var e=p(),t=e.querySelector("button."+i.confirm);t.click()},t.clickCancel=function(){var e=p(),t=e.querySelector("button."+i.cancel);t.click()},t.init=function(){if("undefined"==typeof document)return void console.log("SweetAlert2 requires document to initialize");if(!document.getElementsByClassName(i.container).length){var e='<div class="'+i.overlay+'" tabIndex="-1"></div><div class="'+i.modal+'" style="display: none" tabIndex="-1"><div class="'+i.icon+" "+i.iconTypes.error+'"><span class="x-mark"><span class="line left"></span><span class="line right"></span></span></div><div class="'+i.icon+" "+i.iconTypes.question+'">?</div><div class="'+i.icon+" "+i.iconTypes.warning+'">!</div><div class="'+i.icon+" "+i.iconTypes.info+'">i</div><div class="'+i.icon+" "+i.iconTypes.success+'"><span class="line tip"></span> <span class="line long"></span><div class="placeholder"></div> <div class="fix"></div></div><img class="'+i.image+'"><h2></h2><div class="'+i.content+'"></div><input class="'+i.input+'"><select class="'+i.select+'"></select><div class="'+i.radio+'"></div><label for="'+i.checkbox+'" class="'+i.checkbox+'"><input type="checkbox" id="'+i.checkbox+'"></label><textarea class="'+i.textarea+'"></textarea><div class="'+i.validationerror+'"></div><hr class="'+i.spacer+'"><button class="'+i.confirm+'">OK</button><button class="'+i.cancel+'">Cancel</button><span class="'+i.close+'">×</span></div>',n=document.createElement("div");n.className=i.container,n.innerHTML=e,document.body.appendChild(n);var o=p(),a=b(o,i.input),r=b(o,i.select),l=o.querySelector("#"+i.checkbox),c=b(o,i.textarea);a.oninput=function(){t.resetValidationError()},a.onkeyup=function(e){e.stopPropagation(),13===e.keyCode&&t.clickConfirm()},r.onchange=function(){t.resetValidationError()},l.onchange=function(){t.resetValidationError()},c.onchange=function(){t.resetValidationError()}}},t.setDefaults=function(e){if(!e)throw new Error("userParams is required");if("object"!=typeof e)throw new Error("userParams has to be a object");T(u,e)},t.version="3.1.2",window.sweetAlert=window.swal=t,function(){"complete"===document.readyState||"interactive"===document.readyState&&document.body?t.init():document.addEventListener("DOMContentLoaded",function e(){document.removeEventListener("DOMContentLoaded",e,!1),t.init()},!1)}(),t}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.Sweetalert2=t()}(this,function(){"use strict";function e(){if(void 0===arguments[0])return console.error("sweetAlert2 expects at least 1 attribute!"),!1;var e=v({},f);switch(typeof arguments[0]){case"string":e.title=arguments[0],e.text=arguments[1]||"",e.type=arguments[2]||"";break;case"object":v(e,arguments[0]),e.extraParams=arguments[0].extraParams,"email"===e.input&&null===e.inputValidator&&(e.inputValidator=function(e){return new Promise(function(t,n){var o=/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;o.test(e)?t():n("Invalid email address")})});break;default:return console.error('Unexpected type of argument! Expected "string" or "object", got '+typeof arguments[0]),!1}I(e),j(),D();var n=w();return new Promise(function(o){function r(e,t){for(var n=0;n<w.length;n++)if(e+=t,e===w.length?e=0:-1===e&&(e=w.length-1),w[e].offsetWidth||w[e].offsetHeight||w[e].getClientRects().length)return void w[e].focus()}function a(n){var a=n||window.event,i=a.keyCode||a.which;if(-1!==[9,13,32,27].indexOf(i)){for(var l=a.target||a.srcElement,c=-1,s=0;s<w.length;s++)if(l===w[s]){c=s;break}9===i?(a.shiftKey?r(c,-1):r(c,1),stopEventPropagation(a)):13===i||32===i?-1===c&&fireClick(b,a):27===i&&e.allowEscapeKey===!0&&(t.closeModal(),o(void 0))}}e.timer&&(n.timeout=setTimeout(function(){t.closeModal(),o(void 0)},e.timer));var c=function(){switch(e.input){case"select":return B(n,p.select);case"radio":return n.querySelector("."+p.radio+" input:checked")||n.querySelector("."+p.radio+" input:first-child");case"checkbox":return n.querySelector("#"+p.checkbox);case"textarea":return B(n,p.textarea);default:return B(n,p.input)}},d=function(){var t=c();switch(e.input){case"checkbox":return t.checked?1:0;case"radio":return t.checked?t.value:null;default:return e.inputAutoTrim?t.value.trim():t.value}};e.input&&setTimeout(function(){x(c())},0);var m,f=function(n){e.preConfirm?e.preConfirm(n,e.extraParams).then(function(e){o(e||n),t.closeModal()}):(o(n),t.closeModal())},y=function(r){var a=r||window.event,i=a.target||a.srcElement,l=C(i,p.confirm),c=C(i,p.cancel),s=C(n,"visible");switch(a.type){case"mouseover":case"mouseup":case"focus":e.buttonsStyling&&(l?i.style.backgroundColor=h(e.confirmButtonColor,-.1):c&&(i.style.backgroundColor=h(e.cancelButtonColor,-.1)));break;case"mouseout":case"blur":e.buttonsStyling&&(l?i.style.backgroundColor=e.confirmButtonColor:c&&(i.style.backgroundColor=e.cancelButtonColor));break;case"mousedown":e.buttonsStyling&&(l?i.style.backgroundColor=h(e.confirmButtonColor,-.2):c&&(i.style.backgroundColor=h(e.cancelButtonColor,-.2)));break;case"click":if(l&&s)if(e.input){var u=d();e.inputValidator?(t.disableInput(),e.inputValidator(u,e.extraParams).then(function(){t.enableInput(),f(u)},function(e){t.enableInput(),t.showValidationError(e)})):f(u)}else f(!0);else c&&s&&(t.closeModal(),o(!1))}},v=n.querySelectorAll("button");for(m=0;m<v.length;m++)v[m].onclick=y,v[m].onmouseover=y,v[m].onmouseout=y,v[m].onmousedown=y;i=document.onclick,document.onclick=function(n){var r=n||window.event,a=r.target||r.srcElement;(C(a,p.close)||a===k()&&e.allowOutsideClick)&&(t.closeModal(),o(void 0))};var b=n.querySelector("button."+p.confirm),g=n.querySelector("button."+p.cancel),w=[b,g].concat(Array.prototype.slice.call(n.querySelectorAll("button:not([class^="+u+"]), input:not([type=hidden]), textarea, select")));for(m=0;m<w.length;m++)w[m].onfocus=y,w[m].onblur=y;e.reverseButtons&&b.parentNode.insertBefore(g,b),r(-1,1),l=window.onkeydown,window.onkeydown=a,e.buttonsStyling&&(b.style.borderLeftColor=e.confirmButtonColor,b.style.borderRightColor=e.confirmButtonColor),t.enableLoading=function(){S(b,"loading"),S(n,"loading"),g.disabled=!0},t.disableLoading=function(){E(b,"loading"),E(n,"loading"),g.disabled=!1},t.enableButtons=function(){b.disabled=!1,g.disabled=!1},t.disableButtons=function(){b.disabled=!0,g.disabled=!0},t.enableInput=function(){var e=c();if("radio"===e.type)for(var t=e.parentNode.parentNode,n=t.querySelectorAll("input"),o=0;o<n.length;o++)n[o].disabled=!1;else e.disabled=!1},t.disableInput=function(){var e=c();if("radio"===e.type)for(var t=e.parentNode.parentNode,n=t.querySelectorAll("input"),o=0;o<n.length;o++)n[o].disabled=!0;else e.disabled=!0},t.showValidationError=function(e){var t=n.querySelector("."+p.validationerror);t.innerHTML=e,A(t);var o=c();x(o),S(o,"error")},t.resetValidationError=function(){var e=n.querySelector("."+p.validationerror);L(e);var t=c();E(t,"error")},t.enableButtons(),t.disableLoading(),t.resetValidationError(),window.onfocus=function(){window.setTimeout(function(){void 0!==s&&(s.focus(),s=void 0)},0)}})}function t(){var n=arguments,o=w();return null===o&&(t.init(),o=w()),C(o,"visible")&&O(),e.apply(this,n)}var n,o,r,a,i,l,c,s,u="swal2-",d=function(e){var t={};for(var n in e)t[e[n]]=u+e[n];return t},p=d(["container","modal","overlay","close","content","spacer","confirm","cancel","icon","image","input","select","radio","checkbox","textarea","validationerror"]),m=d(["success","warning","info","question","error"]),f={title:"",text:"",html:"",type:null,animation:!0,allowOutsideClick:!0,allowEscapeKey:!0,showConfirmButton:!0,showCancelButton:!1,preConfirm:null,confirmButtonText:"OK",confirmButtonColor:"#3085d6",confirmButtonClass:null,cancelButtonText:"Cancel",cancelButtonColor:"#aaa",cancelButtonClass:null,buttonsStyling:!0,reverseButtons:!1,showCloseButton:!1,imageUrl:null,imageWidth:null,imageHeight:null,imageClass:null,timer:null,width:500,padding:20,background:"#fff",input:null,inputPlaceholder:"",inputValue:"",inputOptions:{},inputAutoTrim:!0,inputClass:null,inputAttributes:{},inputValidator:null},y='<div class="'+p.overlay+'" tabIndex="-1"></div><div class="'+p.modal+'" style="display: none" tabIndex="-1"><div class="'+p.icon+" "+m.error+'"><span class="x-mark"><span class="line left"></span><span class="line right"></span></span></div><div class="'+p.icon+" "+m.question+'">?</div><div class="'+p.icon+" "+m.warning+'">!</div><div class="'+p.icon+" "+m.info+'">i</div><div class="'+p.icon+" "+m.success+'"><span class="line tip"></span> <span class="line long"></span><div class="placeholder"></div> <div class="fix"></div></div><img class="'+p.image+'"><h2></h2><div class="'+p.content+'"></div><input class="'+p.input+'"><select class="'+p.select+'"></select><div class="'+p.radio+'"></div><label for="'+p.checkbox+'" class="'+p.checkbox+'"><input type="checkbox" id="'+p.checkbox+'"></label><textarea class="'+p.textarea+'"></textarea><div class="'+p.validationerror+'"></div><hr class="'+p.spacer+'"><button class="'+p.confirm+'">OK</button><button class="'+p.cancel+'">Cancel</button><span class="'+p.close+'">×</span></div>',v=function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n]);return e},h=function(e,t){e=String(e).replace(/[^0-9a-f]/gi,""),e.length<6&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),t=t||0;for(var n="#",o=0;3>o;o++){var r=parseInt(e.substr(2*o,2),16);r=Math.round(Math.min(Math.max(0,r+r*t),255)).toString(16),n+=("00"+r).substr(r.length)}return n},b=u+"mediaquery",g=function(e){return document.querySelector("."+e)},w=function(){return g(p.modal)},k=function(){return g(p.overlay)},C=function(e,t){return new RegExp(" "+t+" ").test(" "+e.className+" ")},x=function(e){e.focus();var t=e.value;e.value="",e.value=t},S=function(e,t){t&&!C(e,t)&&(e.className+=" "+t)},E=function(e,t){var n=" "+e.className.replace(/[\t\r\n]/g," ")+" ";if(C(e,t)){for(;n.indexOf(" "+t+" ")>=0;)n=n.replace(" "+t+" "," ");e.className=n.replace(/^\s+|\s+$/g,"")}},B=function(e,t){for(var n=0;n<e.childNodes.length;n++)if(e.childNodes[n].classList.contains(t))return e.childNodes[n]},q=function(e){e.style.opacity="",e.style.display="block"},A=function(e){if(e&&!e.length)return q(e);for(var t=0;t<e.length;++t)q(e[t])},T=function(e){e.style.opacity="",e.style.display="none"},L=function(e){if(e&&!e.length)return T(e);for(var t=0;t<e.length;++t)T(e[t])},M=function(e,t){e.style.removeProperty?e.style.removeProperty(t):e.style.removeAttribute(t)},N=function(e){e.style.left="-9999px",e.style.display="block";var t=e.clientHeight,n=parseInt(getComputedStyle(e).getPropertyValue("padding-top"),10);return e.style.left="",e.style.display="none","-"+parseInt(t/2+n,10)+"px"},P=function(e,t){if(+e.style.opacity<1){t=t||16,e.style.opacity=0,e.style.display="block";var n=+new Date,o=function(){var r=+e.style.opacity+(new Date-n)/100;e.style.opacity=r>1?1:r,n=+new Date,+e.style.opacity<1&&setTimeout(o,t)};o()}},V=function(e,t){if(+e.style.opacity>0){t=t||16;var n=e.style.opacity,o=+new Date,r=function(){var a=new Date-o,i=+e.style.opacity-a/(100*n);e.style.opacity=i,o=+new Date,+e.style.opacity>0?setTimeout(r,t):T(e)};r()}},H=function(){var e=document.createElement("div"),t={WebkitAnimation:"webkitAnimationEnd",MozAnimation:"animationend",OAnimation:"oAnimationEnd oanimationend",msAnimation:"MSAnimationEnd",animation:"animationend"};for(var n in t)if(t.hasOwnProperty(n)&&void 0!==e.style[n])return t[n];return!1}(),O=function(){var e=w();window.onkeydown=o,document.onclick=n,r&&r.focus(),a=void 0,clearTimeout(e.timeout);var t=document.getElementsByTagName("head")[0],i=document.getElementById(b);i&&t.removeChild(i)},I=function(e){var t,n=w();n.style.width=e.width+"px",n.style.padding=e.padding+"px",n.style.marginLeft=-e.width/2+"px",n.style.background=e.background;var o=document.getElementsByTagName("head")[0],r=document.createElement("style");r.type="text/css",r.id=b;var a=5,i=e.width+parseInt(e.width*(a/100)*2,10);r.innerHTML="@media screen and (max-width: "+i+"px) {."+p.modal+" {width: auto !important;left: "+a+"% !important;right: "+a+"% !important;margin-left: 0 !important;}}",o.appendChild(r);var l=n.querySelector("h2"),c=n.querySelector("."+p.content),s=n.querySelector("button."+p.confirm),u=n.querySelector("button."+p.cancel),d=n.querySelector("."+p.spacer),f=n.querySelector("."+p.close);if(l.innerHTML=e.title.split("\n").join("<br>"),e.text||e.html){if("object"==typeof e.html)if(c.innerHTML="",0 in e.html)for(t=0;t in e.html;t++)c.appendChild(e.html[t]);else c.appendChild(e.html);else c.innerHTML=e.html||e.text.split("\n").join("<br>");A(c)}else L(c);if(e.showCloseButton?A(f):L(f),n.className=p.modal,e.customClass&&S(n,e.customClass),L(n.querySelectorAll("."+p.icon)),e.type){var y=!1;for(var v in m)if(e.type===v){y=!0;break}if(!y)return console.error("Unknown alert type: "+e.type),!1;var h=n.querySelector("."+p.icon+"."+m[e.type]);switch(A(h),e.type){case"success":S(h,"animate"),S(h.querySelector(".tip"),"animate-success-tip"),S(h.querySelector(".long"),"animate-success-long");break;case"error":S(h,"animate-error-icon"),S(h.querySelector(".x-mark"),"animate-x-mark");break;case"warning":S(h,"pulse-warning")}}var g=n.querySelector("."+p.image);e.imageUrl?(g.setAttribute("src",e.imageUrl),A(g),e.imageWidth&&g.setAttribute("width",e.imageWidth),e.imageHeight&&g.setAttribute("height",e.imageHeight),e.imageClass&&S(g,e.imageClass)):L(g);var k,C=["input","select","radio","checkbox","textarea"];for(t=0;t<C.length;t++){var x=p[C[t]];for(k=B(n,x);k.attributes.length>0;)k.removeAttribute(k.attributes[0].name);for(var N in e.inputAttributes)k.setAttribute(N,e.inputAttributes[N]);k.className=x,e.inputClass&&S(k,e.inputClass),T(k)}switch(e.input){case"text":case"email":case"password":k=B(n,p.input),k.value=e.inputValue,k.placeholder=e.inputPlaceholder,k.type=e.input,q(k);break;case"select":var P=B(n,p.select);if(P.innerHTML="",e.inputPlaceholder){var V=document.createElement("option");V.innerHTML=e.inputPlaceholder,V.value="",V.disabled=!0,V.selected=!0,P.appendChild(V)}for(var H in e.inputOptions){var O=document.createElement("option");O.value=H,O.innerHTML=e.inputOptions[H],e.inputValue===H&&(O.selected=!0),P.appendChild(O)}q(P);break;case"radio":var I=B(n,p.radio);I.innerHTML="";for(var D in e.inputOptions){var j=1,U=document.createElement("input"),z=document.createElement("label"),K=document.createElement("span");U.type="radio",U.name=p.radio,U.value=D,U.id=p.radio+"-"+j++,e.inputValue===D&&(U.checked=!0),K.innerHTML=e.inputOptions[D],z.appendChild(U),z.appendChild(K),z["for"]=U.id,I.appendChild(z)}q(I);break;case"checkbox":var R=B(n,p.checkbox),W=n.querySelector("#"+p.checkbox);W.value=1,W.checked=Boolean(e.inputValue);var Z=R.getElementsByTagName("span");Z.length&&R.removeChild(Z[0]),Z=document.createElement("span"),Z.innerHTML=e.inputPlaceholder,R.appendChild(Z),q(R);break;case"textarea":var $=B(n,p.textarea);$.value=e.inputValue,$.placeholder=e.inputPlaceholder,q($);break;case null:break;default:console.error('Unexpected type of input! Expected "text" or "email" or "password", "select", "checkbox" or "textarea", got '+typeof arguments[0])}e.showCancelButton?u.style.display="inline-block":L(u),e.showConfirmButton?M(s,"display"):L(s),e.showConfirmButton||e.showCancelButton?A(d):L(d),s.innerHTML=e.confirmButtonText,u.innerHTML=e.cancelButtonText,e.buttonsStyling&&(s.style.backgroundColor=e.confirmButtonColor,u.style.backgroundColor=e.cancelButtonColor),s.className=p.confirm,S(s,e.confirmButtonClass),u.className=p.cancel,S(u,e.cancelButtonClass),e.buttonsStyling?(S(s,"styled"),S(u,"styled")):(E(s,"styled"),E(u,"styled"),s.style.backgroundColor=s.style.borderLeftColor=s.style.borderRightColor="",u.style.backgroundColor=u.style.borderLeftColor=u.style.borderRightColor=""),e.animation===!0?E(n,"no-animation"):S(n,"no-animation")},D=function(){var e=w();P(k(),10),A(e),S(e,"show-swal2"),E(e,"hide-swal2"),c=document.activeElement,S(e,"visible")},j=function(){var e=w();e.style.marginTop=N(w())};return t.close=t.closeModal=function(){var e=w();E(e,"show-swal2"),S(e,"hide-swal2"),E(e,"visible");var t=e.querySelector("."+p.icon+"."+m.success);E(t,"animate"),E(t.querySelector(".tip"),"animate-success-tip"),E(t.querySelector(".long"),"animate-success-long");var n=e.querySelector("."+p.icon+"."+m.error);E(n,"animate-error-icon"),E(n.querySelector(".x-mark"),"animate-x-mark");var o=e.querySelector("."+p.icon+"."+m.warning);E(o,"pulse-warning"),O(),H&&!C(e,"no-animation")?e.addEventListener(H,function r(){e.removeEventListener(H,r),C(e,"hide-swal2")&&(T(e),V(k(),0))}):(T(e),V(k(),0))},t.clickConfirm=function(){var e=w(),t=e.querySelector("button."+p.confirm);t.click()},t.clickCancel=function(){var e=w(),t=e.querySelector("button."+p.cancel);t.click()},t.init=function(){if("undefined"==typeof document)return void console.log("SweetAlert2 requires document to initialize");if(!document.getElementsByClassName(p.container).length){var e=document.createElement("div");e.className=p.container,e.innerHTML=y,document.body.appendChild(e);var n=w(),o=B(n,p.input),r=B(n,p.select),a=n.querySelector("#"+p.checkbox),i=B(n,p.textarea);o.oninput=function(){t.resetValidationError()},o.onkeyup=function(e){e.stopPropagation(),13===e.keyCode&&t.clickConfirm()},r.onchange=function(){t.resetValidationError()},a.onchange=function(){t.resetValidationError()},i.onchange=function(){t.resetValidationError()}}},t.setDefaults=function(e){if(!e)throw new Error("userParams is required");if("object"!=typeof e)throw new Error("userParams has to be a object");v(f,e)},t.version="3.2.0",window.sweetAlert=window.swal=t,function(){"complete"===document.readyState||"interactive"===document.readyState&&document.body?t.init():document.addEventListener("DOMContentLoaded",function e(){document.removeEventListener("DOMContentLoaded",e,!1),t.init()},!1)}(),t}); |
{ | ||
"name": "sweetalert2", | ||
"version": "3.1.2", | ||
"version": "3.2.0", | ||
"repository": "https://github.com/limonte/sweetalert2.git", | ||
@@ -5,0 +5,0 @@ "homepage": "https://limonte.github.io/sweetalert2/", |
@@ -16,5 +16,3 @@ SweetAlert2 [![Build Status](https://travis-ci.org/limonte/sweetalert2.svg?branch=master)](https://travis-ci.org/limonte/sweetalert2) | ||
![SweetAlert2 example]() | ||
Usage | ||
@@ -21,0 +19,0 @@ ----- |
'use strict'; | ||
var swalPrefix = 'swal2-'; | ||
import { defaultParams, sweetHTML } from './utils/default.js'; | ||
import { swalPrefix, swalClasses, iconTypes } from './utils/classes.js'; | ||
import { extend, colorLuminance } from './utils/utils.js'; | ||
import * as dom from './utils/dom.js'; | ||
var prefix = function(items) { | ||
var result = {}; | ||
for (var i in items) { | ||
result[items[i]] = swalPrefix + items[i]; | ||
} | ||
return result; | ||
}; | ||
var swalClasses = prefix([ | ||
'container', 'modal', 'overlay', 'close', 'content', 'spacer', 'confirm', | ||
'cancel', 'icon', 'image', 'input', 'select', 'radio', 'checkbox', 'textarea', | ||
'validationerror' | ||
]); | ||
swalClasses.iconTypes = prefix(['success', 'warning', 'info', 'question', 'error']); | ||
var mediaqueryId = swalPrefix + 'mediaquery'; | ||
var defaultParams = { | ||
title: '', | ||
text: '', | ||
html: '', | ||
type: null, | ||
animation: true, | ||
allowOutsideClick: true, | ||
allowEscapeKey: true, | ||
showConfirmButton: true, | ||
showCancelButton: false, | ||
preConfirm: null, | ||
confirmButtonText: 'OK', | ||
confirmButtonColor: '#3085d6', | ||
confirmButtonClass: null, | ||
cancelButtonText: 'Cancel', | ||
cancelButtonColor: '#aaa', | ||
cancelButtonClass: null, | ||
buttonsStyling: true, | ||
reverseButtons: false, | ||
showCloseButton: false, | ||
imageUrl: null, | ||
imageWidth: null, | ||
imageHeight: null, | ||
imageClass: null, | ||
timer: null, | ||
width: 500, | ||
padding: 20, | ||
background: '#fff', | ||
input: null, // 'text' | 'email' | 'password' | 'select' | 'radio' | 'checkbox' | 'textarea' | ||
inputPlaceholder: '', | ||
inputValue: '', | ||
inputOptions: {}, | ||
inputAutoTrim: true, | ||
inputClass: null, | ||
inputAttributes: {}, | ||
inputValidator: null | ||
}; | ||
/* | ||
* Manipulate DOM | ||
*/ | ||
var elementByClass = function(className) { | ||
return document.querySelector('.' + className); | ||
}; | ||
var getModal = function() { | ||
return elementByClass(swalClasses.modal); | ||
}; | ||
var getOverlay = function() { | ||
return elementByClass(swalClasses.overlay); | ||
}; | ||
var hasClass = function(elem, className) { | ||
return new RegExp(' ' + className + ' ').test(' ' + elem.className + ' '); | ||
}; | ||
var focusInput = function(input) { | ||
input.focus(); | ||
// http://stackoverflow.com/a/2345915/1331425 | ||
var val = input.value; | ||
input.value = ''; | ||
input.value = val; | ||
}; | ||
var addClass = function(elem, className) { | ||
if (className && !hasClass(elem, className)) { | ||
elem.className += ' ' + className; | ||
} | ||
}; | ||
var removeClass = function(elem, className) { | ||
var newClass = ' ' + elem.className.replace(/[\t\r\n]/g, ' ') + ' '; | ||
if (hasClass(elem, className)) { | ||
while (newClass.indexOf(' ' + className + ' ') >= 0) { | ||
newClass = newClass.replace(' ' + className + ' ', ' '); | ||
} | ||
elem.className = newClass.replace(/^\s+|\s+$/g, ''); | ||
} | ||
}; | ||
var getChildByClass = function(elem, className) { | ||
for (var i = 0; i < elem.childNodes.length; i++) { | ||
if (elem.childNodes[i].classList.contains(className)) { | ||
return elem.childNodes[i]; | ||
} | ||
} | ||
}; | ||
var _show = function(elem) { | ||
elem.style.opacity = ''; | ||
elem.style.display = 'block'; | ||
}; | ||
var show = function(elems) { | ||
if (elems && !elems.length) { | ||
return _show(elems); | ||
} | ||
for (var i = 0; i < elems.length; ++i) { | ||
_show(elems[i]); | ||
} | ||
}; | ||
var _hide = function(elem) { | ||
elem.style.opacity = ''; | ||
elem.style.display = 'none'; | ||
}; | ||
var hide = function(elems) { | ||
if (elems && !elems.length) { | ||
return _hide(elems); | ||
} | ||
for (var i = 0; i < elems.length; ++i) { | ||
_hide(elems[i]); | ||
} | ||
}; | ||
var removeStyleProperty = function(elem, property) { | ||
if (elem.style.removeProperty) { | ||
elem.style.removeProperty(property); | ||
} else { | ||
elem.style.removeAttribute(property); | ||
} | ||
}; | ||
var getTopMargin = function(elem) { | ||
elem.style.left = '-9999px'; | ||
elem.style.display = 'block'; | ||
var height = elem.clientHeight; | ||
var paddingTop = parseInt(getComputedStyle(elem).getPropertyValue('padding-top'), 10); | ||
elem.style.left = ''; | ||
elem.style.display = 'none'; | ||
return ('-' + parseInt(height / 2 + paddingTop, 10) + 'px'); | ||
}; | ||
var fadeIn = function(elem, interval) { | ||
if (+elem.style.opacity < 1) { | ||
interval = interval || 16; | ||
elem.style.opacity = 0; | ||
elem.style.display = 'block'; | ||
var last = +new Date(); | ||
var tick = function() { | ||
var newOpacity = +elem.style.opacity + (new Date() - last) / 100; | ||
elem.style.opacity = (newOpacity > 1) ? 1 : newOpacity; | ||
last = +new Date(); | ||
if (+elem.style.opacity < 1) { | ||
setTimeout(tick, interval); | ||
} | ||
}; | ||
tick(); | ||
} | ||
}; | ||
var fadeOut = function(elem, interval) { | ||
if (+elem.style.opacity > 0) { | ||
interval = interval || 16; | ||
var opacity = elem.style.opacity; | ||
var last = +new Date(); | ||
var tick = function() { | ||
var change = new Date() - last; | ||
var newOpacity = +elem.style.opacity - change / (opacity * 100); | ||
elem.style.opacity = newOpacity; | ||
last = +new Date(); | ||
if (+elem.style.opacity > 0) { | ||
setTimeout(tick, interval); | ||
} else { | ||
_hide(elem); | ||
} | ||
}; | ||
tick(); | ||
} | ||
}; | ||
var extend = function(a, b) { | ||
for (var key in b) { | ||
if (b.hasOwnProperty(key)) { | ||
a[key] = b[key]; | ||
} | ||
} | ||
return a; | ||
}; | ||
var fireClick = function(node) { | ||
// Taken from http://www.nonobtrusive.com/2011/11/29/programatically-fire-crossbrowser-click-event-with-javascript/ | ||
// Then fixed for today's Chrome browser. | ||
if (typeof MouseEvent === 'function') { | ||
// Up-to-date approach | ||
var mevt = new MouseEvent('click', { | ||
view: window, | ||
bubbles: false, | ||
cancelable: true | ||
}); | ||
node.dispatchEvent(mevt); | ||
} else if (document.createEvent) { | ||
// Fallback | ||
var evt = document.createEvent('MouseEvents'); | ||
evt.initEvent('click', false, false); | ||
node.dispatchEvent(evt); | ||
} else if (document.createEventObject) { | ||
node.fireEvent('onclick'); | ||
} else if (typeof node.onclick === 'function') { | ||
node.onclick(); | ||
} | ||
}; | ||
var stopEventPropagation = function(e) { | ||
// In particular, make sure the space bar doesn't scroll the main window. | ||
if (typeof e.stopPropagation === 'function') { | ||
e.stopPropagation(); | ||
e.preventDefault(); | ||
} else if (window.event && window.event.hasOwnProperty('cancelBubble')) { | ||
window.event.cancelBubble = true; | ||
} | ||
}; | ||
var animationEndEvent = (function() { | ||
var testEl = document.createElement('div'), | ||
transEndEventNames = { | ||
'WebkitAnimation': 'webkitAnimationEnd', | ||
'MozAnimation': 'animationend', | ||
'OAnimation': 'oAnimationEnd oanimationend', | ||
'msAnimation': 'MSAnimationEnd', | ||
'animation': 'animationend' | ||
}; | ||
for (var i in transEndEventNames) { | ||
if (transEndEventNames.hasOwnProperty(i) && | ||
testEl.style[i] !== undefined) { | ||
return transEndEventNames[i]; | ||
} | ||
} | ||
return false; | ||
})(); | ||
// Remember state in cases where opening and handling a modal will fiddle with it. | ||
var previousDocumentClick; | ||
var previousWindowKeyDown; | ||
var previousActiveElement; | ||
var lastFocusedButton; | ||
var previousDocumentClick, | ||
previousWindowKeyDown, | ||
previousActiveElement, | ||
lastFocusedButton; | ||
// Reset the page to its previous state | ||
var resetPrevState = function() { | ||
var modal = getModal(); | ||
window.onkeydown = previousWindowKeyDown; | ||
document.onclick = previousDocumentClick; | ||
if (previousActiveElement) { | ||
previousActiveElement.focus(); | ||
} | ||
lastFocusedButton = undefined; | ||
clearTimeout(modal.timeout); | ||
// Remove dynamically created media query | ||
var head = document.getElementsByTagName('head')[0]; | ||
var mediaquery = document.getElementById(mediaqueryId); | ||
if (mediaquery) { | ||
head.removeChild(mediaquery); | ||
} | ||
}; | ||
/* | ||
* Set hover, active and focus-states for buttons (source: http://www.sitepoint.com/javascript-generate-lighter-darker-color) | ||
*/ | ||
var colorLuminance = function(hex, lum) { | ||
// Validate hex string | ||
hex = String(hex).replace(/[^0-9a-f]/gi, ''); | ||
if (hex.length < 6) { | ||
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]; | ||
} | ||
lum = lum || 0; | ||
// Convert to decimal and change luminosity | ||
var rgb = '#'; | ||
for (var i = 0; i < 3; i++) { | ||
var c = parseInt(hex.substr(i * 2, 2), 16); | ||
c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16); | ||
rgb += ('00' + c).substr(c.length); | ||
} | ||
return rgb; | ||
}; | ||
/* | ||
* Set type, text and actions on modal | ||
@@ -313,3 +20,3 @@ */ | ||
var i; | ||
var modal = getModal(); | ||
var modal = dom.getModal(); | ||
@@ -326,3 +33,3 @@ // set modal width, padding and margin-left | ||
cssNode.type = 'text/css'; | ||
cssNode.id = mediaqueryId; | ||
cssNode.id = dom.mediaqueryId; | ||
var margin = 5; // % | ||
@@ -365,5 +72,5 @@ var mediaQueryMaxWidth = params.width + parseInt(params.width * (margin/100) * 2, 10); | ||
} | ||
show($content); | ||
dom.show($content); | ||
} else { | ||
hide($content); | ||
dom.hide($content); | ||
} | ||
@@ -373,5 +80,5 @@ | ||
if (params.showCloseButton) { | ||
show($closeButton); | ||
dom.show($closeButton); | ||
} else { | ||
hide($closeButton); | ||
dom.hide($closeButton); | ||
} | ||
@@ -382,10 +89,10 @@ | ||
if (params.customClass) { | ||
addClass(modal, params.customClass); | ||
dom.addClass(modal, params.customClass); | ||
} | ||
// Icon | ||
hide(modal.querySelectorAll('.' + swalClasses.icon)); | ||
dom.hide(modal.querySelectorAll('.' + swalClasses.icon)); | ||
if (params.type) { | ||
var validType = false; | ||
for (var iconType in swalClasses.iconTypes) { | ||
for (var iconType in iconTypes) { | ||
if (params.type === iconType) { | ||
@@ -400,4 +107,4 @@ validType = true; | ||
} | ||
var $icon = modal.querySelector('.' + swalClasses.icon + '.' + swalClasses.iconTypes[params.type]); | ||
show($icon); | ||
var $icon = modal.querySelector('.' + swalClasses.icon + '.' + iconTypes[params.type]); | ||
dom.show($icon); | ||
@@ -407,12 +114,12 @@ // Animate icon | ||
case 'success': | ||
addClass($icon, 'animate'); | ||
addClass($icon.querySelector('.tip'), 'animate-success-tip'); | ||
addClass($icon.querySelector('.long'), 'animate-success-long'); | ||
dom.addClass($icon, 'animate'); | ||
dom.addClass($icon.querySelector('.tip'), 'animate-success-tip'); | ||
dom.addClass($icon.querySelector('.long'), 'animate-success-long'); | ||
break; | ||
case 'error': | ||
addClass($icon, 'animate-error-icon'); | ||
addClass($icon.querySelector('.x-mark'), 'animate-x-mark'); | ||
dom.addClass($icon, 'animate-error-icon'); | ||
dom.addClass($icon.querySelector('.x-mark'), 'animate-x-mark'); | ||
break; | ||
case 'warning': | ||
addClass($icon, 'pulse-warning'); | ||
dom.addClass($icon, 'pulse-warning'); | ||
break; | ||
@@ -429,3 +136,3 @@ default: | ||
$customImage.setAttribute('src', params.imageUrl); | ||
show($customImage); | ||
dom.show($customImage); | ||
@@ -441,6 +148,6 @@ if (params.imageWidth) { | ||
if (params.imageClass) { | ||
addClass($customImage, params.imageClass); | ||
dom.addClass($customImage, params.imageClass); | ||
} | ||
} else { | ||
hide($customImage); | ||
dom.hide($customImage); | ||
} | ||
@@ -453,3 +160,3 @@ | ||
var inputClass = swalClasses[inputTypes[i]]; | ||
input = getChildByClass(modal, inputClass); | ||
input = dom.getChildByClass(modal, inputClass); | ||
@@ -467,6 +174,6 @@ // set attributes | ||
if (params.inputClass) { | ||
addClass(input, params.inputClass); | ||
dom.addClass(input, params.inputClass); | ||
} | ||
_hide(input); | ||
dom._hide(input); | ||
} | ||
@@ -477,10 +184,10 @@ switch (params.input) { | ||
case 'password': | ||
input = getChildByClass(modal, swalClasses.input); | ||
input = dom.getChildByClass(modal, swalClasses.input); | ||
input.value = params.inputValue; | ||
input.placeholder = params.inputPlaceholder; | ||
input.type = params.input; | ||
_show(input); | ||
dom._show(input); | ||
break; | ||
case 'select': | ||
var select = getChildByClass(modal, swalClasses.select); | ||
var select = dom.getChildByClass(modal, swalClasses.select); | ||
select.innerHTML = ''; | ||
@@ -504,6 +211,6 @@ if (params.inputPlaceholder) { | ||
} | ||
_show(select); | ||
dom._show(select); | ||
break; | ||
case 'radio': | ||
var radio = getChildByClass(modal, swalClasses.radio); | ||
var radio = dom.getChildByClass(modal, swalClasses.radio); | ||
radio.innerHTML = ''; | ||
@@ -528,6 +235,6 @@ for (var radioValue in params.inputOptions) { | ||
} | ||
_show(radio); | ||
dom._show(radio); | ||
break; | ||
case 'checkbox': | ||
var checkbox = getChildByClass(modal, swalClasses.checkbox); | ||
var checkbox = dom.getChildByClass(modal, swalClasses.checkbox); | ||
var checkboxInput = modal.querySelector('#' + swalClasses.checkbox); | ||
@@ -543,9 +250,9 @@ checkboxInput.value = 1; | ||
checkbox.appendChild(label); | ||
_show(checkbox); | ||
dom._show(checkbox); | ||
break; | ||
case 'textarea': | ||
var textarea = getChildByClass(modal, swalClasses.textarea); | ||
var textarea = dom.getChildByClass(modal, swalClasses.textarea); | ||
textarea.value = params.inputValue; | ||
textarea.placeholder = params.inputPlaceholder; | ||
_show(textarea); | ||
dom._show(textarea); | ||
break; | ||
@@ -563,3 +270,3 @@ case null: | ||
} else { | ||
hide($cancelBtn); | ||
dom.hide($cancelBtn); | ||
} | ||
@@ -569,5 +276,5 @@ | ||
if (params.showConfirmButton) { | ||
removeStyleProperty($confirmBtn, 'display'); | ||
dom.removeStyleProperty($confirmBtn, 'display'); | ||
} else { | ||
hide($confirmBtn); | ||
dom.hide($confirmBtn); | ||
} | ||
@@ -577,5 +284,5 @@ | ||
if (!params.showConfirmButton && !params.showCancelButton) { | ||
hide($spacer); | ||
dom.hide($spacer); | ||
} else { | ||
show($spacer); | ||
dom.show($spacer); | ||
} | ||
@@ -595,13 +302,13 @@ | ||
$confirmBtn.className = swalClasses.confirm; | ||
addClass($confirmBtn, params.confirmButtonClass); | ||
dom.addClass($confirmBtn, params.confirmButtonClass); | ||
$cancelBtn.className = swalClasses.cancel; | ||
addClass($cancelBtn, params.cancelButtonClass); | ||
dom.addClass($cancelBtn, params.cancelButtonClass); | ||
// Buttons styling | ||
if (params.buttonsStyling) { | ||
addClass($confirmBtn, 'styled'); | ||
addClass($cancelBtn, 'styled'); | ||
dom.addClass($confirmBtn, 'styled'); | ||
dom.addClass($cancelBtn, 'styled'); | ||
} else { | ||
removeClass($confirmBtn, 'styled'); | ||
removeClass($cancelBtn, 'styled'); | ||
dom.removeClass($confirmBtn, 'styled'); | ||
dom.removeClass($cancelBtn, 'styled'); | ||
@@ -614,5 +321,5 @@ $confirmBtn.style.backgroundColor = $confirmBtn.style.borderLeftColor = $confirmBtn.style.borderRightColor = ''; | ||
if (params.animation === true) { | ||
removeClass(modal, 'no-animation'); | ||
dom.removeClass(modal, 'no-animation'); | ||
} else { | ||
addClass(modal, 'no-animation'); | ||
dom.addClass(modal, 'no-animation'); | ||
} | ||
@@ -625,11 +332,11 @@ }; | ||
var openModal = function() { | ||
var modal = getModal(); | ||
fadeIn(getOverlay(), 10); | ||
show(modal); | ||
addClass(modal, 'show-swal2'); | ||
removeClass(modal, 'hide-swal2'); | ||
var modal = dom.getModal(); | ||
dom.fadeIn(dom.getOverlay(), 10); | ||
dom.show(modal); | ||
dom.addClass(modal, 'show-swal2'); | ||
dom.removeClass(modal, 'hide-swal2'); | ||
previousActiveElement = document.activeElement; | ||
addClass(modal, 'visible'); | ||
dom.addClass(modal, 'visible'); | ||
}; | ||
@@ -641,5 +348,5 @@ | ||
var fixVerticalPosition = function() { | ||
var modal = getModal(); | ||
var modal = dom.getModal(); | ||
modal.style.marginTop = getTopMargin(getModal()); | ||
modal.style.marginTop = dom.getTopMargin(dom.getModal()); | ||
}; | ||
@@ -666,43 +373,5 @@ | ||
case 'object': | ||
params.title = arguments[0].title || defaultParams.title; | ||
params.text = arguments[0].text || defaultParams.text; | ||
params.html = arguments[0].html || defaultParams.html; | ||
params.type = arguments[0].type || defaultParams.type; | ||
params.animation = arguments[0].animation !== undefined ? arguments[0].animation : defaultParams.animation; | ||
params.customClass = arguments[0].customClass || params.customClass; | ||
params.allowOutsideClick = arguments[0].allowOutsideClick !== undefined ? arguments[0].allowOutsideClick : defaultParams.allowOutsideClick; | ||
params.allowEscapeKey = arguments[0].allowEscapeKey !== undefined ? arguments[0].allowEscapeKey : defaultParams.allowEscapeKey; | ||
params.showConfirmButton = arguments[0].showConfirmButton !== undefined ? arguments[0].showConfirmButton : defaultParams.showConfirmButton; | ||
params.showCancelButton = arguments[0].showCancelButton !== undefined ? arguments[0].showCancelButton : defaultParams.showCancelButton; | ||
params.preConfirm = arguments[0].preConfirm || defaultParams.preConfirm; | ||
params.timer = parseInt(arguments[0].timer, 10) || defaultParams.timer; | ||
params.width = parseInt(arguments[0].width, 10) || defaultParams.width; | ||
params.padding = parseInt(arguments[0].padding, 10) || defaultParams.padding; | ||
params.background = arguments[0].background !== undefined ? arguments[0].background : defaultParams.background; | ||
extend(params, arguments[0]); | ||
params.extraParams = arguments[0].extraParams; | ||
params.confirmButtonText = arguments[0].confirmButtonText || defaultParams.confirmButtonText; | ||
params.confirmButtonColor = arguments[0].confirmButtonColor || defaultParams.confirmButtonColor; | ||
params.confirmButtonClass = arguments[0].confirmButtonClass || params.confirmButtonClass; | ||
params.cancelButtonText = arguments[0].cancelButtonText || defaultParams.cancelButtonText; | ||
params.cancelButtonColor = arguments[0].cancelButtonColor || defaultParams.cancelButtonColor; | ||
params.cancelButtonClass = arguments[0].cancelButtonClass || params.cancelButtonClass; | ||
params.buttonsStyling = arguments[0].buttonsStyling !== undefined ? arguments[0].buttonsStyling : defaultParams.buttonsStyling; | ||
params.reverseButtons = arguments[0].reverseButtons !== undefined ? arguments[0].reverseButtons : defaultParams.reverseButtons; | ||
params.showCloseButton = arguments[0].showCloseButton !== undefined ? arguments[0].showCloseButton : defaultParams.showCloseButton; | ||
params.imageUrl = arguments[0].imageUrl || defaultParams.imageUrl; | ||
params.imageWidth = arguments[0].imageWidth || defaultParams.imageWidth; | ||
params.imageHeight = arguments[0].imageHeight || defaultParams.imageHeight; | ||
params.imageClass = arguments[0].imageClass || defaultParams.imageClass; | ||
params.input = arguments[0].input || defaultParams.input; | ||
params.inputPlaceholder = arguments[0].inputPlaceholder || defaultParams.inputPlaceholder; | ||
params.inputValue = arguments[0].inputValue || defaultParams.inputValue; | ||
params.inputOptions = arguments[0].inputOptions || defaultParams.inputOptions; | ||
params.inputAutoTrim = arguments[0].inputAutoTrim !== undefined ? arguments[0].inputAutoTrim : defaultParams.inputAutoTrim; | ||
params.inputClass = arguments[0].inputClass || defaultParams.inputClass; | ||
params.inputAttributes = arguments[0].inputAttributes || defaultParams.inputAttributes; | ||
params.inputValidator = arguments[0].inputValidator || defaultParams.inputValidator; | ||
params.extraParams = arguments[0].extraParams; | ||
if (params.input === 'email' && params.inputValidator === null) { | ||
@@ -734,3 +403,3 @@ params.inputValidator = function(email) { | ||
// Modal interactions | ||
var modal = getModal(); | ||
var modal = dom.getModal(); | ||
@@ -750,3 +419,3 @@ return new Promise(function(resolve) { | ||
case 'select': | ||
return getChildByClass(modal, swalClasses.select); | ||
return dom.getChildByClass(modal, swalClasses.select); | ||
case 'radio': | ||
@@ -758,5 +427,5 @@ return modal.querySelector('.' + swalClasses.radio + ' input:checked') || | ||
case 'textarea': | ||
return getChildByClass(modal, swalClasses.textarea); | ||
return dom.getChildByClass(modal, swalClasses.textarea); | ||
default: | ||
return getChildByClass(modal, swalClasses.input); | ||
return dom.getChildByClass(modal, swalClasses.input); | ||
} | ||
@@ -778,3 +447,3 @@ }; | ||
setTimeout(function() { | ||
focusInput(getInput()); | ||
dom.focusInput(getInput()); | ||
}, 0); | ||
@@ -799,5 +468,5 @@ } | ||
var target = e.target || e.srcElement; | ||
var targetedConfirm = hasClass(target, swalClasses.confirm); | ||
var targetedCancel = hasClass(target, swalClasses.cancel); | ||
var modalIsVisible = hasClass(modal, 'visible'); | ||
var targetedConfirm = dom.hasClass(target, swalClasses.confirm); | ||
var targetedCancel = dom.hasClass(target, swalClasses.cancel); | ||
var modalIsVisible = dom.hasClass(modal, 'visible'); | ||
@@ -888,3 +557,3 @@ switch (e.type) { | ||
if (hasClass(target, swalClasses.close) || (target === getOverlay() && params.allowOutsideClick)) { | ||
if (dom.hasClass(target, swalClasses.close) || (target === dom.getOverlay() && params.allowOutsideClick)) { | ||
sweetAlert.closeModal(); | ||
@@ -994,4 +663,4 @@ resolve(undefined); | ||
sweetAlert.enableLoading = function() { | ||
addClass($confirmButton, 'loading'); | ||
addClass(modal, 'loading'); | ||
dom.addClass($confirmButton, 'loading'); | ||
dom.addClass(modal, 'loading'); | ||
$cancelButton.disabled = true; | ||
@@ -1001,4 +670,4 @@ }; | ||
sweetAlert.disableLoading = function() { | ||
removeClass($confirmButton, 'loading'); | ||
removeClass(modal, 'loading'); | ||
dom.removeClass($confirmButton, 'loading'); | ||
dom.removeClass(modal, 'loading'); | ||
$cancelButton.disabled = false; | ||
@@ -1046,7 +715,7 @@ }; | ||
$validationError.innerHTML = error; | ||
show($validationError); | ||
dom.show($validationError); | ||
var input = getInput(); | ||
focusInput(input); | ||
addClass(input, 'error'); | ||
dom.focusInput(input); | ||
dom.addClass(input, 'error'); | ||
}; | ||
@@ -1056,6 +725,6 @@ | ||
var $validationError = modal.querySelector('.' + swalClasses.validationerror); | ||
hide($validationError); | ||
dom.hide($validationError); | ||
var input = getInput(); | ||
removeClass(input, 'error'); | ||
dom.removeClass(input, 'error'); | ||
}; | ||
@@ -1085,11 +754,11 @@ | ||
var args = arguments; | ||
var modal = getModal(); | ||
var modal = dom.getModal(); | ||
if (modal === null) { | ||
sweetAlert.init(); | ||
modal = getModal(); | ||
modal = dom.getModal(); | ||
} | ||
if (hasClass(modal, 'visible')) { | ||
resetPrevState(); | ||
if (dom.hasClass(modal, 'visible')) { | ||
dom.resetPrevState(); | ||
} | ||
@@ -1104,33 +773,33 @@ | ||
sweetAlert.close = sweetAlert.closeModal = function() { | ||
var modal = getModal(); | ||
removeClass(modal, 'show-swal2'); | ||
addClass(modal, 'hide-swal2'); | ||
removeClass(modal, 'visible'); | ||
var modal = dom.getModal(); | ||
dom.removeClass(modal, 'show-swal2'); | ||
dom.addClass(modal, 'hide-swal2'); | ||
dom.removeClass(modal, 'visible'); | ||
// Reset icon animations | ||
var $successIcon = modal.querySelector('.' + swalClasses.icon + '.' + swalClasses.iconTypes.success); | ||
removeClass($successIcon, 'animate'); | ||
removeClass($successIcon.querySelector('.tip'), 'animate-success-tip'); | ||
removeClass($successIcon.querySelector('.long'), 'animate-success-long'); | ||
var $successIcon = modal.querySelector('.' + swalClasses.icon + '.' + iconTypes.success); | ||
dom.removeClass($successIcon, 'animate'); | ||
dom.removeClass($successIcon.querySelector('.tip'), 'animate-success-tip'); | ||
dom.removeClass($successIcon.querySelector('.long'), 'animate-success-long'); | ||
var $errorIcon = modal.querySelector('.' + swalClasses.icon + '.' + swalClasses.iconTypes.error); | ||
removeClass($errorIcon, 'animate-error-icon'); | ||
removeClass($errorIcon.querySelector('.x-mark'), 'animate-x-mark'); | ||
var $errorIcon = modal.querySelector('.' + swalClasses.icon + '.' + iconTypes.error); | ||
dom.removeClass($errorIcon, 'animate-error-icon'); | ||
dom.removeClass($errorIcon.querySelector('.x-mark'), 'animate-x-mark'); | ||
var $warningIcon = modal.querySelector('.' + swalClasses.icon + '.' + swalClasses.iconTypes.warning); | ||
removeClass($warningIcon, 'pulse-warning'); | ||
var $warningIcon = modal.querySelector('.' + swalClasses.icon + '.' + iconTypes.warning); | ||
dom.removeClass($warningIcon, 'pulse-warning'); | ||
resetPrevState(); | ||
dom.resetPrevState(); | ||
if (animationEndEvent && !hasClass(modal, 'no-animation')) { | ||
modal.addEventListener(animationEndEvent, function swalCloseEventFinished() { | ||
modal.removeEventListener(animationEndEvent, swalCloseEventFinished); | ||
if (hasClass(modal, 'hide-swal2')) { | ||
_hide(modal); | ||
fadeOut(getOverlay(), 0); | ||
if (dom.animationEndEvent && !dom.hasClass(modal, 'no-animation')) { | ||
modal.addEventListener(dom.animationEndEvent, function swalCloseEventFinished() { | ||
modal.removeEventListener(dom.animationEndEvent, swalCloseEventFinished); | ||
if (dom.hasClass(modal, 'hide-swal2')) { | ||
dom._hide(modal); | ||
dom.fadeOut(dom.getOverlay(), 0); | ||
} | ||
}); | ||
} else { | ||
_hide(modal); | ||
fadeOut(getOverlay(), 0); | ||
dom._hide(modal); | ||
dom.fadeOut(dom.getOverlay(), 0); | ||
} | ||
@@ -1143,3 +812,3 @@ }; | ||
sweetAlert.clickConfirm = function() { | ||
var modal = getModal(); | ||
var modal = dom.getModal(); | ||
var $confirmButton = modal.querySelector('button.' + swalClasses.confirm); | ||
@@ -1153,3 +822,3 @@ $confirmButton.click(); | ||
sweetAlert.clickCancel = function() { | ||
var modal = getModal(); | ||
var modal = dom.getModal(); | ||
var $cancelButton = modal.querySelector('button.' + swalClasses.cancel); | ||
@@ -1169,32 +838,3 @@ $cancelButton.click(); | ||
} | ||
var sweetHTML = | ||
'<div class="' + swalClasses.overlay + '" tabIndex="-1"></div>' + | ||
'<div class="' + swalClasses.modal + '" style="display: none" tabIndex="-1">' + | ||
'<div class="' + swalClasses.icon + ' ' + swalClasses.iconTypes.error + '">' + | ||
'<span class="x-mark"><span class="line left"></span><span class="line right"></span></span>' + | ||
'</div>' + | ||
'<div class="' + swalClasses.icon + ' ' + swalClasses.iconTypes.question + '">?</div>' + | ||
'<div class="' + swalClasses.icon + ' ' + swalClasses.iconTypes.warning + '">!</div>' + | ||
'<div class="' + swalClasses.icon + ' ' + swalClasses.iconTypes.info + '">i</div>' + | ||
'<div class="' + swalClasses.icon + ' ' + swalClasses.iconTypes.success + '">' + | ||
'<span class="line tip"></span> <span class="line long"></span>' + | ||
'<div class="placeholder"></div> <div class="fix"></div>' + | ||
'</div>' + | ||
'<img class="' + swalClasses.image + '">' + | ||
'<h2></h2>' + | ||
'<div class="' + swalClasses.content + '"></div>' + | ||
'<input class="' + swalClasses.input + '">' + | ||
'<select class="' + swalClasses.select + '"></select>' + | ||
'<div class="' + swalClasses.radio + '"></div>' + | ||
'<label for="' + swalClasses.checkbox + '" class="' + swalClasses.checkbox + '">' + | ||
'<input type="checkbox" id="' + swalClasses.checkbox + '">' + | ||
'</label>' + | ||
'<textarea class="' + swalClasses.textarea + '"></textarea>' + | ||
'<div class="' + swalClasses.validationerror + '"></div>' + | ||
'<hr class="' + swalClasses.spacer + '">' + | ||
'<button class="' + swalClasses.confirm + '">OK</button>' + | ||
'<button class="' + swalClasses.cancel + '">Cancel</button>' + | ||
'<span class="' + swalClasses.close + '">×</span>' + | ||
'</div>'; | ||
var sweetWrap = document.createElement('div'); | ||
@@ -1207,7 +847,7 @@ sweetWrap.className = swalClasses.container; | ||
var modal = getModal(); | ||
var $input = getChildByClass(modal, swalClasses.input); | ||
var $select = getChildByClass(modal, swalClasses.select); | ||
var modal = dom.getModal(); | ||
var $input = dom.getChildByClass(modal, swalClasses.input); | ||
var $select = dom.getChildByClass(modal, swalClasses.select); | ||
var $checkbox = modal.querySelector('#' + swalClasses.checkbox); | ||
var $textarea = getChildByClass(modal, swalClasses.textarea); | ||
var $textarea = dom.getChildByClass(modal, swalClasses.textarea); | ||
@@ -1214,0 +854,0 @@ $input.oninput = function() { |
Sorry, the diff of this file is not supported yet
15
174545
3706
199