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 3.0.1 to 3.0.2

2

dist/sweetalert2.min.js

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

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

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

@@ -166,2 +166,4 @@ SweetAlert2 [![Build Status](https://travis-ci.org/limonte/sweetalert2.svg?branch=master)](https://travis-ci.org/limonte/sweetalert2)

| `swal.resetValidationError()` | Hide validation error message. |
| `swal.enableInput()` | Enable input, this method works with `input` parameter. |
| `swal.disableInput()` | Disable input. |

@@ -168,0 +170,0 @@

@@ -18,3 +18,3 @@ // SweetAlert2

exports['default'] = mod;
exports.default = mod;
} else {

@@ -26,2 +26,4 @@ factory(root);

var swalPrefix = 'swal2-';
var prefix = function(items) {

@@ -35,3 +37,2 @@ var result = {};

var swalPrefix = 'swal2-';
var swalClasses = prefix([

@@ -247,2 +248,3 @@ 'container', 'modal', 'overlay', 'close', 'content', 'spacer', 'confirm',

var previousWindowKeyDown;
var previousActiveElement;
var lastFocusedButton;

@@ -255,4 +257,4 @@

document.onclick = previousDocumentClick;
if (window.previousActiveElement) {
window.previousActiveElement.focus();
if (previousActiveElement) {
previousActiveElement.focus();
}

@@ -462,2 +464,3 @@ lastFocusedButton = undefined;

placeholder.innerHTML = params.inputPlaceholder;
placeholder.value = '';
placeholder.disabled = true;

@@ -595,3 +598,3 @@ placeholder.selected = true;

window.previousActiveElement = document.activeElement;
previousActiveElement = document.activeElement;

@@ -795,11 +798,14 @@ addClass(modal, 'visible');

if (targetedConfirm && modalIsVisible) {
if (params.input) {
var inputValue = getInputValue();
if (params.inputValidator) {
sweetAlert.disableInput();
params.inputValidator(inputValue, params.extraParams).then(
function() {
sweetAlert.enableInput();
confirm(inputValue);
},
function(error) {
sweetAlert.enableInput();
sweetAlert.showValidationError(error);

@@ -969,2 +975,28 @@ }

sweetAlert.enableInput = function() {
var input = getInput();
if (input.type === 'radio') {
var radiosContainer = input.parentNode.parentNode;
var radios = radiosContainer.querySelectorAll('input');
for (var i = 0; i < radios.length; i++) {
radios[i].disabled = false;
}
} else {
input.disabled = false;
}
};
sweetAlert.disableInput = function() {
var input = getInput();
if (input.type === 'radio') {
var radiosContainer = input.parentNode.parentNode;
var radios = radiosContainer.querySelectorAll('input');
for (var i = 0; i < radios.length; i++) {
radios[i].disabled = true;
}
} else {
input.disabled = true;
}
};
sweetAlert.showValidationError = function(error) {

@@ -1022,3 +1054,3 @@ var $validationError = modal.querySelector('.' + swalClasses.validationerror);

return modalDependant.apply(this, args);
};
}

@@ -1076,6 +1108,5 @@ /*

if (typeof document === 'undefined') {
console.log("SweetAlert2 requires document to initialize");
console.log('SweetAlert2 requires document to initialize');
return;
}
else if (document.getElementsByClassName(swalClasses.container).length) {
} else if (document.getElementsByClassName(swalClasses.container).length) {
return;

@@ -1174,15 +1205,6 @@ }

} else {
if (document.addEventListener) {
document.addEventListener('DOMContentLoaded', function onDomContentLoaded() {
document.removeEventListener('DOMContentLoaded', onDomContentLoaded, false);
sweetAlert.init();
}, false);
} else if (document.attachEvent) {
document.attachEvent('onreadystatechange', function onReadyStateChange() {
if (document.readyState === 'complete') {
document.detachEvent('onreadystatechange', onReadyStateChange);
sweetAlert.init();
}
});
}
document.addEventListener('DOMContentLoaded', function onDomContentLoaded() {
document.removeEventListener('DOMContentLoaded', onDomContentLoaded, false);
sweetAlert.init();
}, false);
}

@@ -1189,0 +1211,0 @@ })();

Sorry, the diff of this file is not supported yet

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