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.0.1 to 2.0.2

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("sweetAlert expects at least 1 attribute!"),!1;var s=k({},r);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||r.title,s.text=arguments[0].text||r.text,s.html=arguments[0].html||r.html,s.type=arguments[0].type||r.type,s.animation=void 0!==arguments[0].animation?arguments[0].animation:r.animation,s.customClass=arguments[0].customClass||s.customClass,s.allowOutsideClick=void 0!==arguments[0].allowOutsideClick?arguments[0].allowOutsideClick:r.allowOutsideClick,s.allowEscapeKey=void 0!==arguments[0].allowEscapeKey?arguments[0].allowEscapeKey:r.allowEscapeKey,s.showConfirmButton=void 0!==arguments[0].showConfirmButton?arguments[0].showConfirmButton:r.showConfirmButton,s.showCancelButton=void 0!==arguments[0].showCancelButton?arguments[0].showCancelButton:r.showCancelButton,s.preConfirm=arguments[0].preConfirm||r.preConfirm,s.timer=parseInt(arguments[0].timer,10)||r.timer,s.width=parseInt(arguments[0].width,10)||r.width,s.padding=parseInt(arguments[0].padding,10)||r.padding,s.background=void 0!==arguments[0].background?arguments[0].background:r.background,s.confirmButtonText=arguments[0].confirmButtonText||r.confirmButtonText,s.confirmButtonColor=arguments[0].confirmButtonColor||r.confirmButtonColor,s.confirmButtonClass=arguments[0].confirmButtonClass||s.confirmButtonClass,s.cancelButtonText=arguments[0].cancelButtonText||r.cancelButtonText,s.cancelButtonColor=arguments[0].cancelButtonColor||r.cancelButtonColor,s.cancelButtonClass=arguments[0].cancelButtonClass||s.cancelButtonClass,s.buttonsStyling=void 0!==arguments[0].buttonsStyling?arguments[0].buttonsStyling:r.buttonsStyling,s.reverseButtons=void 0!==arguments[0].reverseButtons?arguments[0].reverseButtons:r.reverseButtons,s.showCloseButton=void 0!==arguments[0].showCloseButton?arguments[0].showCloseButton:r.showCloseButton,s.imageUrl=arguments[0].imageUrl||r.imageUrl,s.imageWidth=arguments[0].imageWidth||r.imageWidth,s.imageHeight=arguments[0].imageHeight||r.imageHeight,s.imageClass=arguments[0].imageClass||r.imageClass,s.input=arguments[0].input||r.input,s.inputPlaceholder=arguments[0].inputPlaceholder||r.inputPlaceholder,s.inputValue=arguments[0].inputValue||r.inputValue,s.inputOptions=arguments[0].inputOptions||r.inputOptions,s.inputValidator=arguments[0].inputValidator||r.inputValidator;break;default:return e.console.error('Unexpected type of argument! Expected "string" or "object", got '+typeof arguments[0]),!1}T(s),M(),q();var n=c();return new Promise(function(i){function r(e,t){for(var s=0;s<q.length;s++)if(e+=t,e===q.length?e=0:-1===e&&(e=q.length-1),q[e].offsetWidth||q[e].offsetHeight||q[e].getClientRects().length)return void q[e].focus()}function c(t){var n=t||e.event,l=n.keyCode||n.which;if(-1!==[9,13,32,27].indexOf(l)){for(var a=n.target||n.srcElement,o=-1,c=0;c<q.length;c++)if(a===q[c]){o=c;break}9===l?(n.shiftKey?r(o,-1):r(o,1),x(n)):13===l||32===l?-1===o&&B(S,n):27===l&&s.allowEscapeKey===!0&&(e.swal.closeModal(),i(void 0))}}s.timer&&(n.timeout=setTimeout(function(){e.swal.closeModal(),i(void 0)},s.timer));var f=function(){return"select"===s.input?n.querySelector("."+e.swalClasses.select):"checkbox"===s.input?n.querySelector("#"+e.swalClasses.checkbox):n.querySelector("."+e.swalClasses.input)},C=function(){var e=f();return"checkbox"===s.input?e.checked?1:0:e.value};s.input&&setTimeout(function(){p(f())},0);var h,g=function(){if(s.input){var t=C();s.inputValidator?s.inputValidator(t).then(function(){e.swal.closeModal(),i(t)},function(t){e.swal.showValidationError(t)}):(e.swal.closeModal(),i(t))}else s.input||(e.swal.closeModal(),i(!0))},b=function(t){var l=t||e.event,a=l.target||l.srcElement,o=d(a,e.swalClasses.confirm),r=d(a,e.swalClasses.cancel),c=d(n,"visible");switch(l.type){case"mouseover":case"mouseup":case"focus":s.buttonsStyling&&(o?a.style.backgroundColor=E(s.confirmButtonColor,-.1):r&&(a.style.backgroundColor=E(s.cancelButtonColor,-.1)));break;case"mouseout":case"blur":s.buttonsStyling&&(o?a.style.backgroundColor=s.confirmButtonColor:r&&(a.style.backgroundColor=s.cancelButtonColor));break;case"mousedown":s.buttonsStyling&&(o?a.style.backgroundColor=E(s.confirmButtonColor,-.2):r&&(a.style.backgroundColor=E(s.cancelButtonColor,-.2)));break;case"click":o&&c?s.preConfirm?s.preConfirm().then(function(){g()}):g():r&&c?(e.swal.closeModal(),i(!1)):e.swal.closeModal()}},k=n.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;l=t.onclick,t.onclick=function(t){var n=t||e.event,l=n.target||n.srcElement;(d(l,e.swalClasses.close)||l===u()&&s.allowOutsideClick)&&(e.swal.closeModal(),i(void 0))};var S=n.querySelector("button."+e.swalClasses.confirm),T=n.querySelector("button."+e.swalClasses.cancel),q=[S,T].concat(Array.prototype.slice.call(n.querySelectorAll("button:not([class^=sweet-]), input:not([type=hidden]), textarea, select")));for(h=0;h<q.length;h++)q[h].onfocus=b,q[h].onblur=b;s.reverseButtons&&S.parentNode.insertBefore(T,S),r(-1,1),a=e.onkeydown,e.onkeydown=c,s.buttonsStyling&&(S.style.borderLeftColor=s.confirmButtonColor,S.style.borderRightColor=s.confirmButtonColor),e.swal.enableLoading=function(){w(S,"loading"),w(n,"loading"),T.disabled=!0},e.swal.disableLoading=function(){m(S,"loading"),m(n,"loading"),T.disabled=!1},e.swal.enableButtons=function(){S.disabled=!1,T.disabled=!1},e.swal.disableButtons=function(){S.disabled=!0,T.disabled=!0},e.swal.showValidationError=function(t){var s=n.querySelector("."+e.swalClasses.validationError);s.innerHTML=t,y(s);var l=f();p(l),w(l,"error")},e.swal.resetValidationError=function(){var t=n.querySelector("."+e.swalClasses.validationError);v(t);var s=f();m(s,"error")},e.swal.enableButtons(),e.swal.disableLoading(),e.swal.resetValidationError(),e.onfocus=function(){e.setTimeout(function(){void 0!==o&&(o.focus(),o=void 0)},0)}})}e.swalClasses={container:"sweet-container",modal:"sweet-alert",overlay:"sweet-overlay",close:"sweet-close",content:"sweet-content",spacer:"sweet-spacer",confirm:"sweet-confirm",cancel:"sweet-cancel",icon:"sweet-icon",image:"sweet-image",input:"sweet-input",select:"sweet-select",checkbox:"sweet-checkbox",validationError:"sweet-validation-error",iconTypes:{success:"sweet-success",warning:"sweet-warning",info:"sweet-info",question:"sweet-question",error:"sweet-error"}};var n,l,a,o,i="sweet-alert-mediaquery",r={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:{},inputValidator:null},c=function(){return t.querySelector("."+e.swalClasses.modal)},u=function(){return t.querySelector("."+e.swalClasses.overlay)},d=function(e,t){return new RegExp(" "+t+" ").test(" "+e.className+" ")},p=function(e){e.focus();var t=e.value;e.value="",e.value=t},w=function(e,t){t&&!d(e,t)&&(e.className+=" "+t)},m=function(e,t){var s=" "+e.className.replace(/[\t\r\n]/g," ")+" ";if(d(e,t)){for(;s.indexOf(" "+t+" ")>=0;)s=s.replace(" "+t+" "," ");e.className=s.replace(/^\s+|\s+$/g,"")}},f=function(e){e.style.opacity="",e.style.display="block"},y=function(e){if(e&&!e.length)return f(e);for(var t=0;t<e.length;++t)f(e[t])},C=function(e){e.style.opacity="",e.style.display="none"},v=function(e){if(e&&!e.length)return C(e);for(var t=0;t<e.length;++t)C(e[t])},h=function(e,t){e.style.removeProperty?e.style.removeProperty(t):e.style.removeAttribute(t)},g=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"},b=function(e,t){if(+e.style.opacity<1){t=t||16,e.style.opacity=0,e.style.display="block";var s=+new Date,n=function(){e.style.opacity=+e.style.opacity+(new Date-s)/100,s=+new Date,+e.style.opacity<1&&setTimeout(n,t)};n()}},k=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 n=new MouseEvent("click",{view:e,bubbles:!1,cancelable:!0});s.dispatchEvent(n)}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()},x=function(t){"function"==typeof t.stopPropagation?(t.stopPropagation(),t.preventDefault()):e.event&&e.event.hasOwnProperty("cancelBubble")&&(e.event.cancelBubble=!0)},S=function(){var s=c();e.onkeydown=a,t.onclick=l,n&&n.focus(),o=void 0,clearTimeout(s.timeout);var r=t.getElementsByTagName("head")[0],u=t.getElementById(i);u&&r.removeChild(u)},E=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="#",n=0;3>n;n++){var l=parseInt(e.substr(2*n,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 n=c();n.style.width=s.width+"px",n.style.padding=s.padding+"px",n.style.marginLeft=-s.width/2+"px",n.style.background=s.background;var l=t.getElementsByTagName("head")[0],a=t.createElement("style");a.type="text/css",a.id=i,a.innerHTML="@media screen and (max-width: "+s.width+"px) {."+e.swalClasses.modal+" {max-width: 100%;left: 0 !important;margin-left: 0 !important;}}",l.appendChild(a);var o=n.querySelector("h2"),r=n.querySelector("."+e.swalClasses.content),u=n.querySelector("button."+e.swalClasses.confirm),d=n.querySelector("button."+e.swalClasses.cancel),p=n.querySelector("."+e.swalClasses.spacer),g=n.querySelector("."+e.swalClasses.close);if(o.innerHTML=s.title.split("\n").join("<br>"),s.text||s.html){if("object"==typeof s.html)if(r.innerHTML="",0 in s.html)for(var b=0;b in s.html;b++)r.appendChild(s.html[b]);else r.appendChild(s.html);else r.innerHTML=s.html||"<p>"+s.text.split("\n").join("<br>")+"</p>";y(r)}else v(r);if(s.showCloseButton?y(g):v(g),n.className=e.swalClasses.modal,s.customClass&&w(n,s.customClass),v(n.querySelectorAll("."+e.swalClasses.icon)),s.type){var k=!1;for(var B in e.swalClasses.iconTypes)if(s.type===B){k=!0;break}if(!k)return e.console.error("Unknown alert type: "+s.type),!1;var x=n.querySelector("."+e.swalClasses.icon+"."+e.swalClasses.iconTypes[s.type]);switch(y(x),s.type){case"success":w(x,"animate"),w(x.querySelector(".tip"),"animate-success-tip"),w(x.querySelector(".long"),"animate-success-long");break;case"error":w(x,"animate-error-icon"),w(x.querySelector(".x-mark"),"animate-x-mark");break;case"warning":w(x,"pulse-warning")}}var S=n.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&&w(S,s.imageClass)):v(S);var E=n.querySelector("."+e.swalClasses.input),T=n.querySelector("."+e.swalClasses.select),q=n.querySelector("#"+e.swalClasses.checkbox),M=n.querySelector("."+e.swalClasses.checkbox);switch(C(E),C(T),C(M),s.input){case"text":case"email":case"password":E.value=s.inputValue,E.placeholder=s.inputPlaceholder,E.type=s.input,f(E);break;case"select":if(T.innerHTML="",s.inputPlaceholder){var L=t.createElement("option");L.innerHTML=s.inputPlaceholder,L.disabled=!0,L.selected=!0,T.appendChild(L)}for(var O in s.inputOptions){var V=t.createElement("option");V.value=O,V.innerHTML=s.inputOptions[O],s.inputValue===O&&(V.selected=!0),T.appendChild(V)}f(T);break;case"checkbox":q.value=1,q.checked=Boolean(s.inputValue);var H=M.getElementsByTagName("span");H.length&&M.removeChild(H[0]),H=t.createElement("span"),H.innerHTML=s.inputPlaceholder,M.appendChild(H),f(M);break;case null:break;default:e.console.error('Unexpected type of input! Expected "text" or "email" or "password", "select" or "checkbox", got '+typeof arguments[0])}s.showCancelButton?d.style.display="inline-block":v(d),s.showConfirmButton?h(u,"display"):v(u),s.showConfirmButton||s.showCancelButton?y(p):v(p),u.innerHTML=s.confirmButtonText,d.innerHTML=s.cancelButtonText,s.buttonsStyling&&(u.style.backgroundColor=s.confirmButtonColor,d.style.backgroundColor=s.cancelButtonColor),u.className=e.swalClasses.confirm,w(u,s.confirmButtonClass),d.className=e.swalClasses.cancel,w(d,s.cancelButtonClass),s.buttonsStyling?(w(u,"styled"),w(d,"styled")):(m(u,"styled"),m(d,"styled"),u.style.backgroundColor=u.style.borderLeftColor=u.style.borderRightColor="",d.style.backgroundColor=d.style.borderLeftColor=d.style.borderRightColor=""),s.animation===!0?m(n,"no-animation"):w(n,"no-animation")},q=function(){var e=c();b(u(),10),y(e),w(e,"show-sweet-alert"),m(e,"hide-sweet-alert"),n=t.activeElement,w(e,"visible")},M=function(){var e=c();e.style.marginTop=g(c())};e.sweetAlert=e.swal=function(){var t=arguments,n=c();return null===n&&(e.swal.init(),n=c()),d(n,"visible")&&S(),s.apply(this,t)},e.sweetAlert.close=e.swal.close=e.sweetAlert.closeModal=e.swal.closeModal=function(){var t=c();C(u()),C(t),m(t,"showSweetAlert"),w(t,"hideSweetAlert"),m(t,"visible");var s=t.querySelector("."+e.swalClasses.icon+"."+e.swalClasses.iconTypes.success);m(s,"animate"),m(s.querySelector(".tip"),"animate-success-tip"),m(s.querySelector(".long"),"animate-success-long");var n=t.querySelector("."+e.swalClasses.icon+"."+e.swalClasses.iconTypes.error);m(n,"animate-error-icon"),m(n.querySelector(".x-mark"),"animate-x-mark");var l=t.querySelector("."+e.swalClasses.icon+"."+e.swalClasses.iconTypes.warning);m(l,"pulse-warning"),S()},e.sweetAlert.clickConfirm=e.swal.clickConfirm=function(){var t=c(),s=t.querySelector("button."+e.swalClasses.confirm);s.click()},e.sweetAlert.clickCancel=e.swal.clickCancel=function(){var t=c(),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><label for="'+e.swalClasses.checkbox+'" class="'+e.swalClasses.checkbox+'"><input type="checkbox" id="'+e.swalClasses.checkbox+'"></label><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>',n=t.createElement("div");n.className=e.swalClasses.container,n.innerHTML=s,t.body.appendChild(n);var l=c(),a=l.querySelector("."+e.swalClasses.input),o=l.querySelector("."+e.swalClasses.select),i=l.querySelector("#"+e.swalClasses.checkbox);a.oninput=function(){e.swal.resetValidationError()},a.onkeyup=function(){13===event.keyCode&&e.swal.clickConfirm()},o.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");k(r,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 n(){"complete"===t.readyState&&(t.detachEvent("onreadystatechange",n),e.swal.init())})}()}(window,document);
!function(e,t){"use strict";function s(){if(void 0===arguments[0])return e.console.error("sweetAlert expects at least 1 attribute!"),!1;var s=k({},i);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||i.title,s.text=arguments[0].text||i.text,s.html=arguments[0].html||i.html,s.type=arguments[0].type||i.type,s.animation=void 0!==arguments[0].animation?arguments[0].animation:i.animation,s.customClass=arguments[0].customClass||s.customClass,s.allowOutsideClick=void 0!==arguments[0].allowOutsideClick?arguments[0].allowOutsideClick:i.allowOutsideClick,s.allowEscapeKey=void 0!==arguments[0].allowEscapeKey?arguments[0].allowEscapeKey:i.allowEscapeKey,s.showConfirmButton=void 0!==arguments[0].showConfirmButton?arguments[0].showConfirmButton:i.showConfirmButton,s.showCancelButton=void 0!==arguments[0].showCancelButton?arguments[0].showCancelButton:i.showCancelButton,s.preConfirm=arguments[0].preConfirm||i.preConfirm,s.timer=parseInt(arguments[0].timer,10)||i.timer,s.width=parseInt(arguments[0].width,10)||i.width,s.padding=parseInt(arguments[0].padding,10)||i.padding,s.background=void 0!==arguments[0].background?arguments[0].background:i.background,s.confirmButtonText=arguments[0].confirmButtonText||i.confirmButtonText,s.confirmButtonColor=arguments[0].confirmButtonColor||i.confirmButtonColor,s.confirmButtonClass=arguments[0].confirmButtonClass||s.confirmButtonClass,s.cancelButtonText=arguments[0].cancelButtonText||i.cancelButtonText,s.cancelButtonColor=arguments[0].cancelButtonColor||i.cancelButtonColor,s.cancelButtonClass=arguments[0].cancelButtonClass||s.cancelButtonClass,s.buttonsStyling=void 0!==arguments[0].buttonsStyling?arguments[0].buttonsStyling:i.buttonsStyling,s.reverseButtons=void 0!==arguments[0].reverseButtons?arguments[0].reverseButtons:i.reverseButtons,s.showCloseButton=void 0!==arguments[0].showCloseButton?arguments[0].showCloseButton:i.showCloseButton,s.imageUrl=arguments[0].imageUrl||i.imageUrl,s.imageWidth=arguments[0].imageWidth||i.imageWidth,s.imageHeight=arguments[0].imageHeight||i.imageHeight,s.imageClass=arguments[0].imageClass||i.imageClass,s.input=arguments[0].input||i.input,s.inputPlaceholder=arguments[0].inputPlaceholder||i.inputPlaceholder,s.inputValue=arguments[0].inputValue||i.inputValue,s.inputOptions=arguments[0].inputOptions||i.inputOptions,s.inputValidator=arguments[0].inputValidator||i.inputValidator;break;default:return e.console.error('Unexpected type of argument! Expected "string" or "object", got '+typeof arguments[0]),!1}q(s),M(),T();var a=c();return new Promise(function(r){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,l=a.keyCode||a.which;if(-1!==[9,13,32,27].indexOf(l)){for(var n=a.target||a.srcElement,o=-1,c=0;c<T.length;c++)if(n===T[c]){o=c;break}9===l?(a.shiftKey?i(o,-1):i(o,1),x(a)):13===l||32===l?-1===o&&B(S,a):27===l&&s.allowEscapeKey===!0&&(e.swal.closeModal(),r(void 0))}}s.timer&&(a.timeout=setTimeout(function(){e.swal.closeModal(),r(void 0)},s.timer));var f=function(){switch(s.input){case"select":return a.querySelector("."+e.swalClasses.select);case"checkbox":return a.querySelector("#"+e.swalClasses.checkbox);case"textarea":return a.querySelector("."+e.swalClasses.textarea);default:return a.querySelector("."+e.swalClasses.input)}},C=function(){var e=f();return"checkbox"===s.input?e.checked?1:0:e.value};s.input&&setTimeout(function(){p(f())},0);var v,g=function(){if(s.input){var t=C();s.inputValidator?s.inputValidator(t).then(function(){e.swal.closeModal(),r(t)},function(t){e.swal.showValidationError(t)}):(e.swal.closeModal(),r(t))}else s.input||(e.swal.closeModal(),r(!0))},b=function(t){var l=t||e.event,n=l.target||l.srcElement,o=d(n,e.swalClasses.confirm),i=d(n,e.swalClasses.cancel),c=d(a,"visible");switch(l.type){case"mouseover":case"mouseup":case"focus":s.buttonsStyling&&(o?n.style.backgroundColor=E(s.confirmButtonColor,-.1):i&&(n.style.backgroundColor=E(s.cancelButtonColor,-.1)));break;case"mouseout":case"blur":s.buttonsStyling&&(o?n.style.backgroundColor=s.confirmButtonColor:i&&(n.style.backgroundColor=s.cancelButtonColor));break;case"mousedown":s.buttonsStyling&&(o?n.style.backgroundColor=E(s.confirmButtonColor,-.2):i&&(n.style.backgroundColor=E(s.cancelButtonColor,-.2)));break;case"click":o&&c?s.preConfirm?s.preConfirm().then(function(){g()}):g():i&&c?(e.swal.closeModal(),r(!1)):e.swal.closeModal()}},k=a.querySelectorAll("button");for(v=0;v<k.length;v++)k[v].onclick=b,k[v].onmouseover=b,k[v].onmouseout=b,k[v].onmousedown=b;l=t.onclick,t.onclick=function(t){var a=t||e.event,l=a.target||a.srcElement;(d(l,e.swalClasses.close)||l===u()&&s.allowOutsideClick)&&(e.swal.closeModal(),r(void 0))};var S=a.querySelector("button."+e.swalClasses.confirm),q=a.querySelector("button."+e.swalClasses.cancel),T=[S,q].concat(Array.prototype.slice.call(a.querySelectorAll("button:not([class^=sweet-]), input:not([type=hidden]), textarea, select")));for(v=0;v<T.length;v++)T[v].onfocus=b,T[v].onblur=b;s.reverseButtons&&S.parentNode.insertBefore(q,S),i(-1,1),n=e.onkeydown,e.onkeydown=c,s.buttonsStyling&&(S.style.borderLeftColor=s.confirmButtonColor,S.style.borderRightColor=s.confirmButtonColor),e.swal.enableLoading=function(){w(S,"loading"),w(a,"loading"),q.disabled=!0},e.swal.disableLoading=function(){m(S,"loading"),m(a,"loading"),q.disabled=!1},e.swal.enableButtons=function(){S.disabled=!1,q.disabled=!1},e.swal.disableButtons=function(){S.disabled=!0,q.disabled=!0},e.swal.showValidationError=function(t){var s=a.querySelector("."+e.swalClasses.validationError);s.innerHTML=t,y(s);var l=f();p(l),w(l,"error")},e.swal.resetValidationError=function(){var t=a.querySelector("."+e.swalClasses.validationError);h(t);var s=f();m(s,"error")},e.swal.enableButtons(),e.swal.disableLoading(),e.swal.resetValidationError(),e.onfocus=function(){e.setTimeout(function(){void 0!==o&&(o.focus(),o=void 0)},0)}})}e.swalClasses={container:"sweet-container",modal:"sweet-alert",overlay:"sweet-overlay",close:"sweet-close",content:"sweet-content",spacer:"sweet-spacer",confirm:"sweet-confirm",cancel:"sweet-cancel",icon:"sweet-icon",image:"sweet-image",input:"sweet-input",select:"sweet-select",checkbox:"sweet-checkbox",textarea:"sweet-textarea",validationError:"sweet-validation-error",iconTypes:{success:"sweet-success",warning:"sweet-warning",info:"sweet-info",question:"sweet-question",error:"sweet-error"}};var a,l,n,o,r="sweet-alert-mediaquery",i={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:{},inputValidator:null},c=function(){return t.querySelector("."+e.swalClasses.modal)},u=function(){return t.querySelector("."+e.swalClasses.overlay)},d=function(e,t){return new RegExp(" "+t+" ").test(" "+e.className+" ")},p=function(e){e.focus();var t=e.value;e.value="",e.value=t},w=function(e,t){t&&!d(e,t)&&(e.className+=" "+t)},m=function(e,t){var s=" "+e.className.replace(/[\t\r\n]/g," ")+" ";if(d(e,t)){for(;s.indexOf(" "+t+" ")>=0;)s=s.replace(" "+t+" "," ");e.className=s.replace(/^\s+|\s+$/g,"")}},f=function(e){e.style.opacity="",e.style.display="block"},y=function(e){if(e&&!e.length)return f(e);for(var t=0;t<e.length;++t)f(e[t])},C=function(e){e.style.opacity="",e.style.display="none"},h=function(e){if(e&&!e.length)return C(e);for(var t=0;t<e.length;++t)C(e[t])},v=function(e,t){e.style.removeProperty?e.style.removeProperty(t):e.style.removeAttribute(t)},g=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"},b=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()}},k=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()},x=function(t){"function"==typeof t.stopPropagation?(t.stopPropagation(),t.preventDefault()):e.event&&e.event.hasOwnProperty("cancelBubble")&&(e.event.cancelBubble=!0)},S=function(){var s=c();e.onkeydown=n,t.onclick=l,a&&a.focus(),o=void 0,clearTimeout(s.timeout);var i=t.getElementsByTagName("head")[0],u=t.getElementById(r);u&&i.removeChild(u)},E=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},q=function(s){var a=c();a.style.width=s.width+"px",a.style.padding=s.padding+"px",a.style.marginLeft=-s.width/2+"px",a.style.background=s.background;var l=t.getElementsByTagName("head")[0],n=t.createElement("style");n.type="text/css",n.id=r,n.innerHTML="@media screen and (max-width: "+s.width+"px) {."+e.swalClasses.modal+" {max-width: 100%;left: 0 !important;margin-left: 0 !important;}}",l.appendChild(n);var o=a.querySelector("h2"),i=a.querySelector("."+e.swalClasses.content),u=a.querySelector("button."+e.swalClasses.confirm),d=a.querySelector("button."+e.swalClasses.cancel),p=a.querySelector("."+e.swalClasses.spacer),g=a.querySelector("."+e.swalClasses.close);if(o.innerHTML=s.title.split("\n").join("<br>"),s.text||s.html){if("object"==typeof s.html)if(i.innerHTML="",0 in s.html)for(var b=0;b in s.html;b++)i.appendChild(s.html[b]);else i.appendChild(s.html);else i.innerHTML=s.html||"<p>"+s.text.split("\n").join("<br>")+"</p>";y(i)}else h(i);if(s.showCloseButton?y(g):h(g),a.className=e.swalClasses.modal,s.customClass&&w(a,s.customClass),h(a.querySelectorAll("."+e.swalClasses.icon)),s.type){var k=!1;for(var B in e.swalClasses.iconTypes)if(s.type===B){k=!0;break}if(!k)return e.console.error("Unknown alert type: "+s.type),!1;var x=a.querySelector("."+e.swalClasses.icon+"."+e.swalClasses.iconTypes[s.type]);switch(y(x),s.type){case"success":w(x,"animate"),w(x.querySelector(".tip"),"animate-success-tip"),w(x.querySelector(".long"),"animate-success-long");break;case"error":w(x,"animate-error-icon"),w(x.querySelector(".x-mark"),"animate-x-mark");break;case"warning":w(x,"pulse-warning")}}var S=a.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&&w(S,s.imageClass)):h(S);var E=a.querySelector("."+e.swalClasses.input),q=a.querySelector("."+e.swalClasses.select),T=a.querySelector("#"+e.swalClasses.checkbox),M=a.querySelector("."+e.swalClasses.checkbox),L=a.querySelector("."+e.swalClasses.textarea);switch(C(E),C(q),C(M),C(L),s.input){case"text":case"email":case"password":E.value=s.inputValue,E.placeholder=s.inputPlaceholder,E.type=s.input,f(E);break;case"select":if(q.innerHTML="",s.inputPlaceholder){var V=t.createElement("option");V.innerHTML=s.inputPlaceholder,V.disabled=!0,V.selected=!0,q.appendChild(V)}for(var O in s.inputOptions){var H=t.createElement("option");H.value=O,H.innerHTML=s.inputOptions[O],s.inputValue===O&&(H.selected=!0),q.appendChild(H)}f(q);break;case"checkbox":T.value=1,T.checked=Boolean(s.inputValue);var P=M.getElementsByTagName("span");P.length&&M.removeChild(P[0]),P=t.createElement("span"),P.innerHTML=s.inputPlaceholder,M.appendChild(P),f(M);break;case"textarea":L.value=s.inputValue,L.placeholder=s.inputPlaceholder,f(L);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?d.style.display="inline-block":h(d),s.showConfirmButton?v(u,"display"):h(u),s.showConfirmButton||s.showCancelButton?y(p):h(p),u.innerHTML=s.confirmButtonText,d.innerHTML=s.cancelButtonText,s.buttonsStyling&&(u.style.backgroundColor=s.confirmButtonColor,d.style.backgroundColor=s.cancelButtonColor),u.className=e.swalClasses.confirm,w(u,s.confirmButtonClass),d.className=e.swalClasses.cancel,w(d,s.cancelButtonClass),s.buttonsStyling?(w(u,"styled"),w(d,"styled")):(m(u,"styled"),m(d,"styled"),u.style.backgroundColor=u.style.borderLeftColor=u.style.borderRightColor="",d.style.backgroundColor=d.style.borderLeftColor=d.style.borderRightColor=""),s.animation===!0?m(a,"no-animation"):w(a,"no-animation")},T=function(){var e=c();b(u(),10),y(e),w(e,"show-sweet-alert"),m(e,"hide-sweet-alert"),a=t.activeElement,w(e,"visible")},M=function(){var e=c();e.style.marginTop=g(c())};e.sweetAlert=e.swal=function(){var t=arguments,a=c();return null===a&&(e.swal.init(),a=c()),d(a,"visible")&&S(),s.apply(this,t)},e.sweetAlert.close=e.swal.close=e.sweetAlert.closeModal=e.swal.closeModal=function(){var t=c();C(u()),C(t),m(t,"showSweetAlert"),w(t,"hideSweetAlert"),m(t,"visible");var s=t.querySelector("."+e.swalClasses.icon+"."+e.swalClasses.iconTypes.success);m(s,"animate"),m(s.querySelector(".tip"),"animate-success-tip"),m(s.querySelector(".long"),"animate-success-long");var a=t.querySelector("."+e.swalClasses.icon+"."+e.swalClasses.iconTypes.error);m(a,"animate-error-icon"),m(a.querySelector(".x-mark"),"animate-x-mark");var l=t.querySelector("."+e.swalClasses.icon+"."+e.swalClasses.iconTypes.warning);m(l,"pulse-warning"),S()},e.sweetAlert.clickConfirm=e.swal.clickConfirm=function(){var t=c(),s=t.querySelector("button."+e.swalClasses.confirm);s.click()},e.sweetAlert.clickCancel=e.swal.clickCancel=function(){var t=c(),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><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=c(),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(){13===event.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");k(i,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.0.1",
"version": "2.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",

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

| `background` | `"#fff"` | Modal window background (CSS `background` property). |
| `input` | `null` | Input field type, can be `text`, `email`, `password`, `select` and `checkbox`. |
| `input` | `null` | Input field type, can be `text`, `email`, `password`, `select`, `checkbox` and `textarea`. |
| `inputPlaceholder` | `""` | Input field placeholder. |

@@ -137,0 +137,0 @@ | `inputValue` | `""` | Input field initial value. |

@@ -21,2 +21,3 @@ // SweetAlert2

checkbox: 'sweet-checkbox',
textarea: 'sweet-textarea',
validationError: 'sweet-validation-error',

@@ -61,3 +62,3 @@ iconTypes: {

background: '#fff',
input: null, // 'text' | 'email' | 'password' | 'select' | 'checkbox'
input: null, // 'text' | 'email' | 'password' | 'select' | 'checkbox' | 'textarea'
inputPlaceholder: '',

@@ -397,5 +398,7 @@ inputValue: '',

var $checkboxLabel = modal.querySelector('.' + window.swalClasses.checkbox);
var $textarea = modal.querySelector('.' + window.swalClasses.textarea);
_hide($input);
_hide($select);
_hide($checkboxLabel);
_hide($textarea);
switch (params.input) {

@@ -442,6 +445,11 @@ case 'text':

break;
case 'textarea':
$textarea.value = params.inputValue;
$textarea.placeholder = params.inputPlaceholder;
_show($textarea);
break;
case null:
break;
default:
window.console.error('Unexpected type of input! Expected "text" or "email" or "password", "select" or "checkbox", got ' + typeof arguments[0]);
window.console.error('Unexpected type of input! Expected "text" or "email" or "password", "select", "checkbox" or "textarea", got ' + typeof arguments[0]);
break;

@@ -612,8 +620,12 @@ }

var getInput = function() {
if (params.input === 'select') {
return modal.querySelector('.' + window.swalClasses.select);
} else if (params.input === 'checkbox') {
return modal.querySelector('#' + window.swalClasses.checkbox);
switch (params.input) {
case 'select':
return modal.querySelector('.' + window.swalClasses.select);
case 'checkbox':
return modal.querySelector('#' + window.swalClasses.checkbox);
case 'textarea':
return modal.querySelector('.' + window.swalClasses.textarea);
default:
return modal.querySelector('.' + window.swalClasses.input);
}
return modal.querySelector('.' + window.swalClasses.input);
};

@@ -997,2 +1009,3 @@ var getInputValue = function() {

'</label>' +
'<textarea class="' + window.swalClasses.textarea + '"></textarea>' +
'<div class="' + window.swalClasses.validationError + '"></div>' +

@@ -1015,2 +1028,3 @@ '<hr class="' + window.swalClasses.spacer + '">' +

var $checkbox = modal.querySelector('#' + window.swalClasses.checkbox);
var $textarea = modal.querySelector('.' + window.swalClasses.textarea);

@@ -1034,2 +1048,6 @@ $input.oninput = function() {

};
$textarea.onchange = function() {
window.swal.resetValidationError();
};
};

@@ -1036,0 +1054,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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