sweetalert2
Advanced tools
Comparing version 3.2.0 to 3.2.1
/*! | ||
* sweetalert2 v3.2.0 | ||
* sweetalert2 v3.2.1 | ||
* (c) 2016 Tristan Edwards <tristan.edwards@me.com> (http://tristanedwards.me) | ||
@@ -291,2 +291,12 @@ * Released under the MIT License. | ||
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() { | ||
@@ -1078,3 +1088,3 @@ var testEl = document.createElement('div'), | ||
resetPrevState(); | ||
if (animationEndEvent && !hasClass(modal, 'no-animation')) { | ||
@@ -1122,3 +1132,3 @@ modal.addEventListener(animationEndEvent, function swalCloseEventFinished() { | ||
} | ||
var sweetWrap = document.createElement('div'); | ||
@@ -1176,3 +1186,3 @@ sweetWrap.className = swalClasses.container; | ||
sweetAlert.version = '3.2.0'; | ||
sweetAlert.version = '3.2.1'; | ||
@@ -1179,0 +1189,0 @@ window.sweetAlert = window.swal = sweetAlert; |
/*! | ||
* sweetalert2 v3.2.0 | ||
* sweetalert2 v3.2.1 | ||
* (c) 2016 Tristan Edwards <tristan.edwards@me.com> (http://tristanedwards.me) | ||
@@ -295,2 +295,12 @@ * Released under the MIT License. | ||
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() { | ||
@@ -1082,3 +1092,3 @@ var testEl = document.createElement('div'), | ||
resetPrevState(); | ||
if (animationEndEvent && !hasClass(modal, 'no-animation')) { | ||
@@ -1126,3 +1136,3 @@ modal.addEventListener(animationEndEvent, function swalCloseEventFinished() { | ||
} | ||
var sweetWrap = document.createElement('div'); | ||
@@ -1180,3 +1190,3 @@ sweetWrap.className = swalClasses.container; | ||
sweetAlert.version = '3.2.0'; | ||
sweetAlert.version = '3.2.1'; | ||
@@ -1183,0 +1193,0 @@ window.sweetAlert = window.swal = sweetAlert; |
/*! | ||
* sweetalert2 v3.2.0 | ||
* sweetalert2 v3.2.1 | ||
* (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=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}); | ||
!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}D(e),U(),j();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),H(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 E(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 E(n,p.textarea);default:return E(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(){B(b,"loading"),B(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();B(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")&&I(),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)},B=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,"")}},E=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)},P=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"},N=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(e){"function"==typeof e.stopPropagation?(e.stopPropagation(),e.preventDefault()):window.event&&window.event.hasOwnProperty("cancelBubble")&&(window.event.cancelBubble=!0)},O=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}(),I=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)},D=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=E(n,x);k.attributes.length>0;)k.removeAttribute(k.attributes[0].name);for(var P in e.inputAttributes)k.setAttribute(P,e.inputAttributes[P]);k.className=x,e.inputClass&&S(k,e.inputClass),T(k)}switch(e.input){case"text":case"email":case"password":k=E(n,p.input),k.value=e.inputValue,k.placeholder=e.inputPlaceholder,k.type=e.input,q(k);break;case"select":var N=E(n,p.select);if(N.innerHTML="",e.inputPlaceholder){var V=document.createElement("option");V.innerHTML=e.inputPlaceholder,V.value="",V.disabled=!0,V.selected=!0,N.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),N.appendChild(O)}q(N);break;case"radio":var I=E(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=E(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 $=E(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")):(B(s,"styled"),B(u,"styled"),s.style.backgroundColor=s.style.borderLeftColor=s.style.borderRightColor="",u.style.backgroundColor=u.style.borderLeftColor=u.style.borderRightColor=""),e.animation===!0?B(n,"no-animation"):S(n,"no-animation")},j=function(){var e=w();N(k(),10),A(e),S(e,"show-swal2"),B(e,"hide-swal2"),c=document.activeElement,S(e,"visible")},U=function(){var e=w();e.style.marginTop=P(w())};return t.close=t.closeModal=function(){var e=w();B(e,"show-swal2"),S(e,"hide-swal2"),B(e,"visible");var t=e.querySelector("."+p.icon+"."+m.success);B(t,"animate"),B(t.querySelector(".tip"),"animate-success-tip"),B(t.querySelector(".long"),"animate-success-long");var n=e.querySelector("."+p.icon+"."+m.error);B(n,"animate-error-icon"),B(n.querySelector(".x-mark"),"animate-x-mark");var o=e.querySelector("."+p.icon+"."+m.warning);B(o,"pulse-warning"),I(),O&&!C(e,"no-animation")?e.addEventListener(O,function r(){e.removeEventListener(O,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=E(n,p.input),r=E(n,p.select),a=n.querySelector("#"+p.checkbox),i=E(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.1",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.2.0", | ||
"version": "3.2.1", | ||
"repository": "https://github.com/limonte/sweetalert2.git", | ||
@@ -5,0 +5,0 @@ "homepage": "https://limonte.github.io/sweetalert2/", |
@@ -609,3 +609,3 @@ 'use strict'; | ||
stopEventPropagation(e); | ||
dom.stopEventPropagation(e); | ||
@@ -759,3 +759,3 @@ } else { | ||
dom.resetPrevState(); | ||
if (dom.animationEndEvent && !dom.hasClass(modal, 'no-animation')) { | ||
@@ -803,3 +803,3 @@ modal.addEventListener(dom.animationEndEvent, function swalCloseEventFinished() { | ||
} | ||
var sweetWrap = document.createElement('div'); | ||
@@ -806,0 +806,0 @@ sweetWrap.className = swalClasses.container; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
175426
3724