sweetalert2
Advanced tools
Comparing version
/*! | ||
* sweetalert2 v4.2.6 | ||
* sweetalert2 v4.2.7 | ||
* Released under the MIT License. | ||
@@ -177,2 +177,11 @@ */ | ||
var getIcons = function() { | ||
var modal = getModal(); | ||
return modal.querySelectorAll('.' + swalClasses.icon); | ||
}; | ||
var getSpacer = function() { | ||
return elementByClass(swalClasses.spacer); | ||
}; | ||
var getConfirmButton = function() { | ||
@@ -241,17 +250,11 @@ return elementByClass(swalClasses.confirm); | ||
var _show = function(elem) { | ||
var show = function(elem, display) { | ||
if (!display) { | ||
display = 'block'; | ||
} | ||
elem.style.opacity = ''; | ||
elem.style.display = 'block'; | ||
elem.style.display = display; | ||
}; | ||
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) { | ||
var hide = function(elem) { | ||
elem.style.opacity = ''; | ||
@@ -261,11 +264,2 @@ 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]); | ||
} | ||
}; | ||
// borrowed from jqeury $(elem).is(':visible') implementation | ||
@@ -329,3 +323,3 @@ var isVisible = function(elem) { | ||
} else { | ||
_hide(elem); | ||
hide(elem); | ||
} | ||
@@ -477,3 +471,2 @@ }; | ||
var $cancelBtn = getCancelButton(); | ||
var $spacer = modal.querySelector('.' + swalClasses.spacer); | ||
var $closeButton = modal.querySelector('.' + swalClasses.close); | ||
@@ -485,2 +478,3 @@ | ||
// Content | ||
var i; | ||
if (params.text || params.html) { | ||
@@ -490,3 +484,3 @@ if (typeof params.html === 'object') { | ||
if (0 in params.html) { | ||
for (var i = 0; i in params.html; i++) { | ||
for (i = 0; i in params.html; i++) { | ||
$content.appendChild(params.html[i].cloneNode(true)); | ||
@@ -519,3 +513,6 @@ } | ||
// Icon | ||
hide(modal.querySelectorAll('.' + swalClasses.icon)); | ||
var icons = getIcons(); | ||
for (i = 0; i < icons.length; i++) { | ||
hide(icons[i]); | ||
} | ||
if (params.type) { | ||
@@ -597,6 +594,7 @@ var validType = false; | ||
// Buttons spacer | ||
var spacer = getSpacer(); | ||
if (!params.showConfirmButton && !params.showCancelButton) { | ||
hide($spacer); | ||
hide(spacer); | ||
} else { | ||
show($spacer); | ||
show(spacer); | ||
} | ||
@@ -984,2 +982,4 @@ | ||
sweetAlert.showLoading = sweetAlert.enableLoading = function() { | ||
show(getSpacer()); | ||
show($confirmButton, 'inline-block'); | ||
addClass($confirmButton, 'loading'); | ||
@@ -995,2 +995,8 @@ addClass(modal, 'loading'); | ||
sweetAlert.hideLoading = sweetAlert.disableLoading = function() { | ||
if (!params.showConfirmButton) { | ||
hide($confirmButton); | ||
if (!params.showCancelButton) { | ||
hide(getSpacer()); | ||
} | ||
} | ||
removeClass($confirmButton, 'loading'); | ||
@@ -1091,3 +1097,3 @@ removeClass(modal, 'loading'); | ||
_hide(input); | ||
hide(input); | ||
} | ||
@@ -1108,3 +1114,3 @@ | ||
input.type = params.input; | ||
_show(input); | ||
show(input); | ||
break; | ||
@@ -1132,3 +1138,3 @@ case 'select': | ||
} | ||
_show(select); | ||
show(select); | ||
select.focus(); | ||
@@ -1159,3 +1165,3 @@ }; | ||
} | ||
_show(radio); | ||
show(radio); | ||
var radios = radio.querySelectorAll('input'); | ||
@@ -1179,3 +1185,3 @@ if (radios.length) { | ||
checkbox.appendChild(label); | ||
_show(checkbox); | ||
show(checkbox); | ||
break; | ||
@@ -1186,3 +1192,3 @@ case 'textarea': | ||
textarea.placeholder = params.inputPlaceholder; | ||
_show(textarea); | ||
show(textarea); | ||
break; | ||
@@ -1327,3 +1333,3 @@ case null: | ||
if (hasClass(modal, 'hide-swal2')) { | ||
_hide(modal); | ||
hide(modal); | ||
fadeOut(getOverlay(), 0); | ||
@@ -1335,4 +1341,4 @@ } | ||
// Otherwise, remove mediaquery immediately | ||
_hide(modal); | ||
_hide(getOverlay()); | ||
hide(modal); | ||
hide(getOverlay()); | ||
removeMediaQuery(mediaqueryId); | ||
@@ -1434,3 +1440,3 @@ } | ||
sweetAlert.version = '4.2.6'; | ||
sweetAlert.version = '4.2.7'; | ||
@@ -1437,0 +1443,0 @@ window.sweetAlert = window.swal = sweetAlert; |
/*! | ||
* sweetalert2 v4.2.6 | ||
* sweetalert2 v4.2.7 | ||
* Released under the MIT License. | ||
@@ -181,2 +181,11 @@ */ | ||
var getIcons = function() { | ||
var modal = getModal(); | ||
return modal.querySelectorAll('.' + swalClasses.icon); | ||
}; | ||
var getSpacer = function() { | ||
return elementByClass(swalClasses.spacer); | ||
}; | ||
var getConfirmButton = function() { | ||
@@ -245,17 +254,11 @@ return elementByClass(swalClasses.confirm); | ||
var _show = function(elem) { | ||
var show = function(elem, display) { | ||
if (!display) { | ||
display = 'block'; | ||
} | ||
elem.style.opacity = ''; | ||
elem.style.display = 'block'; | ||
elem.style.display = display; | ||
}; | ||
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) { | ||
var hide = function(elem) { | ||
elem.style.opacity = ''; | ||
@@ -265,11 +268,2 @@ 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]); | ||
} | ||
}; | ||
// borrowed from jqeury $(elem).is(':visible') implementation | ||
@@ -333,3 +327,3 @@ var isVisible = function(elem) { | ||
} else { | ||
_hide(elem); | ||
hide(elem); | ||
} | ||
@@ -481,3 +475,2 @@ }; | ||
var $cancelBtn = getCancelButton(); | ||
var $spacer = modal.querySelector('.' + swalClasses.spacer); | ||
var $closeButton = modal.querySelector('.' + swalClasses.close); | ||
@@ -489,2 +482,3 @@ | ||
// Content | ||
var i; | ||
if (params.text || params.html) { | ||
@@ -494,3 +488,3 @@ if (typeof params.html === 'object') { | ||
if (0 in params.html) { | ||
for (var i = 0; i in params.html; i++) { | ||
for (i = 0; i in params.html; i++) { | ||
$content.appendChild(params.html[i].cloneNode(true)); | ||
@@ -523,3 +517,6 @@ } | ||
// Icon | ||
hide(modal.querySelectorAll('.' + swalClasses.icon)); | ||
var icons = getIcons(); | ||
for (i = 0; i < icons.length; i++) { | ||
hide(icons[i]); | ||
} | ||
if (params.type) { | ||
@@ -601,6 +598,7 @@ var validType = false; | ||
// Buttons spacer | ||
var spacer = getSpacer(); | ||
if (!params.showConfirmButton && !params.showCancelButton) { | ||
hide($spacer); | ||
hide(spacer); | ||
} else { | ||
show($spacer); | ||
show(spacer); | ||
} | ||
@@ -988,2 +986,4 @@ | ||
sweetAlert.showLoading = sweetAlert.enableLoading = function() { | ||
show(getSpacer()); | ||
show($confirmButton, 'inline-block'); | ||
addClass($confirmButton, 'loading'); | ||
@@ -999,2 +999,8 @@ addClass(modal, 'loading'); | ||
sweetAlert.hideLoading = sweetAlert.disableLoading = function() { | ||
if (!params.showConfirmButton) { | ||
hide($confirmButton); | ||
if (!params.showCancelButton) { | ||
hide(getSpacer()); | ||
} | ||
} | ||
removeClass($confirmButton, 'loading'); | ||
@@ -1095,3 +1101,3 @@ removeClass(modal, 'loading'); | ||
_hide(input); | ||
hide(input); | ||
} | ||
@@ -1112,3 +1118,3 @@ | ||
input.type = params.input; | ||
_show(input); | ||
show(input); | ||
break; | ||
@@ -1136,3 +1142,3 @@ case 'select': | ||
} | ||
_show(select); | ||
show(select); | ||
select.focus(); | ||
@@ -1163,3 +1169,3 @@ }; | ||
} | ||
_show(radio); | ||
show(radio); | ||
var radios = radio.querySelectorAll('input'); | ||
@@ -1183,3 +1189,3 @@ if (radios.length) { | ||
checkbox.appendChild(label); | ||
_show(checkbox); | ||
show(checkbox); | ||
break; | ||
@@ -1190,3 +1196,3 @@ case 'textarea': | ||
textarea.placeholder = params.inputPlaceholder; | ||
_show(textarea); | ||
show(textarea); | ||
break; | ||
@@ -1331,3 +1337,3 @@ case null: | ||
if (hasClass(modal, 'hide-swal2')) { | ||
_hide(modal); | ||
hide(modal); | ||
fadeOut(getOverlay(), 0); | ||
@@ -1339,4 +1345,4 @@ } | ||
// Otherwise, remove mediaquery immediately | ||
_hide(modal); | ||
_hide(getOverlay()); | ||
hide(modal); | ||
hide(getOverlay()); | ||
removeMediaQuery(mediaqueryId); | ||
@@ -1438,3 +1444,3 @@ } | ||
sweetAlert.version = '4.2.6'; | ||
sweetAlert.version = '4.2.7'; | ||
@@ -1441,0 +1447,0 @@ window.sweetAlert = window.swal = sweetAlert; |
@@ -1,1 +0,1 @@ | ||
!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=c({},j);switch(typeof arguments[0]){case"string":e.title=arguments[0],e.text=arguments[1]||"",e.type=arguments[2]||"";break;case"object":c(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('SweetAlert2: Unexpected type of argument! Expected "string" or "object", got '+typeof arguments[0]),!1}K(e);var n=f();return new Promise(function(o,r){function a(t,n){for(var o=b(e.focusCancel),i=0;i<o.length;i++){t+=n,t===o.length?t=0:-1===t&&(t=o.length-1);var r=o[t];if(L(r))return r.focus()}}function l(n){var o=n||window.event,i=o.keyCode||o.which;if(-1!==[9,13,32,27].indexOf(i)){for(var l=o.target||o.srcElement,c=b(e.focusCancel),s=-1,u=0;u<c.length;u++)if(l===c[u]){s=u;break}9===i?(o.shiftKey?a(s,-1):a(s,1),V(o)):13===i||32===i?-1===s&&(e.focusCancel?O(P,o):O(M,o)):27===i&&e.allowEscapeKey===!0&&(t.closeModal(e.onClose),r("esc"))}}e.timer&&(n.timeout=setTimeout(function(){t.closeModal(e.onClose),r("timer")},e.timer));var c=function(){switch(e.input){case"select":return x(n,i.select);case"radio":return n.querySelector("."+i.radio+" input:checked")||n.querySelector("."+i.radio+" input:first-child");case"checkbox":return n.querySelector("#"+i.checkbox);case"textarea":return x(n,i.textarea);default:return x(n,i.input)}},u=function(){var t=c();switch(e.input){case"checkbox":return t.checked?1:0;case"radio":return t.checked?t.value:null;case"file":return t.files.length?t.files[0]:null;default:return e.inputAutoTrim?t.value.trim():t.value}};e.input&&setTimeout(function(){var e=c();e&&w(e)},0);var p,f=function(n){e.showLoaderOnConfirm&&t.showLoading(),e.preConfirm?e.preConfirm(n,e.extraParams).then(function(i){t.closeModal(e.onClose),o(i||n)},function(e){t.hideLoading(),e&&t.showValidationError(e)}):(t.closeModal(e.onClose),o(n))},g=function(n){var o=n||window.event,i=o.target||o.srcElement,a=v(),l=y(),c=a===i||a.contains(i),d=l===i||l.contains(i);switch(o.type){case"mouseover":case"mouseup":e.buttonsStyling&&(c?a.style.backgroundColor=s(e.confirmButtonColor,-.1):d&&(l.style.backgroundColor=s(e.cancelButtonColor,-.1)));break;case"mouseout":e.buttonsStyling&&(c?a.style.backgroundColor=e.confirmButtonColor:d&&(l.style.backgroundColor=e.cancelButtonColor));break;case"mousedown":e.buttonsStyling&&(c?a.style.backgroundColor=s(e.confirmButtonColor,-.2):d&&(l.style.backgroundColor=s(e.cancelButtonColor,-.2)));break;case"click":if(c&&t.isVisible())if(e.input){var p=u();e.inputValidator?(t.disableInput(),e.inputValidator(p,e.extraParams).then(function(){t.enableInput(),f(p)},function(e){t.enableInput(),e&&t.showValidationError(e)})):f(p)}else f(!0);else d&&t.isVisible()&&(t.closeModal(e.onClose),r("cancel"))}},q=n.querySelectorAll("button");for(p=0;p<q.length;p++)q[p].onclick=g,q[p].onmouseover=g,q[p].onmouseout=g,q[p].onmousedown=g;h().onclick=function(){t.closeModal(e.onClose),r("close")},m().onclick=function(){e.allowOutsideClick&&(t.closeModal(e.onClose),r("overlay"))};var M=v(),P=y();e.reverseButtons?M.parentNode.insertBefore(P,M):M.parentNode.insertBefore(M,P),d.previousWindowKeyDown=window.onkeydown,window.onkeydown=l,e.buttonsStyling&&(M.style.borderLeftColor=e.confirmButtonColor,M.style.borderRightColor=e.confirmButtonColor),t.showLoading=t.enableLoading=function(){C(M,"loading"),C(n,"loading"),M.disabled=!0,P.disabled=!0},t.hideLoading=t.disableLoading=function(){k(M,"loading"),k(n,"loading"),M.disabled=!1,P.disabled=!1},t.enableButtons=function(){M.disabled=!1,P.disabled=!1},t.disableButtons=function(){M.disabled=!0,P.disabled=!0},t.enableConfirmButton=function(){M.disabled=!1},t.disableConfirmButton=function(){M.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("."+i.validationerror);t.innerHTML=e,S(t);var o=c();w(o),C(o,"error")},t.resetValidationError=function(){var e=n.querySelector("."+i.validationerror);B(e);var t=c();t&&k(t,"error")},t.enableButtons(),t.hideLoading(),t.resetValidationError();var T,N=["input","select","radio","checkbox","textarea"];for(p=0;p<N.length;p++){var H=i[N[p]];for(T=x(n,H);T.attributes.length>0;)T.removeAttribute(T.attributes[0].name);for(var D in e.inputAttributes)T.setAttribute(D,e.inputAttributes[D]);T.className=H,e.inputClass&&C(T,e.inputClass),A(T)}var I;switch(e.input){case"text":case"email":case"password":case"file":case"number":case"tel":case"range":T=x(n,i.input),T.value=e.inputValue,T.placeholder=e.inputPlaceholder,T.type=e.input,E(T);break;case"select":var j=x(n,i.select);if(j.innerHTML="",e.inputPlaceholder){var K=document.createElement("option");K.innerHTML=e.inputPlaceholder,K.value="",K.disabled=!0,K.selected=!0,j.appendChild(K)}I=function(t){for(var n in t){var o=document.createElement("option");o.value=n,o.innerHTML=t[n],e.inputValue===n&&(o.selected=!0),j.appendChild(o)}E(j),j.focus()};break;case"radio":var z=x(n,i.radio);z.innerHTML="",I=function(t){for(var n in t){var o=1,r=document.createElement("input"),a=document.createElement("label"),l=document.createElement("span");r.type="radio",r.name=i.radio,r.value=n,r.id=i.radio+"-"+o++,e.inputValue===n&&(r.checked=!0),l.innerHTML=t[n],a.appendChild(r),a.appendChild(l),a["for"]=r.id,z.appendChild(a)}E(z);var c=z.querySelectorAll("input");c.length&&c[0].focus()};break;case"checkbox":var R=x(n,i.checkbox),Z=n.querySelector("#"+i.checkbox);Z.value=1,Z.checked=Boolean(e.inputValue);var $=R.getElementsByTagName("span");$.length&&R.removeChild($[0]),$=document.createElement("span"),$.innerHTML=e.inputPlaceholder,R.appendChild($),E(R);break;case"textarea":var F=x(n,i.textarea);F.value=e.inputValue,F.placeholder=e.inputPlaceholder,E(F);break;case null:break;default:console.error('SweetAlert2: Unexpected type of input! Expected "text" or "email" or "password", "select", "checkbox", "textarea" or "file", got "'+e.input+'"')}"select"!==e.input&&"radio"!==e.input||(e.inputOptions instanceof Promise?(t.showLoading(),e.inputOptions.then(function(e){t.hideLoading(),I(e)})):"object"==typeof e.inputOptions?I(e.inputOptions):console.error("SweetAlert2: Unexpected type of inputOptions! Expected object or Promise, got "+typeof e.inputOptions)),W(),U(e.animation,e.onOpen),a(-1,1)})}function t(){var n=arguments,o=f();return null===o&&(t.init(),o=f()),t.isVisible()&&t.close(),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"]),r=o(["success","warning","info","question","error"]),a={title:"",text:"",html:"",type:null,customClass:"",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,focusCancel:!1,showCloseButton:!1,showLoaderOnConfirm:!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,onOpen:null,onClose:null},l='<div class="'+i.overlay+'" tabIndex="-1"></div><div class="'+i.modal+'" style="display: none" tabIndex="-1"><div class="'+i.icon+" "+r.error+'"><span class="x-mark"><span class="line left"></span><span class="line right"></span></span></div><div class="'+i.icon+" "+r.question+'">?</div><div class="'+i.icon+" "+r.warning+'">!</div><div class="'+i.icon+" "+r.info+'">i</div><div class="'+i.icon+" "+r.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 type="button" class="'+i.confirm+'">OK</button><button type="button" class="'+i.cancel+'">Cancel</button><span class="'+i.close+'">×</span></div>',c=function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n]);return e},s=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},u=function(e){return"function"==typeof e},d={previousWindowKeyDown:null,previousActiveElement:null},p=function(e){return document.querySelector("."+e)},f=function(){return p(i.modal)},m=function(){return p(i.overlay)},v=function(){return p(i.confirm)},y=function(){return p(i.cancel)},h=function(){return p(i.close)},b=function(e){var t=[v(),y()];return e&&t.reverse(),t.concat(Array.prototype.slice.call(f().querySelectorAll("button:not([class^="+n+"]), input:not([type=hidden]), textarea, select")))},g=function(e,t){return e.classList.contains(t)},w=function(e){e.focus();var t=e.value;e.value="",e.value=t},C=function(e,t){if(e&&t){var n=t.split(/\s+/);n.forEach(function(t){e.classList.add(t)})}},k=function(e,t){if(e&&t){var n=t.split(/\s+/);n.forEach(function(t){e.classList.remove(t)})}},x=function(e,t){for(var n=0;n<e.childNodes.length;n++)if(g(e.childNodes[n],t))return e.childNodes[n]},E=function(e){e.style.opacity="",e.style.display="block"},S=function(e){if(e&&!e.length)return E(e);for(var t=0;t<e.length;++t)E(e[t])},A=function(e){e.style.opacity="",e.style.display="none"},B=function(e){if(e&&!e.length)return A(e);for(var t=0;t<e.length;++t)A(e[t])},L=function(e){return e.offsetWidth||e.offsetHeight||e.getClientRects().length},q=function(e,t){e.style.removeProperty?e.style.removeProperty(t):e.style.removeAttribute(t)},M=function(e){var t=e.style.display;e.style.left="-9999px",e.style.display="block";var n=e.clientHeight;return e.style.left="",e.style.display=t,"-"+parseInt(n/2,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 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()}},T=function(e,t){if(+e.style.opacity>0){t=t||16;var n=e.style.opacity,o=+new Date,i=function(){var r=new Date-o,a=+e.style.opacity-r/(100*n);e.style.opacity=a,o=+new Date,+e.style.opacity>0?setTimeout(i,t):A(e)};i()}},O=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()},V=function(e){"function"==typeof e.stopPropagation?(e.stopPropagation(),e.preventDefault()):window.event&&window.event.hasOwnProperty("cancelBubble")&&(window.event.cancelBubble=!0)},N=function(){var e=document.createElement("div"),t={WebkitAnimation:"webkitAnimationEnd",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}(),H=function(){var e=f();window.onkeydown=d.previousWindowKeyDown,d.previousActiveElement&&d.previousActiveElement.focus&&d.previousActiveElement.focus(),clearTimeout(e.timeout)},D=function(e){var t=n+"mediaquery-"+Math.random().toString(36).substring(2,7),o=document.getElementsByTagName("head")[0],i=document.createElement("style");return i.type="text/css",i.id=t,i.innerHTML=e,o.appendChild(i),t},I=function(e){if(!e)return!1;var t=document.getElementsByTagName("head")[0],n=document.getElementById(e);n&&t.removeChild(n)},j=c({},a),K=function(e){var t=f();for(var n in e)a.hasOwnProperty(n)||"extraParams"===n||console.warn('SweetAlert2: Unknown parameter "'+n+'"');e.width=e.width.toString();var o,l=e.width.match(/^(\d+)(px|%)?$/);if(l?(o="px",l[2]&&(o=l[2]),l=parseInt(l[1],10),t.style.width=l+o,t.style.marginLeft=-l/2+o):console.warn('SweetAlert2: Invalid width parameter, usage examples: "400px", "50%", or just 500 which equals to "500px"'),t.style.padding=e.padding+"px",t.style.background=e.background,"px"===o){var c=5,s=l+l*(c/100)*2,u=D("@media screen and (max-width: "+s+"px) {."+i.modal+" {width: auto !important;left: "+c+"% !important;right: "+c+"% !important;margin-left: 0 !important;}}");t.setAttribute("data-mediaquery-id",u)}var d=t.querySelector("h2"),p=t.querySelector("."+i.content),m=v(),h=y(),b=t.querySelector("."+i.spacer),g=t.querySelector("."+i.close);if(d.innerHTML=e.title.split("\n").join("<br>"),e.text||e.html){if("object"==typeof e.html)if(p.innerHTML="",0 in e.html)for(var w=0;w in e.html;w++)p.appendChild(e.html[w].cloneNode(!0));else p.appendChild(e.html.cloneNode(!0));else p.innerHTML=e.html||e.text.split("\n").join("<br>");S(p)}else B(p);if(e.showCloseButton?S(g):B(g),t.className=i.modal,e.customClass&&C(t,e.customClass),B(t.querySelectorAll("."+i.icon)),e.type){var x=!1;for(var E in r)if(e.type===E){x=!0;break}if(!x)return console.error("SweetAlert2: Unknown alert type: "+e.type),!1;var A=t.querySelector("."+i.icon+"."+r[e.type]);switch(S(A),e.type){case"success":C(A,"animate"),C(A.querySelector(".tip"),"animate-success-tip"),C(A.querySelector(".long"),"animate-success-long");break;case"error":C(A,"animate-error-icon"),C(A.querySelector(".x-mark"),"animate-x-mark");break;case"warning":C(A,"pulse-warning")}}var L=t.querySelector("."+i.image);e.imageUrl?(L.setAttribute("src",e.imageUrl),S(L),e.imageWidth?L.setAttribute("width",e.imageWidth):L.removeAttribute("width"),e.imageHeight?L.setAttribute("height",e.imageHeight):L.removeAttribute("height"),L.className=i.image,e.imageClass&&C(L,e.imageClass)):B(L),e.showCancelButton?h.style.display="inline-block":B(h),e.showConfirmButton?q(m,"display"):B(m),e.showConfirmButton||e.showCancelButton?S(b):B(b),m.innerHTML=e.confirmButtonText,h.innerHTML=e.cancelButtonText,e.buttonsStyling&&(m.style.backgroundColor=e.confirmButtonColor,h.style.backgroundColor=e.cancelButtonColor),m.className=i.confirm,C(m,e.confirmButtonClass),h.className=i.cancel,C(h,e.cancelButtonClass),e.buttonsStyling?(C(m,"styled"),C(h,"styled")):(k(m,"styled"),k(h,"styled"),m.style.backgroundColor=m.style.borderLeftColor=m.style.borderRightColor="",h.style.backgroundColor=h.style.borderLeftColor=h.style.borderRightColor=""),e.animation===!0?k(t,"no-animation"):C(t,"no-animation")},U=function(e,t){var n=f();e?(P(m(),10),C(n,"show-swal2"),k(n,"hide-swal2")):S(m()),S(n),d.previousActiveElement=document.activeElement,null!==t&&"function"==typeof t&&t.call(this,n)},W=function(){var e=f();null!==e&&(e.style.marginTop=M(e))};return t.isVisible=function(){var e=f();return L(e)},t.queue=function(e,n){var o;return n&&(o={fork:function(e){n=e,this.next=e[0]},repeatCurrent:function(){n.unshift(this.current),this.next=this.current},insert:function(e){n.unshift(e),this.next=this.state},terminate:function(){n=[],this.next=""}}),new Promise(function(i,r){!function a(l,c){var s=null;u(e)?n&&n.length>0?(o.current=n[0],o.next=n.length>1?n[1]:"",o.alertNumber=l,n.shift(),s=e(o)):s=e(l):l<e.length&&(s=e[l]),s?t(s).then(function(){a(l+1,c)},function(e){r(e)}):i()}(0)})},t.close=t.closeModal=function(e){var t=f();k(t,"show-swal2"),C(t,"hide-swal2");var n=t.querySelector("."+i.icon+"."+r.success);k(n,"animate"),k(n.querySelector(".tip"),"animate-success-tip"),k(n.querySelector(".long"),"animate-success-long");var o=t.querySelector("."+i.icon+"."+r.error);k(o,"animate-error-icon"),k(o.querySelector(".x-mark"),"animate-x-mark");var a=t.querySelector("."+i.icon+"."+r.warning);k(a,"pulse-warning"),H();var l=t.getAttribute("data-mediaquery-id");N&&!g(t,"no-animation")?t.addEventListener(N,function c(){t.removeEventListener(N,c),g(t,"hide-swal2")&&(A(t),T(m(),0)),I(l)}):(A(t),A(m()),I(l)),null!==e&&"function"==typeof e&&e.call(this,t)},t.clickConfirm=function(){v().click()},t.clickCancel=function(){y().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=document.createElement("div");e.className=i.container,e.innerHTML=l,document.body.appendChild(e);var n=f(),o=x(n,i.input),r=x(n,i.select),a=n.querySelector("#"+i.checkbox),c=x(n,i.textarea),s=x(n,i.image);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()},c.oninput=function(){t.resetValidationError()},s.onload=s.onerror=W,window.addEventListener("resize",W,!1)}},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");c(j,e)},t.resetDefaults=function(){j=c({},a)},t.version="4.2.6",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)}(),"function"==typeof Promise?Promise.prototype.done=Promise.prototype.done||function(){return this["catch"](function(){})}:console.warn("SweetAlert2: Please inlude Promise polyfill BEFORE including sweetalert2.js if IE10+ support needed."),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=c({},j);switch(typeof arguments[0]){case"string":e.title=arguments[0],e.text=arguments[1]||"",e.type=arguments[2]||"";break;case"object":c(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('SweetAlert2: Unexpected type of argument! Expected "string" or "object", got '+typeof arguments[0]),!1}K(e);var n=f();return new Promise(function(o,r){function a(t,n){for(var o=w(e.focusCancel),i=0;i<o.length;i++){t+=n,t===o.length?t=0:-1===t&&(t=o.length-1);var r=o[t];if(L(r))return r.focus()}}function l(n){var o=n||window.event,i=o.keyCode||o.which;if(-1!==[9,13,32,27].indexOf(i)){for(var l=o.target||o.srcElement,c=w(e.focusCancel),s=-1,u=0;u<c.length;u++)if(l===c[u]){s=u;break}9===i?(o.shiftKey?a(s,-1):a(s,1),V(o)):13===i||32===i?-1===s&&(e.focusCancel?O(M,o):O(q,o)):27===i&&e.allowEscapeKey===!0&&(t.closeModal(e.onClose),r("esc"))}}e.timer&&(n.timeout=setTimeout(function(){t.closeModal(e.onClose),r("timer")},e.timer));var c=function(){switch(e.input){case"select":return S(n,i.select);case"radio":return n.querySelector("."+i.radio+" input:checked")||n.querySelector("."+i.radio+" input:first-child");case"checkbox":return n.querySelector("#"+i.checkbox);case"textarea":return S(n,i.textarea);default:return S(n,i.input)}},u=function(){var t=c();switch(e.input){case"checkbox":return t.checked?1:0;case"radio":return t.checked?t.value:null;case"file":return t.files.length?t.files[0]:null;default:return e.inputAutoTrim?t.value.trim():t.value}};e.input&&setTimeout(function(){var e=c();e&&k(e)},0);var p,f=function(n){e.showLoaderOnConfirm&&t.showLoading(),e.preConfirm?e.preConfirm(n,e.extraParams).then(function(i){t.closeModal(e.onClose),o(i||n)},function(e){t.hideLoading(),e&&t.showValidationError(e)}):(t.closeModal(e.onClose),o(n))},v=function(n){var o=n||window.event,i=o.target||o.srcElement,a=h(),l=b(),c=a===i||a.contains(i),d=l===i||l.contains(i);switch(o.type){case"mouseover":case"mouseup":e.buttonsStyling&&(c?a.style.backgroundColor=s(e.confirmButtonColor,-.1):d&&(l.style.backgroundColor=s(e.cancelButtonColor,-.1)));break;case"mouseout":e.buttonsStyling&&(c?a.style.backgroundColor=e.confirmButtonColor:d&&(l.style.backgroundColor=e.cancelButtonColor));break;case"mousedown":e.buttonsStyling&&(c?a.style.backgroundColor=s(e.confirmButtonColor,-.2):d&&(l.style.backgroundColor=s(e.cancelButtonColor,-.2)));break;case"click":if(c&&t.isVisible())if(e.input){var p=u();e.inputValidator?(t.disableInput(),e.inputValidator(p,e.extraParams).then(function(){t.enableInput(),f(p)},function(e){t.enableInput(),e&&t.showValidationError(e)})):f(p)}else f(!0);else d&&t.isVisible()&&(t.closeModal(e.onClose),r("cancel"))}},C=n.querySelectorAll("button");for(p=0;p<C.length;p++)C[p].onclick=v,C[p].onmouseover=v,C[p].onmouseout=v,C[p].onmousedown=v;g().onclick=function(){t.closeModal(e.onClose),r("close")},m().onclick=function(){e.allowOutsideClick&&(t.closeModal(e.onClose),r("overlay"))};var q=h(),M=b();e.reverseButtons?q.parentNode.insertBefore(M,q):q.parentNode.insertBefore(q,M),d.previousWindowKeyDown=window.onkeydown,window.onkeydown=l,e.buttonsStyling&&(q.style.borderLeftColor=e.confirmButtonColor,q.style.borderRightColor=e.confirmButtonColor),t.showLoading=t.enableLoading=function(){B(y()),B(q,"inline-block"),x(q,"loading"),x(n,"loading"),q.disabled=!0,M.disabled=!0},t.hideLoading=t.disableLoading=function(){e.showConfirmButton||(A(q),e.showCancelButton||A(y())),E(q,"loading"),E(n,"loading"),q.disabled=!1,M.disabled=!1},t.enableButtons=function(){q.disabled=!1,M.disabled=!1},t.disableButtons=function(){q.disabled=!0,M.disabled=!0},t.enableConfirmButton=function(){q.disabled=!1},t.disableConfirmButton=function(){q.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("."+i.validationerror);t.innerHTML=e,B(t);var o=c();k(o),x(o,"error")},t.resetValidationError=function(){var e=n.querySelector("."+i.validationerror);A(e);var t=c();t&&E(t,"error")},t.enableButtons(),t.hideLoading(),t.resetValidationError();var P,T=["input","select","radio","checkbox","textarea"];for(p=0;p<T.length;p++){var N=i[T[p]];for(P=S(n,N);P.attributes.length>0;)P.removeAttribute(P.attributes[0].name);for(var H in e.inputAttributes)P.setAttribute(H,e.inputAttributes[H]);P.className=N,e.inputClass&&x(P,e.inputClass),A(P)}var D;switch(e.input){case"text":case"email":case"password":case"file":case"number":case"tel":case"range":P=S(n,i.input),P.value=e.inputValue,P.placeholder=e.inputPlaceholder,P.type=e.input,B(P);break;case"select":var I=S(n,i.select);if(I.innerHTML="",e.inputPlaceholder){var j=document.createElement("option");j.innerHTML=e.inputPlaceholder,j.value="",j.disabled=!0,j.selected=!0,I.appendChild(j)}D=function(t){for(var n in t){var o=document.createElement("option");o.value=n,o.innerHTML=t[n],e.inputValue===n&&(o.selected=!0),I.appendChild(o)}B(I),I.focus()};break;case"radio":var K=S(n,i.radio);K.innerHTML="",D=function(t){for(var n in t){var o=1,r=document.createElement("input"),a=document.createElement("label"),l=document.createElement("span");r.type="radio",r.name=i.radio,r.value=n,r.id=i.radio+"-"+o++,e.inputValue===n&&(r.checked=!0),l.innerHTML=t[n],a.appendChild(r),a.appendChild(l),a["for"]=r.id,K.appendChild(a)}B(K);var c=K.querySelectorAll("input");c.length&&c[0].focus()};break;case"checkbox":var z=S(n,i.checkbox),R=n.querySelector("#"+i.checkbox);R.value=1,R.checked=Boolean(e.inputValue);var Z=z.getElementsByTagName("span");Z.length&&z.removeChild(Z[0]),Z=document.createElement("span"),Z.innerHTML=e.inputPlaceholder,z.appendChild(Z),B(z);break;case"textarea":var $=S(n,i.textarea);$.value=e.inputValue,$.placeholder=e.inputPlaceholder,B($);break;case null:break;default:console.error('SweetAlert2: Unexpected type of input! Expected "text" or "email" or "password", "select", "checkbox", "textarea" or "file", got "'+e.input+'"')}"select"!==e.input&&"radio"!==e.input||(e.inputOptions instanceof Promise?(t.showLoading(),e.inputOptions.then(function(e){t.hideLoading(),D(e)})):"object"==typeof e.inputOptions?D(e.inputOptions):console.error("SweetAlert2: Unexpected type of inputOptions! Expected object or Promise, got "+typeof e.inputOptions)),W(),U(e.animation,e.onOpen),a(-1,1)})}function t(){var n=arguments,o=f();return null===o&&(t.init(),o=f()),t.isVisible()&&t.close(),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"]),r=o(["success","warning","info","question","error"]),a={title:"",text:"",html:"",type:null,customClass:"",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,focusCancel:!1,showCloseButton:!1,showLoaderOnConfirm:!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,onOpen:null,onClose:null},l='<div class="'+i.overlay+'" tabIndex="-1"></div><div class="'+i.modal+'" style="display: none" tabIndex="-1"><div class="'+i.icon+" "+r.error+'"><span class="x-mark"><span class="line left"></span><span class="line right"></span></span></div><div class="'+i.icon+" "+r.question+'">?</div><div class="'+i.icon+" "+r.warning+'">!</div><div class="'+i.icon+" "+r.info+'">i</div><div class="'+i.icon+" "+r.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 type="button" class="'+i.confirm+'">OK</button><button type="button" class="'+i.cancel+'">Cancel</button><span class="'+i.close+'">×</span></div>',c=function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n]);return e},s=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},u=function(e){return"function"==typeof e},d={previousWindowKeyDown:null,previousActiveElement:null},p=function(e){return document.querySelector("."+e)},f=function(){return p(i.modal)},m=function(){return p(i.overlay)},v=function(){var e=f();return e.querySelectorAll("."+i.icon)},y=function(){return p(i.spacer)},h=function(){return p(i.confirm)},b=function(){return p(i.cancel)},g=function(){return p(i.close)},w=function(e){var t=[h(),b()];return e&&t.reverse(),t.concat(Array.prototype.slice.call(f().querySelectorAll("button:not([class^="+n+"]), input:not([type=hidden]), textarea, select")))},C=function(e,t){return e.classList.contains(t)},k=function(e){e.focus();var t=e.value;e.value="",e.value=t},x=function(e,t){if(e&&t){var n=t.split(/\s+/);n.forEach(function(t){e.classList.add(t)})}},E=function(e,t){if(e&&t){var n=t.split(/\s+/);n.forEach(function(t){e.classList.remove(t)})}},S=function(e,t){for(var n=0;n<e.childNodes.length;n++)if(C(e.childNodes[n],t))return e.childNodes[n]},B=function(e,t){t||(t="block"),e.style.opacity="",e.style.display=t},A=function(e){e.style.opacity="",e.style.display="none"},L=function(e){return e.offsetWidth||e.offsetHeight||e.getClientRects().length},q=function(e,t){e.style.removeProperty?e.style.removeProperty(t):e.style.removeAttribute(t)},M=function(e){var t=e.style.display;e.style.left="-9999px",e.style.display="block";var n=e.clientHeight;return e.style.left="",e.style.display=t,"-"+parseInt(n/2,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 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()}},T=function(e,t){if(+e.style.opacity>0){t=t||16;var n=e.style.opacity,o=+new Date,i=function(){var r=new Date-o,a=+e.style.opacity-r/(100*n);e.style.opacity=a,o=+new Date,+e.style.opacity>0?setTimeout(i,t):A(e)};i()}},O=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()},V=function(e){"function"==typeof e.stopPropagation?(e.stopPropagation(),e.preventDefault()):window.event&&window.event.hasOwnProperty("cancelBubble")&&(window.event.cancelBubble=!0)},N=function(){var e=document.createElement("div"),t={WebkitAnimation:"webkitAnimationEnd",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}(),H=function(){var e=f();window.onkeydown=d.previousWindowKeyDown,d.previousActiveElement&&d.previousActiveElement.focus&&d.previousActiveElement.focus(),clearTimeout(e.timeout)},D=function(e){var t=n+"mediaquery-"+Math.random().toString(36).substring(2,7),o=document.getElementsByTagName("head")[0],i=document.createElement("style");return i.type="text/css",i.id=t,i.innerHTML=e,o.appendChild(i),t},I=function(e){if(!e)return!1;var t=document.getElementsByTagName("head")[0],n=document.getElementById(e);n&&t.removeChild(n)},j=c({},a),K=function(e){var t=f();for(var n in e)a.hasOwnProperty(n)||"extraParams"===n||console.warn('SweetAlert2: Unknown parameter "'+n+'"');e.width=e.width.toString();var o,l=e.width.match(/^(\d+)(px|%)?$/);if(l?(o="px",l[2]&&(o=l[2]),l=parseInt(l[1],10),t.style.width=l+o,t.style.marginLeft=-l/2+o):console.warn('SweetAlert2: Invalid width parameter, usage examples: "400px", "50%", or just 500 which equals to "500px"'),t.style.padding=e.padding+"px",t.style.background=e.background,"px"===o){var c=5,s=l+l*(c/100)*2,u=D("@media screen and (max-width: "+s+"px) {."+i.modal+" {width: auto !important;left: "+c+"% !important;right: "+c+"% !important;margin-left: 0 !important;}}");t.setAttribute("data-mediaquery-id",u)}var d=t.querySelector("h2"),p=t.querySelector("."+i.content),m=h(),g=b(),w=t.querySelector("."+i.close);d.innerHTML=e.title.split("\n").join("<br>");var C;if(e.text||e.html){if("object"==typeof e.html)if(p.innerHTML="",0 in e.html)for(C=0;C in e.html;C++)p.appendChild(e.html[C].cloneNode(!0));else p.appendChild(e.html.cloneNode(!0));else p.innerHTML=e.html||e.text.split("\n").join("<br>");B(p)}else A(p);e.showCloseButton?B(w):A(w),t.className=i.modal,e.customClass&&x(t,e.customClass);var k=v();for(C=0;C<k.length;C++)A(k[C]);if(e.type){var S=!1;for(var L in r)if(e.type===L){S=!0;break}if(!S)return console.error("SweetAlert2: Unknown alert type: "+e.type),!1;var M=t.querySelector("."+i.icon+"."+r[e.type]);switch(B(M),e.type){case"success":x(M,"animate"),x(M.querySelector(".tip"),"animate-success-tip"),x(M.querySelector(".long"),"animate-success-long");break;case"error":x(M,"animate-error-icon"),x(M.querySelector(".x-mark"),"animate-x-mark");break;case"warning":x(M,"pulse-warning")}}var P=t.querySelector("."+i.image);e.imageUrl?(P.setAttribute("src",e.imageUrl),B(P),e.imageWidth?P.setAttribute("width",e.imageWidth):P.removeAttribute("width"),e.imageHeight?P.setAttribute("height",e.imageHeight):P.removeAttribute("height"),P.className=i.image,e.imageClass&&x(P,e.imageClass)):A(P),e.showCancelButton?g.style.display="inline-block":A(g),e.showConfirmButton?q(m,"display"):A(m);var T=y();e.showConfirmButton||e.showCancelButton?B(T):A(T),m.innerHTML=e.confirmButtonText,g.innerHTML=e.cancelButtonText,e.buttonsStyling&&(m.style.backgroundColor=e.confirmButtonColor,g.style.backgroundColor=e.cancelButtonColor),m.className=i.confirm,x(m,e.confirmButtonClass),g.className=i.cancel,x(g,e.cancelButtonClass),e.buttonsStyling?(x(m,"styled"),x(g,"styled")):(E(m,"styled"),E(g,"styled"),m.style.backgroundColor=m.style.borderLeftColor=m.style.borderRightColor="",g.style.backgroundColor=g.style.borderLeftColor=g.style.borderRightColor=""),e.animation===!0?E(t,"no-animation"):x(t,"no-animation")},U=function(e,t){var n=f();e?(P(m(),10),x(n,"show-swal2"),E(n,"hide-swal2")):B(m()),B(n),d.previousActiveElement=document.activeElement,null!==t&&"function"==typeof t&&t.call(this,n)},W=function(){var e=f();null!==e&&(e.style.marginTop=M(e))};return t.isVisible=function(){var e=f();return L(e)},t.queue=function(e,n){var o;return n&&(o={fork:function(e){n=e,this.next=e[0]},repeatCurrent:function(){n.unshift(this.current),this.next=this.current},insert:function(e){n.unshift(e),this.next=this.state},terminate:function(){n=[],this.next=""}}),new Promise(function(i,r){!function a(l,c){var s=null;u(e)?n&&n.length>0?(o.current=n[0],o.next=n.length>1?n[1]:"",o.alertNumber=l,n.shift(),s=e(o)):s=e(l):l<e.length&&(s=e[l]),s?t(s).then(function(){a(l+1,c)},function(e){r(e)}):i()}(0)})},t.close=t.closeModal=function(e){var t=f();E(t,"show-swal2"),x(t,"hide-swal2");var n=t.querySelector("."+i.icon+"."+r.success);E(n,"animate"),E(n.querySelector(".tip"),"animate-success-tip"),E(n.querySelector(".long"),"animate-success-long");var o=t.querySelector("."+i.icon+"."+r.error);E(o,"animate-error-icon"),E(o.querySelector(".x-mark"),"animate-x-mark");var a=t.querySelector("."+i.icon+"."+r.warning);E(a,"pulse-warning"),H();var l=t.getAttribute("data-mediaquery-id");N&&!C(t,"no-animation")?t.addEventListener(N,function c(){t.removeEventListener(N,c),C(t,"hide-swal2")&&(A(t),T(m(),0)),I(l)}):(A(t),A(m()),I(l)),null!==e&&"function"==typeof e&&e.call(this,t)},t.clickConfirm=function(){h().click()},t.clickCancel=function(){b().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=document.createElement("div");e.className=i.container,e.innerHTML=l,document.body.appendChild(e);var n=f(),o=S(n,i.input),r=S(n,i.select),a=n.querySelector("#"+i.checkbox),c=S(n,i.textarea),s=S(n,i.image);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()},c.oninput=function(){t.resetValidationError()},s.onload=s.onerror=W,window.addEventListener("resize",W,!1)}},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");c(j,e)},t.resetDefaults=function(){j=c({},a)},t.version="4.2.7",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)}(),"function"==typeof Promise?Promise.prototype.done=Promise.prototype.done||function(){return this["catch"](function(){})}:console.warn("SweetAlert2: Please inlude Promise polyfill BEFORE including sweetalert2.js if IE10+ support needed."),t}); |
{ | ||
"name": "sweetalert2", | ||
"version": "4.2.6", | ||
"version": "4.2.7", | ||
"repository": "https://github.com/limonte/sweetalert2.git", | ||
@@ -5,0 +5,0 @@ "homepage": "https://limonte.github.io/sweetalert2/", |
@@ -114,2 +114,3 @@ SweetAlert2 [](https://travis-ci.org/limonte/sweetalert2) | ||
Modal Types | ||
@@ -167,2 +168,3 @@ ----------- | ||
| `onClose` | `null` | Function to run when modal closes, provides modal DOM element as the first argument. | | ||
You can redefine default params by using `swal.setDefaults(customParams)` where `customParams` is an object. | ||
@@ -179,4 +181,3 @@ | ||
| `swal.resetDefaults()` | Resets settings to their default value. | | ||
| `swal.queue([Array] || Function, [Array])` | Provide array of SweetAlert2 parameters to show multiple modals, one modal after another or a function that returns alert parameters given modal number. See [usage example](https://limonte.github.io/sweetalert2/#chaining-modals). | | ||
| `swal.queue(Function, [Array])` | Provide an function that performs state machine like direction of modal flow and an array of default states to follow. The function will recieve an object indicating current and next state along with helper methods (`insert(string)`, `fork([string])`, `repeatCurrent()`, `terminate()`) to augment the flow of modals. See [usage example](https://limonte.github.io/sweetalert2/#state-machine). | | ||
| `swal.queue([Array] || Function)` | Provide array of SweetAlert2 parameters to show multiple modals, one modal after another or a function that returns alert parameters given modal number. See [usage example](https://limonte.github.io/sweetalert2/#chaining-modals). | | ||
| `swal.close()` or `swal.closeModal()` | Close the currently open SweetAlert2 modal programmatically. | | ||
@@ -197,2 +198,19 @@ | `swal.enableButtons()` | Enable "Confirm" and "Cancel" buttons. | | ||
State Machine | ||
------------- | ||
When a series of alerts are needed but depend on user input and/or external resources (i.e. AJAX), a state machine like function can be provided by `swal.queue(Function, [Array])`. | ||
The supplied function will be called upon for each modal and will receive a control hash as a parameter with the attributes/methods shown below. The supplied function must return a hash of swal parameters to build the current alert. | ||
The array parameter is the initial set of states to start the alert chain. See [usage example](https://limonte.github.io/sweetalert2/#state-machine). | ||
|Member | Type | Description | | ||
|------------------------------|------------|--------------------------------------------------------------------------------------------------------------------------------------| | ||
| `current` | `object` | Represents the state for the current alert. | | ||
| `next` | `object` | Represents the next state that will follow the current if not altered. Null would indicated that this is the last alert in the chain.| | ||
| `fork(Array[object])` | `function` | Replaces all remaining state objects in chain with the state array passed as a parameter. | | ||
| `repeatCurrent()` | `function` | Duplicates current alert state and inserts it next in state array | | ||
| `insert(object)` | `function` | Inserts new state to directly follow current. | | ||
| `terminate()` | `function` | Removes all states that were queued to follow current. | | ||
Browser compatibility | ||
@@ -199,0 +217,0 @@ --------------------- |
@@ -62,3 +62,2 @@ 'use strict'; | ||
var $cancelBtn = dom.getCancelButton(); | ||
var $spacer = modal.querySelector('.' + swalClasses.spacer); | ||
var $closeButton = modal.querySelector('.' + swalClasses.close); | ||
@@ -70,2 +69,3 @@ | ||
// Content | ||
var i; | ||
if (params.text || params.html) { | ||
@@ -75,3 +75,3 @@ if (typeof params.html === 'object') { | ||
if (0 in params.html) { | ||
for (var i = 0; i in params.html; i++) { | ||
for (i = 0; i in params.html; i++) { | ||
$content.appendChild(params.html[i].cloneNode(true)); | ||
@@ -104,3 +104,6 @@ } | ||
// Icon | ||
dom.hide(modal.querySelectorAll('.' + swalClasses.icon)); | ||
var icons = dom.getIcons(); | ||
for (i = 0; i < icons.length; i++) { | ||
dom.hide(icons[i]); | ||
} | ||
if (params.type) { | ||
@@ -182,6 +185,7 @@ var validType = false; | ||
// Buttons spacer | ||
var spacer = dom.getSpacer(); | ||
if (!params.showConfirmButton && !params.showCancelButton) { | ||
dom.hide($spacer); | ||
dom.hide(spacer); | ||
} else { | ||
dom.show($spacer); | ||
dom.show(spacer); | ||
} | ||
@@ -569,2 +573,4 @@ | ||
sweetAlert.showLoading = sweetAlert.enableLoading = function() { | ||
dom.show(dom.getSpacer()); | ||
dom.show($confirmButton, 'inline-block'); | ||
dom.addClass($confirmButton, 'loading'); | ||
@@ -580,2 +586,8 @@ dom.addClass(modal, 'loading'); | ||
sweetAlert.hideLoading = sweetAlert.disableLoading = function() { | ||
if (!params.showConfirmButton) { | ||
dom.hide($confirmButton); | ||
if (!params.showCancelButton) { | ||
dom.hide(dom.getSpacer()); | ||
} | ||
} | ||
dom.removeClass($confirmButton, 'loading'); | ||
@@ -676,3 +688,3 @@ dom.removeClass(modal, 'loading'); | ||
dom._hide(input); | ||
dom.hide(input); | ||
} | ||
@@ -693,3 +705,3 @@ | ||
input.type = params.input; | ||
dom._show(input); | ||
dom.show(input); | ||
break; | ||
@@ -717,3 +729,3 @@ case 'select': | ||
} | ||
dom._show(select); | ||
dom.show(select); | ||
select.focus(); | ||
@@ -744,3 +756,3 @@ }; | ||
} | ||
dom._show(radio); | ||
dom.show(radio); | ||
var radios = radio.querySelectorAll('input'); | ||
@@ -764,3 +776,3 @@ if (radios.length) { | ||
checkbox.appendChild(label); | ||
dom._show(checkbox); | ||
dom.show(checkbox); | ||
break; | ||
@@ -771,3 +783,3 @@ case 'textarea': | ||
textarea.placeholder = params.inputPlaceholder; | ||
dom._show(textarea); | ||
dom.show(textarea); | ||
break; | ||
@@ -912,3 +924,3 @@ case null: | ||
if (dom.hasClass(modal, 'hide-swal2')) { | ||
dom._hide(modal); | ||
dom.hide(modal); | ||
dom.fadeOut(dom.getOverlay(), 0); | ||
@@ -920,4 +932,4 @@ } | ||
// Otherwise, remove mediaquery immediately | ||
dom._hide(modal); | ||
dom._hide(dom.getOverlay()); | ||
dom.hide(modal); | ||
dom.hide(dom.getOverlay()); | ||
dom.removeMediaQuery(mediaqueryId); | ||
@@ -924,0 +936,0 @@ } |
@@ -24,2 +24,11 @@ import { swalPrefix, swalClasses } from './classes.js'; | ||
export var getIcons = function() { | ||
var modal = getModal(); | ||
return modal.querySelectorAll('.' + swalClasses.icon); | ||
}; | ||
export var getSpacer = function() { | ||
return elementByClass(swalClasses.spacer); | ||
}; | ||
export var getConfirmButton = function() { | ||
@@ -88,17 +97,11 @@ return elementByClass(swalClasses.confirm); | ||
export var _show = function(elem) { | ||
export var show = function(elem, display) { | ||
if (!display) { | ||
display = 'block'; | ||
} | ||
elem.style.opacity = ''; | ||
elem.style.display = 'block'; | ||
elem.style.display = display; | ||
}; | ||
export var show = function(elems) { | ||
if (elems && !elems.length) { | ||
return _show(elems); | ||
} | ||
for (var i = 0; i < elems.length; ++i) { | ||
_show(elems[i]); | ||
} | ||
}; | ||
export var _hide = function(elem) { | ||
export var hide = function(elem) { | ||
elem.style.opacity = ''; | ||
@@ -108,11 +111,2 @@ elem.style.display = 'none'; | ||
export var hide = function(elems) { | ||
if (elems && !elems.length) { | ||
return _hide(elems); | ||
} | ||
for (var i = 0; i < elems.length; ++i) { | ||
_hide(elems[i]); | ||
} | ||
}; | ||
// borrowed from jqeury $(elem).is(':visible') implementation | ||
@@ -176,3 +170,3 @@ export var isVisible = function(elem) { | ||
} else { | ||
_hide(elem); | ||
hide(elem); | ||
} | ||
@@ -179,0 +173,0 @@ }; |
Sorry, the diff of this file is not supported yet
208581
1.02%4420
0.41%241
8.07%