Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sweetalert2

Package Overview
Dependencies
Maintainers
1
Versions
742
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sweetalert2 - npm Package Compare versions

Comparing version 2.1.1 to 2.2.0

2

dist/sweetalert2.min.js

@@ -1,1 +0,1 @@

!function(e,t){"use strict";function s(){if(void 0===arguments[0])return e.console.error("sweetAlert2 expects at least 1 attribute!"),!1;var s=x({},c);switch(typeof arguments[0]){case"string":s.title=arguments[0],s.text=arguments[1]||"",s.type=arguments[2]||"";break;case"object":s.title=arguments[0].title||c.title,s.text=arguments[0].text||c.text,s.html=arguments[0].html||c.html,s.type=arguments[0].type||c.type,s.animation=void 0!==arguments[0].animation?arguments[0].animation:c.animation,s.customClass=arguments[0].customClass||s.customClass,s.allowOutsideClick=void 0!==arguments[0].allowOutsideClick?arguments[0].allowOutsideClick:c.allowOutsideClick,s.allowEscapeKey=void 0!==arguments[0].allowEscapeKey?arguments[0].allowEscapeKey:c.allowEscapeKey,s.showConfirmButton=void 0!==arguments[0].showConfirmButton?arguments[0].showConfirmButton:c.showConfirmButton,s.showCancelButton=void 0!==arguments[0].showCancelButton?arguments[0].showCancelButton:c.showCancelButton,s.preConfirm=arguments[0].preConfirm||c.preConfirm,s.timer=parseInt(arguments[0].timer,10)||c.timer,s.width=parseInt(arguments[0].width,10)||c.width,s.padding=parseInt(arguments[0].padding,10)||c.padding,s.background=void 0!==arguments[0].background?arguments[0].background:c.background,s.confirmButtonText=arguments[0].confirmButtonText||c.confirmButtonText,s.confirmButtonColor=arguments[0].confirmButtonColor||c.confirmButtonColor,s.confirmButtonClass=arguments[0].confirmButtonClass||s.confirmButtonClass,s.cancelButtonText=arguments[0].cancelButtonText||c.cancelButtonText,s.cancelButtonColor=arguments[0].cancelButtonColor||c.cancelButtonColor,s.cancelButtonClass=arguments[0].cancelButtonClass||s.cancelButtonClass,s.buttonsStyling=void 0!==arguments[0].buttonsStyling?arguments[0].buttonsStyling:c.buttonsStyling,s.reverseButtons=void 0!==arguments[0].reverseButtons?arguments[0].reverseButtons:c.reverseButtons,s.showCloseButton=void 0!==arguments[0].showCloseButton?arguments[0].showCloseButton:c.showCloseButton,s.imageUrl=arguments[0].imageUrl||c.imageUrl,s.imageWidth=arguments[0].imageWidth||c.imageWidth,s.imageHeight=arguments[0].imageHeight||c.imageHeight,s.imageClass=arguments[0].imageClass||c.imageClass,s.input=arguments[0].input||c.input,s.inputPlaceholder=arguments[0].inputPlaceholder||c.inputPlaceholder,s.inputValue=arguments[0].inputValue||c.inputValue,s.inputOptions=arguments[0].inputOptions||c.inputOptions,s.inputClass=arguments[0].inputClass||c.inputClass,s.inputValidator=arguments[0].inputValidator||c.inputValidator,"email"===s.input&&null===s.inputValidator&&(s.inputValidator=function(e){return new Promise(function(t,s){var a=/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;a.test(e)?t():s("Invalid email address")})});break;default:return e.console.error('Unexpected type of argument! Expected "string" or "object", got '+typeof arguments[0]),!1}T(s),L(),M();var a=u();return new Promise(function(l){function i(e,t){for(var s=0;s<T.length;s++)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 c(t){var a=t||e.event,n=a.keyCode||a.which;if(-1!==[9,13,32,27].indexOf(n)){for(var o=a.target||a.srcElement,r=-1,c=0;c<T.length;c++)if(o===T[c]){r=c;break}9===n?(a.shiftKey?i(r,-1):i(r,1),S(a)):13===n||32===n?-1===r&&B(x,a):27===n&&s.allowEscapeKey===!0&&(e.swal.closeModal(),l(void 0))}}s.timer&&(a.timeout=setTimeout(function(){e.swal.closeModal(),l(void 0)},s.timer));var u=function(){switch(s.input){case"select":return a.querySelector("."+e.swalClasses.select);case"radio":return a.querySelector("."+e.swalClasses.radio+" input:checked")||a.querySelector("."+e.swalClasses.radio+" input:first-child");case"checkbox":return a.querySelector("#"+e.swalClasses.checkbox);case"textarea":return a.querySelector("."+e.swalClasses.textarea);default:return a.querySelector("."+e.swalClasses.input)}},m=function(){var e=u();switch(s.input){case"checkbox":return e.checked?1:0;case"radio":return e.checked?e.value:null;default:return e.value}};s.input&&setTimeout(function(){w(u())},0);var h,g=function(){if(s.input){var t=m();s.inputValidator?s.inputValidator(t).then(function(){e.swal.closeModal(),l(t)},function(t){e.swal.showValidationError(t)}):(e.swal.closeModal(),l(t))}else s.input||(e.swal.closeModal(),l(!0))},b=function(t){var n=t||e.event,o=n.target||n.srcElement,r=p(o,e.swalClasses.confirm),i=p(o,e.swalClasses.cancel),c=p(a,"visible");switch(n.type){case"mouseover":case"mouseup":case"focus":s.buttonsStyling&&(r?o.style.backgroundColor=q(s.confirmButtonColor,-.1):i&&(o.style.backgroundColor=q(s.cancelButtonColor,-.1)));break;case"mouseout":case"blur":s.buttonsStyling&&(r?o.style.backgroundColor=s.confirmButtonColor:i&&(o.style.backgroundColor=s.cancelButtonColor));break;case"mousedown":s.buttonsStyling&&(r?o.style.backgroundColor=q(s.confirmButtonColor,-.2):i&&(o.style.backgroundColor=q(s.cancelButtonColor,-.2)));break;case"click":r&&c?s.preConfirm?s.preConfirm().then(function(){g()}):g():i&&c?(e.swal.closeModal(),l(!1)):e.swal.closeModal()}},k=a.querySelectorAll("button");for(h=0;h<k.length;h++)k[h].onclick=b,k[h].onmouseover=b,k[h].onmouseout=b,k[h].onmousedown=b;n=t.onclick,t.onclick=function(t){var a=t||e.event,n=a.target||a.srcElement;(p(n,e.swalClasses.close)||n===d()&&s.allowOutsideClick)&&(e.swal.closeModal(),l(void 0))};var x=a.querySelector("button."+e.swalClasses.confirm),E=a.querySelector("button."+e.swalClasses.cancel),T=[x,E].concat(Array.prototype.slice.call(a.querySelectorAll("button:not([class^="+e.swalPrefix+"]), input:not([type=hidden]), textarea, select")));for(h=0;h<T.length;h++)T[h].onfocus=b,T[h].onblur=b;s.reverseButtons&&x.parentNode.insertBefore(E,x),i(-1,1),o=e.onkeydown,e.onkeydown=c,s.buttonsStyling&&(x.style.borderLeftColor=s.confirmButtonColor,x.style.borderRightColor=s.confirmButtonColor),e.swal.enableLoading=function(){f(x,"loading"),f(a,"loading"),E.disabled=!0},e.swal.disableLoading=function(){C(x,"loading"),C(a,"loading"),E.disabled=!1},e.swal.enableButtons=function(){x.disabled=!1,E.disabled=!1},e.swal.disableButtons=function(){x.disabled=!0,E.disabled=!0},e.swal.showValidationError=function(t){var s=a.querySelector("."+e.swalClasses.validationerror);s.innerHTML=t,y(s);var l=u();w(l),f(l,"error")},e.swal.resetValidationError=function(){var t=a.querySelector("."+e.swalClasses.validationerror);v(t);var s=u();C(s,"error")},e.swal.enableButtons(),e.swal.disableLoading(),e.swal.resetValidationError(),e.onfocus=function(){e.setTimeout(function(){void 0!==r&&(r.focus(),r=void 0)},0)}})}e.swalPrefix="swal2-";var a=function(t){var s={};for(var a in t)s[t[a]]=e.swalPrefix+t[a];return s};e.swalClasses=a(["container","modal","overlay","close","content","spacer","confirm","cancel","icon","image","input","select","radio","checkbox","textarea","validationerror"]),e.swalClasses.iconTypes=a(["success","warning","info","question","error"]);var l,n,o,r,i=e.swalPrefix+"mediaquery",c={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:{},inputClass:null,inputValidator:null},u=function(){return t.querySelector("."+e.swalClasses.modal)},d=function(){return t.querySelector("."+e.swalClasses.overlay)},p=function(e,t){return new RegExp(" "+t+" ").test(" "+e.className+" ")},w=function(e){e.focus();var t=e.value;e.value="",e.value=t},f=function(e,t){t&&!p(e,t)&&(e.className+=" "+t)},C=function(e,t){var s=" "+e.className.replace(/[\t\r\n]/g," ")+" ";if(p(e,t)){for(;s.indexOf(" "+t+" ")>=0;)s=s.replace(" "+t+" "," ");e.className=s.replace(/^\s+|\s+$/g,"")}},m=function(e){e.style.opacity="",e.style.display="block"},y=function(e){if(e&&!e.length)return m(e);for(var t=0;t<e.length;++t)m(e[t])},h=function(e){e.style.opacity="",e.style.display="none"},v=function(e){if(e&&!e.length)return h(e);for(var t=0;t<e.length;++t)h(e[t])},g=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,s=parseInt(getComputedStyle(e).getPropertyValue("padding-top"),10);return e.style.left="",e.style.display="none","-"+parseInt(t/2+s,10)+"px"},k=function(e,t){if(+e.style.opacity<1){t=t||16,e.style.opacity=0,e.style.display="block";var s=+new Date,a=function(){e.style.opacity=+e.style.opacity+(new Date-s)/100,s=+new Date,+e.style.opacity<1&&setTimeout(a,t)};a()}},x=function(e,t){for(var s in t)t.hasOwnProperty(s)&&(e[s]=t[s]);return e},B=function(s){if("function"==typeof MouseEvent){var a=new MouseEvent("click",{view:e,bubbles:!1,cancelable:!0});s.dispatchEvent(a)}else if(t.createEvent){var l=t.createEvent("MouseEvents");l.initEvent("click",!1,!1),s.dispatchEvent(l)}else t.createEventObject?s.fireEvent("onclick"):"function"==typeof s.onclick&&s.onclick()},S=function(t){"function"==typeof t.stopPropagation?(t.stopPropagation(),t.preventDefault()):e.event&&e.event.hasOwnProperty("cancelBubble")&&(e.event.cancelBubble=!0)},E=function(){var s=u();e.onkeydown=o,t.onclick=n,l&&l.focus(),r=void 0,clearTimeout(s.timeout);var a=t.getElementsByTagName("head")[0],c=t.getElementById(i);c&&a.removeChild(c)},q=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 s="#",a=0;3>a;a++){var l=parseInt(e.substr(2*a,2),16);l=Math.round(Math.min(Math.max(0,l+l*t),255)).toString(16),s+=("00"+l).substr(l.length)}return s},T=function(s){var a,l=u();l.style.width=s.width+"px",l.style.padding=s.padding+"px",l.style.marginLeft=-s.width/2+"px",l.style.background=s.background;var n=t.getElementsByTagName("head")[0],o=t.createElement("style");o.type="text/css",o.id=i,o.innerHTML="@media screen and (max-width: "+s.width+"px) {."+e.swalClasses.modal+" {max-width: 100%;left: 0 !important;margin-left: 0 !important;}}",n.appendChild(o);var r=l.querySelector("h2"),c=l.querySelector("."+e.swalClasses.content),d=l.querySelector("button."+e.swalClasses.confirm),p=l.querySelector("button."+e.swalClasses.cancel),w=l.querySelector("."+e.swalClasses.spacer),b=l.querySelector("."+e.swalClasses.close);if(r.innerHTML=s.title.split("\n").join("<br>"),s.text||s.html){if("object"==typeof s.html)if(c.innerHTML="",0 in s.html)for(a=0;a in s.html;a++)c.appendChild(s.html[a]);else c.appendChild(s.html);else c.innerHTML=s.html||"<p>"+s.text.split("\n").join("<br>")+"</p>";y(c)}else v(c);if(s.showCloseButton?y(b):v(b),l.className=e.swalClasses.modal,s.customClass&&f(l,s.customClass),v(l.querySelectorAll("."+e.swalClasses.icon)),s.type){var k=!1;for(var x in e.swalClasses.iconTypes)if(s.type===x){k=!0;break}if(!k)return e.console.error("Unknown alert type: "+s.type),!1;var B=l.querySelector("."+e.swalClasses.icon+"."+e.swalClasses.iconTypes[s.type]);switch(y(B),s.type){case"success":f(B,"animate"),f(B.querySelector(".tip"),"animate-success-tip"),f(B.querySelector(".long"),"animate-success-long");break;case"error":f(B,"animate-error-icon"),f(B.querySelector(".x-mark"),"animate-x-mark");break;case"warning":f(B,"pulse-warning")}}var S=l.querySelector("."+e.swalClasses.image);s.imageUrl?(S.setAttribute("src",s.imageUrl),y(S),s.imageWidth&&S.setAttribute("width",s.imageWidth),s.imageHeight&&S.setAttribute("height",s.imageHeight),s.imageClass&&f(S,s.imageClass)):v(S);var E,q=["input","select","radio","checkbox","textarea"];for(a=0;a<q.length;a++){var T=e.swalClasses[q[a]];E=l.querySelector("."+T),h(E),E.className=T,s.inputClass&&f(E,s.inputClass)}switch(s.input){case"text":case"email":case"password":E=l.querySelector("."+e.swalClasses.input),E.value=s.inputValue,E.placeholder=s.inputPlaceholder,E.type=s.input,m(E);break;case"select":var M=l.querySelector("."+e.swalClasses.select);if(M.innerHTML="",s.inputPlaceholder){var L=t.createElement("option");L.innerHTML=s.inputPlaceholder,L.disabled=!0,L.selected=!0,M.appendChild(L)}for(var V in s.inputOptions){var P=t.createElement("option");P.value=V,P.innerHTML=s.inputOptions[V],s.inputValue===V&&(P.selected=!0),M.appendChild(P)}m(M);break;case"radio":var O=l.querySelector("."+e.swalClasses.radio);O.innerHTML="";for(var H in s.inputOptions){var A=1,N=t.createElement("input"),I=t.createElement("label"),K=t.createElement("span");N.type="radio",N.name=e.swalClasses.radio,N.value=H,N.id=e.swalClasses.radio+"-"+A++,s.inputValue===H&&(N.checked=!0),K.innerHTML=s.inputOptions[H],I.appendChild(N),I.appendChild(K),I["for"]=N.id,O.appendChild(I)}m(O);break;case"checkbox":var U=l.querySelector("."+e.swalClasses.checkbox),j=l.querySelector("#"+e.swalClasses.checkbox);j.value=1,j.checked=Boolean(s.inputValue);var D=U.getElementsByTagName("span");D.length&&U.removeChild(D[0]),D=t.createElement("span"),D.innerHTML=s.inputPlaceholder,U.appendChild(D),m(U);break;case"textarea":var W=l.querySelector("."+e.swalClasses.textarea);W.value=s.inputValue,W.placeholder=s.inputPlaceholder,m(W);break;case null:break;default:e.console.error('Unexpected type of input! Expected "text" or "email" or "password", "select", "checkbox" or "textarea", got '+typeof arguments[0])}s.showCancelButton?p.style.display="inline-block":v(p),s.showConfirmButton?g(d,"display"):v(d),s.showConfirmButton||s.showCancelButton?y(w):v(w),d.innerHTML=s.confirmButtonText,p.innerHTML=s.cancelButtonText,s.buttonsStyling&&(d.style.backgroundColor=s.confirmButtonColor,p.style.backgroundColor=s.cancelButtonColor),d.className=e.swalClasses.confirm,f(d,s.confirmButtonClass),p.className=e.swalClasses.cancel,f(p,s.cancelButtonClass),s.buttonsStyling?(f(d,"styled"),f(p,"styled")):(C(d,"styled"),C(p,"styled"),d.style.backgroundColor=d.style.borderLeftColor=d.style.borderRightColor="",p.style.backgroundColor=p.style.borderLeftColor=p.style.borderRightColor=""),s.animation===!0?C(l,"no-animation"):f(l,"no-animation")},M=function(){var e=u();k(d(),10),y(e),f(e,"show-swal2"),C(e,"hide-swal2"),l=t.activeElement,f(e,"visible")},L=function(){var e=u();e.style.marginTop=b(u())};e.sweetAlert=e.swal=function(){var t=arguments,a=u();return null===a&&(e.swal.init(),a=u()),p(a,"visible")&&E(),s.apply(this,t)},e.sweetAlert.close=e.swal.close=e.sweetAlert.closeModal=e.swal.closeModal=function(){var t=u();h(d()),h(t),C(t,"show-swal2"),f(t,"hide-swal2"),C(t,"visible");var s=t.querySelector("."+e.swalClasses.icon+"."+e.swalClasses.iconTypes.success);C(s,"animate"),C(s.querySelector(".tip"),"animate-success-tip"),C(s.querySelector(".long"),"animate-success-long");var a=t.querySelector("."+e.swalClasses.icon+"."+e.swalClasses.iconTypes.error);C(a,"animate-error-icon"),C(a.querySelector(".x-mark"),"animate-x-mark");var l=t.querySelector("."+e.swalClasses.icon+"."+e.swalClasses.iconTypes.warning);C(l,"pulse-warning"),E()},e.sweetAlert.clickConfirm=e.swal.clickConfirm=function(){var t=u(),s=t.querySelector("button."+e.swalClasses.confirm);s.click()},e.sweetAlert.clickCancel=e.swal.clickCancel=function(){var t=u(),s=t.querySelector("button."+e.swalClasses.cancel);s.click()},e.swal.init=function(){if(!t.getElementsByClassName(e.swalClasses.container).length){var s='<div class="'+e.swalClasses.overlay+'" tabIndex="-1"></div><div class="'+e.swalClasses.modal+'" style="display: none" tabIndex="-1"><div class="'+e.swalClasses.icon+" "+e.swalClasses.iconTypes.error+'"><span class="x-mark"><span class="line left"></span><span class="line right"></span></span></div><div class="'+e.swalClasses.icon+" "+e.swalClasses.iconTypes.question+'">?</div><div class="'+e.swalClasses.icon+" "+e.swalClasses.iconTypes.warning+'">!</div><div class="'+e.swalClasses.icon+" "+e.swalClasses.iconTypes.info+'">i</div><div class="'+e.swalClasses.icon+" "+e.swalClasses.iconTypes.success+'"><span class="line tip"></span> <span class="line long"></span><div class="placeholder"></div> <div class="fix"></div></div><img class="'+e.swalClasses.image+'"><h2>Title</h2><div class="'+e.swalClasses.content+'">Text</div><input class="'+e.swalClasses.input+'"><select class="'+e.swalClasses.select+'"></select><fieldset class="'+e.swalClasses.radio+'"></fieldset><label for="'+e.swalClasses.checkbox+'" class="'+e.swalClasses.checkbox+'"><input type="checkbox" id="'+e.swalClasses.checkbox+'"></label><textarea class="'+e.swalClasses.textarea+'"></textarea><div class="'+e.swalClasses.validationerror+'"></div><hr class="'+e.swalClasses.spacer+'"><button class="'+e.swalClasses.confirm+'">OK</button><button class="'+e.swalClasses.cancel+'">Cancel</button><span class="'+e.swalClasses.close+'">&times;</span></div>',a=t.createElement("div");a.className=e.swalClasses.container,a.innerHTML=s,t.body.appendChild(a);var l=u(),n=l.querySelector("."+e.swalClasses.input),o=l.querySelector("."+e.swalClasses.select),r=l.querySelector("#"+e.swalClasses.checkbox),i=l.querySelector("."+e.swalClasses.textarea);n.oninput=function(){e.swal.resetValidationError()},n.onkeyup=function(t){13===t.keyCode&&e.swal.clickConfirm()},o.onchange=function(){e.swal.resetValidationError()},r.onchange=function(){e.swal.resetValidationError()},i.onchange=function(){e.swal.resetValidationError()}}},e.swal.setDefaults=function(e){if(!e)throw new Error("userParams is required");if("object"!=typeof e)throw new Error("userParams has to be a object");x(c,e)},function(){"complete"===t.readyState||"interactive"===t.readyState&&t.body?e.swal.init():t.addEventListener?t.addEventListener("DOMContentLoaded",function s(){t.removeEventListener("DOMContentLoaded",s,!1),e.swal.init()},!1):t.attachEvent&&t.attachEvent("onreadystatechange",function a(){"complete"===t.readyState&&(t.detachEvent("onreadystatechange",a),e.swal.init())})}()}(window,document);
!function(e,t){"use strict";function s(){if(void 0===arguments[0])return e.console.error("sweetAlert2 expects at least 1 attribute!"),!1;var s=x({},c);switch(typeof arguments[0]){case"string":s.title=arguments[0],s.text=arguments[1]||"",s.type=arguments[2]||"";break;case"object":s.title=arguments[0].title||c.title,s.text=arguments[0].text||c.text,s.html=arguments[0].html||c.html,s.type=arguments[0].type||c.type,s.animation=void 0!==arguments[0].animation?arguments[0].animation:c.animation,s.customClass=arguments[0].customClass||s.customClass,s.allowOutsideClick=void 0!==arguments[0].allowOutsideClick?arguments[0].allowOutsideClick:c.allowOutsideClick,s.allowEscapeKey=void 0!==arguments[0].allowEscapeKey?arguments[0].allowEscapeKey:c.allowEscapeKey,s.showConfirmButton=void 0!==arguments[0].showConfirmButton?arguments[0].showConfirmButton:c.showConfirmButton,s.showCancelButton=void 0!==arguments[0].showCancelButton?arguments[0].showCancelButton:c.showCancelButton,s.preConfirm=arguments[0].preConfirm||c.preConfirm,s.timer=parseInt(arguments[0].timer,10)||c.timer,s.width=parseInt(arguments[0].width,10)||c.width,s.padding=parseInt(arguments[0].padding,10)||c.padding,s.background=void 0!==arguments[0].background?arguments[0].background:c.background,s.confirmButtonText=arguments[0].confirmButtonText||c.confirmButtonText,s.confirmButtonColor=arguments[0].confirmButtonColor||c.confirmButtonColor,s.confirmButtonClass=arguments[0].confirmButtonClass||s.confirmButtonClass,s.cancelButtonText=arguments[0].cancelButtonText||c.cancelButtonText,s.cancelButtonColor=arguments[0].cancelButtonColor||c.cancelButtonColor,s.cancelButtonClass=arguments[0].cancelButtonClass||s.cancelButtonClass,s.buttonsStyling=void 0!==arguments[0].buttonsStyling?arguments[0].buttonsStyling:c.buttonsStyling,s.reverseButtons=void 0!==arguments[0].reverseButtons?arguments[0].reverseButtons:c.reverseButtons,s.showCloseButton=void 0!==arguments[0].showCloseButton?arguments[0].showCloseButton:c.showCloseButton,s.imageUrl=arguments[0].imageUrl||c.imageUrl,s.imageWidth=arguments[0].imageWidth||c.imageWidth,s.imageHeight=arguments[0].imageHeight||c.imageHeight,s.imageClass=arguments[0].imageClass||c.imageClass,s.input=arguments[0].input||c.input,s.inputPlaceholder=arguments[0].inputPlaceholder||c.inputPlaceholder,s.inputValue=arguments[0].inputValue||c.inputValue,s.inputOptions=arguments[0].inputOptions||c.inputOptions,s.inputClass=arguments[0].inputClass||c.inputClass,s.inputValidator=arguments[0].inputValidator||c.inputValidator,"email"===s.input&&null===s.inputValidator&&(s.inputValidator=function(e){return new Promise(function(t,s){var a=/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;a.test(e)?t():s("Invalid email address")})});break;default:return e.console.error('Unexpected type of argument! Expected "string" or "object", got '+typeof arguments[0]),!1}T(s),L(),M();var a=u();return new Promise(function(l){function i(e,t){for(var s=0;s<T.length;s++)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 c(t){var a=t||e.event,n=a.keyCode||a.which;if(-1!==[9,13,32,27].indexOf(n)){for(var o=a.target||a.srcElement,r=-1,c=0;c<T.length;c++)if(o===T[c]){r=c;break}9===n?(a.shiftKey?i(r,-1):i(r,1),S(a)):13===n||32===n?-1===r&&B(x,a):27===n&&s.allowEscapeKey===!0&&(e.swal.closeModal(),l(void 0))}}s.timer&&(a.timeout=setTimeout(function(){e.swal.closeModal(),l(void 0)},s.timer));var u=function(){switch(s.input){case"select":return a.querySelector("."+e.swalClasses.select);case"radio":return a.querySelector("."+e.swalClasses.radio+" input:checked")||a.querySelector("."+e.swalClasses.radio+" input:first-child");case"checkbox":return a.querySelector("#"+e.swalClasses.checkbox);case"textarea":return a.querySelector("."+e.swalClasses.textarea);default:return a.querySelector("."+e.swalClasses.input)}},m=function(){var e=u();switch(s.input){case"checkbox":return e.checked?1:0;case"radio":return e.checked?e.value:null;default:return e.value}};s.input&&setTimeout(function(){w(u())},0);var h,g=function(t){s.preConfirm?s.preConfirm().then(function(){l(t),e.swal.closeModal()}):(l(t),e.swal.closeModal())},b=function(t){var n=t||e.event,o=n.target||n.srcElement,r=p(o,e.swalClasses.confirm),i=p(o,e.swalClasses.cancel),c=p(a,"visible");switch(n.type){case"mouseover":case"mouseup":case"focus":s.buttonsStyling&&(r?o.style.backgroundColor=q(s.confirmButtonColor,-.1):i&&(o.style.backgroundColor=q(s.cancelButtonColor,-.1)));break;case"mouseout":case"blur":s.buttonsStyling&&(r?o.style.backgroundColor=s.confirmButtonColor:i&&(o.style.backgroundColor=s.cancelButtonColor));break;case"mousedown":s.buttonsStyling&&(r?o.style.backgroundColor=q(s.confirmButtonColor,-.2):i&&(o.style.backgroundColor=q(s.cancelButtonColor,-.2)));break;case"click":if(r&&c)if(s.input){var u=m();s.inputValidator?s.inputValidator(u).then(function(){g(u)},function(t){e.swal.showValidationError(t)}):g(u)}else g(!0);else i&&c?(e.swal.closeModal(),l(!1)):e.swal.closeModal()}},k=a.querySelectorAll("button");for(h=0;h<k.length;h++)k[h].onclick=b,k[h].onmouseover=b,k[h].onmouseout=b,k[h].onmousedown=b;n=t.onclick,t.onclick=function(t){var a=t||e.event,n=a.target||a.srcElement;(p(n,e.swalClasses.close)||n===d()&&s.allowOutsideClick)&&(e.swal.closeModal(),l(void 0))};var x=a.querySelector("button."+e.swalClasses.confirm),E=a.querySelector("button."+e.swalClasses.cancel),T=[x,E].concat(Array.prototype.slice.call(a.querySelectorAll("button:not([class^="+e.swalPrefix+"]), input:not([type=hidden]), textarea, select")));for(h=0;h<T.length;h++)T[h].onfocus=b,T[h].onblur=b;s.reverseButtons&&x.parentNode.insertBefore(E,x),i(-1,1),o=e.onkeydown,e.onkeydown=c,s.buttonsStyling&&(x.style.borderLeftColor=s.confirmButtonColor,x.style.borderRightColor=s.confirmButtonColor),e.swal.enableLoading=function(){f(x,"loading"),f(a,"loading"),E.disabled=!0},e.swal.disableLoading=function(){C(x,"loading"),C(a,"loading"),E.disabled=!1},e.swal.enableButtons=function(){x.disabled=!1,E.disabled=!1},e.swal.disableButtons=function(){x.disabled=!0,E.disabled=!0},e.swal.showValidationError=function(t){var s=a.querySelector("."+e.swalClasses.validationerror);s.innerHTML=t,y(s);var l=u();w(l),f(l,"error")},e.swal.resetValidationError=function(){var t=a.querySelector("."+e.swalClasses.validationerror);v(t);var s=u();C(s,"error")},e.swal.enableButtons(),e.swal.disableLoading(),e.swal.resetValidationError(),e.onfocus=function(){e.setTimeout(function(){void 0!==r&&(r.focus(),r=void 0)},0)}})}e.swalPrefix="swal2-";var a=function(t){var s={};for(var a in t)s[t[a]]=e.swalPrefix+t[a];return s};e.swalClasses=a(["container","modal","overlay","close","content","spacer","confirm","cancel","icon","image","input","select","radio","checkbox","textarea","validationerror"]),e.swalClasses.iconTypes=a(["success","warning","info","question","error"]);var l,n,o,r,i=e.swalPrefix+"mediaquery",c={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:{},inputClass:null,inputValidator:null},u=function(){return t.querySelector("."+e.swalClasses.modal)},d=function(){return t.querySelector("."+e.swalClasses.overlay)},p=function(e,t){return new RegExp(" "+t+" ").test(" "+e.className+" ")},w=function(e){e.focus();var t=e.value;e.value="",e.value=t},f=function(e,t){t&&!p(e,t)&&(e.className+=" "+t)},C=function(e,t){var s=" "+e.className.replace(/[\t\r\n]/g," ")+" ";if(p(e,t)){for(;s.indexOf(" "+t+" ")>=0;)s=s.replace(" "+t+" "," ");e.className=s.replace(/^\s+|\s+$/g,"")}},m=function(e){e.style.opacity="",e.style.display="block"},y=function(e){if(e&&!e.length)return m(e);for(var t=0;t<e.length;++t)m(e[t])},h=function(e){e.style.opacity="",e.style.display="none"},v=function(e){if(e&&!e.length)return h(e);for(var t=0;t<e.length;++t)h(e[t])},g=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,s=parseInt(getComputedStyle(e).getPropertyValue("padding-top"),10);return e.style.left="",e.style.display="none","-"+parseInt(t/2+s,10)+"px"},k=function(e,t){if(+e.style.opacity<1){t=t||16,e.style.opacity=0,e.style.display="block";var s=+new Date,a=function(){e.style.opacity=+e.style.opacity+(new Date-s)/100,s=+new Date,+e.style.opacity<1&&setTimeout(a,t)};a()}},x=function(e,t){for(var s in t)t.hasOwnProperty(s)&&(e[s]=t[s]);return e},B=function(s){if("function"==typeof MouseEvent){var a=new MouseEvent("click",{view:e,bubbles:!1,cancelable:!0});s.dispatchEvent(a)}else if(t.createEvent){var l=t.createEvent("MouseEvents");l.initEvent("click",!1,!1),s.dispatchEvent(l)}else t.createEventObject?s.fireEvent("onclick"):"function"==typeof s.onclick&&s.onclick()},S=function(t){"function"==typeof t.stopPropagation?(t.stopPropagation(),t.preventDefault()):e.event&&e.event.hasOwnProperty("cancelBubble")&&(e.event.cancelBubble=!0)},E=function(){var s=u();e.onkeydown=o,t.onclick=n,l&&l.focus(),r=void 0,clearTimeout(s.timeout);var a=t.getElementsByTagName("head")[0],c=t.getElementById(i);c&&a.removeChild(c)},q=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 s="#",a=0;3>a;a++){var l=parseInt(e.substr(2*a,2),16);l=Math.round(Math.min(Math.max(0,l+l*t),255)).toString(16),s+=("00"+l).substr(l.length)}return s},T=function(s){var a,l=u();l.style.width=s.width+"px",l.style.padding=s.padding+"px",l.style.marginLeft=-s.width/2+"px",l.style.background=s.background;var n=t.getElementsByTagName("head")[0],o=t.createElement("style");o.type="text/css",o.id=i,o.innerHTML="@media screen and (max-width: "+s.width+"px) {."+e.swalClasses.modal+" {max-width: 100%;left: 0 !important;margin-left: 0 !important;}}",n.appendChild(o);var r=l.querySelector("h2"),c=l.querySelector("."+e.swalClasses.content),d=l.querySelector("button."+e.swalClasses.confirm),p=l.querySelector("button."+e.swalClasses.cancel),w=l.querySelector("."+e.swalClasses.spacer),b=l.querySelector("."+e.swalClasses.close);if(r.innerHTML=s.title.split("\n").join("<br>"),s.text||s.html){if("object"==typeof s.html)if(c.innerHTML="",0 in s.html)for(a=0;a in s.html;a++)c.appendChild(s.html[a]);else c.appendChild(s.html);else c.innerHTML=s.html||"<p>"+s.text.split("\n").join("<br>")+"</p>";y(c)}else v(c);if(s.showCloseButton?y(b):v(b),l.className=e.swalClasses.modal,s.customClass&&f(l,s.customClass),v(l.querySelectorAll("."+e.swalClasses.icon)),s.type){var k=!1;for(var x in e.swalClasses.iconTypes)if(s.type===x){k=!0;break}if(!k)return e.console.error("Unknown alert type: "+s.type),!1;var B=l.querySelector("."+e.swalClasses.icon+"."+e.swalClasses.iconTypes[s.type]);switch(y(B),s.type){case"success":f(B,"animate"),f(B.querySelector(".tip"),"animate-success-tip"),f(B.querySelector(".long"),"animate-success-long");break;case"error":f(B,"animate-error-icon"),f(B.querySelector(".x-mark"),"animate-x-mark");break;case"warning":f(B,"pulse-warning")}}var S=l.querySelector("."+e.swalClasses.image);s.imageUrl?(S.setAttribute("src",s.imageUrl),y(S),s.imageWidth&&S.setAttribute("width",s.imageWidth),s.imageHeight&&S.setAttribute("height",s.imageHeight),s.imageClass&&f(S,s.imageClass)):v(S);var E,q=["input","select","radio","checkbox","textarea"];for(a=0;a<q.length;a++){var T=e.swalClasses[q[a]];E=l.querySelector("."+T),h(E),E.className=T,s.inputClass&&f(E,s.inputClass)}switch(s.input){case"text":case"email":case"password":E=l.querySelector("."+e.swalClasses.input),E.value=s.inputValue,E.placeholder=s.inputPlaceholder,E.type=s.input,m(E);break;case"select":var M=l.querySelector("."+e.swalClasses.select);if(M.innerHTML="",s.inputPlaceholder){var L=t.createElement("option");L.innerHTML=s.inputPlaceholder,L.disabled=!0,L.selected=!0,M.appendChild(L)}for(var V in s.inputOptions){var P=t.createElement("option");P.value=V,P.innerHTML=s.inputOptions[V],s.inputValue===V&&(P.selected=!0),M.appendChild(P)}m(M);break;case"radio":var O=l.querySelector("."+e.swalClasses.radio);O.innerHTML="";for(var H in s.inputOptions){var A=1,N=t.createElement("input"),I=t.createElement("label"),K=t.createElement("span");N.type="radio",N.name=e.swalClasses.radio,N.value=H,N.id=e.swalClasses.radio+"-"+A++,s.inputValue===H&&(N.checked=!0),K.innerHTML=s.inputOptions[H],I.appendChild(N),I.appendChild(K),I["for"]=N.id,O.appendChild(I)}m(O);break;case"checkbox":var U=l.querySelector("."+e.swalClasses.checkbox),j=l.querySelector("#"+e.swalClasses.checkbox);j.value=1,j.checked=Boolean(s.inputValue);var D=U.getElementsByTagName("span");D.length&&U.removeChild(D[0]),D=t.createElement("span"),D.innerHTML=s.inputPlaceholder,U.appendChild(D),m(U);break;case"textarea":var W=l.querySelector("."+e.swalClasses.textarea);W.value=s.inputValue,W.placeholder=s.inputPlaceholder,m(W);break;case null:break;default:e.console.error('Unexpected type of input! Expected "text" or "email" or "password", "select", "checkbox" or "textarea", got '+typeof arguments[0])}s.showCancelButton?p.style.display="inline-block":v(p),s.showConfirmButton?g(d,"display"):v(d),s.showConfirmButton||s.showCancelButton?y(w):v(w),d.innerHTML=s.confirmButtonText,p.innerHTML=s.cancelButtonText,s.buttonsStyling&&(d.style.backgroundColor=s.confirmButtonColor,p.style.backgroundColor=s.cancelButtonColor),d.className=e.swalClasses.confirm,f(d,s.confirmButtonClass),p.className=e.swalClasses.cancel,f(p,s.cancelButtonClass),s.buttonsStyling?(f(d,"styled"),f(p,"styled")):(C(d,"styled"),C(p,"styled"),d.style.backgroundColor=d.style.borderLeftColor=d.style.borderRightColor="",p.style.backgroundColor=p.style.borderLeftColor=p.style.borderRightColor=""),s.animation===!0?C(l,"no-animation"):f(l,"no-animation")},M=function(){var e=u();k(d(),10),y(e),f(e,"show-swal2"),C(e,"hide-swal2"),l=t.activeElement,f(e,"visible")},L=function(){var e=u();e.style.marginTop=b(u())};e.sweetAlert=e.swal=function(){var t=arguments,a=u();return null===a&&(e.swal.init(),a=u()),p(a,"visible")&&E(),s.apply(this,t)},e.sweetAlert.close=e.swal.close=e.sweetAlert.closeModal=e.swal.closeModal=function(){var t=u();h(d()),h(t),C(t,"show-swal2"),f(t,"hide-swal2"),C(t,"visible");var s=t.querySelector("."+e.swalClasses.icon+"."+e.swalClasses.iconTypes.success);C(s,"animate"),C(s.querySelector(".tip"),"animate-success-tip"),C(s.querySelector(".long"),"animate-success-long");var a=t.querySelector("."+e.swalClasses.icon+"."+e.swalClasses.iconTypes.error);C(a,"animate-error-icon"),C(a.querySelector(".x-mark"),"animate-x-mark");var l=t.querySelector("."+e.swalClasses.icon+"."+e.swalClasses.iconTypes.warning);C(l,"pulse-warning"),E()},e.sweetAlert.clickConfirm=e.swal.clickConfirm=function(){var t=u(),s=t.querySelector("button."+e.swalClasses.confirm);s.click()},e.sweetAlert.clickCancel=e.swal.clickCancel=function(){var t=u(),s=t.querySelector("button."+e.swalClasses.cancel);s.click()},e.swal.init=function(){if(!t.getElementsByClassName(e.swalClasses.container).length){var s='<div class="'+e.swalClasses.overlay+'" tabIndex="-1"></div><div class="'+e.swalClasses.modal+'" style="display: none" tabIndex="-1"><div class="'+e.swalClasses.icon+" "+e.swalClasses.iconTypes.error+'"><span class="x-mark"><span class="line left"></span><span class="line right"></span></span></div><div class="'+e.swalClasses.icon+" "+e.swalClasses.iconTypes.question+'">?</div><div class="'+e.swalClasses.icon+" "+e.swalClasses.iconTypes.warning+'">!</div><div class="'+e.swalClasses.icon+" "+e.swalClasses.iconTypes.info+'">i</div><div class="'+e.swalClasses.icon+" "+e.swalClasses.iconTypes.success+'"><span class="line tip"></span> <span class="line long"></span><div class="placeholder"></div> <div class="fix"></div></div><img class="'+e.swalClasses.image+'"><h2>Title</h2><div class="'+e.swalClasses.content+'">Text</div><input class="'+e.swalClasses.input+'"><select class="'+e.swalClasses.select+'"></select><fieldset class="'+e.swalClasses.radio+'"></fieldset><label for="'+e.swalClasses.checkbox+'" class="'+e.swalClasses.checkbox+'"><input type="checkbox" id="'+e.swalClasses.checkbox+'"></label><textarea class="'+e.swalClasses.textarea+'"></textarea><div class="'+e.swalClasses.validationerror+'"></div><hr class="'+e.swalClasses.spacer+'"><button class="'+e.swalClasses.confirm+'">OK</button><button class="'+e.swalClasses.cancel+'">Cancel</button><span class="'+e.swalClasses.close+'">&times;</span></div>',a=t.createElement("div");a.className=e.swalClasses.container,a.innerHTML=s,t.body.appendChild(a);var l=u(),n=l.querySelector("."+e.swalClasses.input),o=l.querySelector("."+e.swalClasses.select),r=l.querySelector("#"+e.swalClasses.checkbox),i=l.querySelector("."+e.swalClasses.textarea);n.oninput=function(){e.swal.resetValidationError()},n.onkeyup=function(t){13===t.keyCode&&e.swal.clickConfirm()},o.onchange=function(){e.swal.resetValidationError()},r.onchange=function(){e.swal.resetValidationError()},i.onchange=function(){e.swal.resetValidationError()}}},e.swal.setDefaults=function(e){if(!e)throw new Error("userParams is required");if("object"!=typeof e)throw new Error("userParams has to be a object");x(c,e)},function(){"complete"===t.readyState||"interactive"===t.readyState&&t.body?e.swal.init():t.addEventListener?t.addEventListener("DOMContentLoaded",function s(){t.removeEventListener("DOMContentLoaded",s,!1),e.swal.init()},!1):t.attachEvent&&t.attachEvent("onreadystatechange",function a(){"complete"===t.readyState&&(t.detachEvent("onreadystatechange",a),e.swal.init())})}()}(window,document);
{
"name": "sweetalert2",
"version": "2.1.1",
"version": "2.2.0",
"repository": "git@github.com:limonte/sweetalert2.git",

@@ -5,0 +5,0 @@ "description": "A replacement for JavaScript's popup boxes, supported fork of sweetalert",

@@ -685,24 +685,11 @@ // SweetAlert2

var confirm = function() {
if (params.input) {
var inputValue = getInputValue();
if (params.inputValidator) {
params.inputValidator(inputValue).then(
function() {
window.swal.closeModal();
resolve(inputValue);
},
function(error) {
window.swal.showValidationError(error);
}
);
} else {
var confirm = function(value) {
if (params.preConfirm) {
params.preConfirm().then(function() {
resolve(value);
window.swal.closeModal();
resolve(inputValue);
}
} else if (params.input) {
});
} else {
resolve(value);
window.swal.closeModal();
resolve(true);
}

@@ -754,8 +741,19 @@ };

if (params.preConfirm) {
params.preConfirm().then(function() {
confirm();
});
if (params.input) {
var inputValue = getInputValue();
if (params.inputValidator) {
params.inputValidator(inputValue).then(
function() {
confirm(inputValue);
},
function(error) {
window.swal.showValidationError(error);
}
);
} else {
confirm(inputValue);
}
} else {
confirm();
confirm(true);
}

@@ -762,0 +760,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc