sweetalert2
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -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=B({},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<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 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<T.length;c++)if(a===T[c]){o=c;break}9===l?(n.shiftKey?r(o,-1):r(o,1),S(n)):13===l||32===l?-1===o&&k(B,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):n.querySelector("."+e.swalClasses.input)};s.input&&setTimeout(function(){p(f())},0);var C,g=function(){if(s.input){var t=f();s.inputValidator?s.inputValidator(t.value).then(function(){e.swal.closeModal(),i(t.value)},function(t){e.swal.showValidationError(t)}):(e.swal.closeModal(),i(t.value))}else s.input||(e.swal.closeModal(),i(!0))},h=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=x(s.confirmButtonColor,-.1):r&&(a.style.backgroundColor=x(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=x(s.confirmButtonColor,-.2):r&&(a.style.backgroundColor=x(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()}},b=n.querySelectorAll("button");for(C=0;C<b.length;C++)b[C].onclick=h,b[C].onmouseover=h,b[C].onmouseout=h,b[C].onmousedown=h;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 B=n.querySelector("button."+e.swalClasses.confirm),E=n.querySelector("button."+e.swalClasses.cancel),T=[B,E].concat(Array.prototype.slice.call(n.querySelectorAll("button:not([class^=sweet-]), input:not([type=hidden]), textarea, select")));for(C=0;C<T.length;C++)T[C].onfocus=h,T[C].onblur=h;s.reverseButtons&&B.parentNode.insertBefore(E,B),r(-1,1),a=e.onkeydown,e.onkeydown=c,s.buttonsStyling&&(B.style.borderLeftColor=s.confirmButtonColor,B.style.borderRightColor=s.confirmButtonColor),e.swal.enableLoading=function(){w(B,"loading"),w(n,"loading"),E.disabled=!0},e.swal.disableLoading=function(){m(B,"loading"),m(n,"loading"),E.disabled=!1},e.swal.enableButtons=function(){B.disabled=!1,E.disabled=!1},e.swal.disableButtons=function(){B.disabled=!0,E.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",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])},g=function(e,t){e.style.removeProperty?e.style.removeProperty(t):e.style.removeAttribute(t)},h=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()}},B=function(e,t){for(var s in t)t.hasOwnProperty(s)&&(e[s]=t[s]);return e},k=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()},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=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)},x=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),h=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(h):v(h),n.className=e.swalClasses.modal,s.customClass&&w(n,s.customClass),v(n.querySelectorAll("."+e.swalClasses.icon)),s.type){var B=!1;for(var k in e.swalClasses.iconTypes)if(s.type===k){B=!0;break}if(!B)return e.console.error("Unknown alert type: "+s.type),!1;var S=n.querySelector("."+e.swalClasses.icon+"."+e.swalClasses.iconTypes[s.type]);switch(y(S),s.type){case"success":w(S,"animate"),w(S.querySelector(".tip"),"animate-success-tip"),w(S.querySelector(".long"),"animate-success-long");break;case"error":w(S,"animate-error-icon"),w(S.querySelector(".x-mark"),"animate-x-mark");break;case"warning":w(S,"pulse-warning")}}var E=n.querySelector("."+e.swalClasses.image);s.imageUrl?(E.setAttribute("src",s.imageUrl),y(E),s.imageWidth&&E.setAttribute("width",s.imageWidth),s.imageHeight&&E.setAttribute("height",s.imageHeight),s.imageClass&&w(E,s.imageClass)):v(E);var x=n.querySelector("."+e.swalClasses.input),T=n.querySelector("."+e.swalClasses.select);switch(C(x),C(T),s.input){case"text":case"email":case"password":x.value=s.inputValue,x.placeholder=s.inputPlaceholder,x.type=s.input,f(x);break;case"select":if(T.innerHTML="",s.inputPlaceholder){var q=t.createElement("option");q.innerHTML=s.inputPlaceholder,q.disabled=!0,q.selected=!0,T.appendChild(q)}for(var M in s.inputOptions){var L=t.createElement("option");L.value=M,L.innerHTML=s.inputOptions[M],s.inputValue===M&&(L.selected=!0),T.appendChild(L)}f(T);break;case null:break;default:e.console.error('Unexpected type of input! Expected "text" or "email" or "password" or "select", got '+typeof arguments[0])}s.showCancelButton?d.style.display="inline-block":v(d),s.showConfirmButton?g(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=h(c())};e.sweetAlert=e.swal=function(){var t=arguments,n=c();return null===n&&(e.swal.init(),n=c()),d(n,"visible")&&E(),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"),E()},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><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+'">×</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);a.oninput=function(){e.swal.resetValidationError()},a.onkeyup=function(){13===event.keyCode&&e.swal.clickConfirm()},o.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");B(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({},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+'">×</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); |
{ | ||
"name": "sweetalert2", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"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` and `select`. | | ||
| `input` | `null` | Input field type, can be `text`, `email`, `password`, `select` and `checkbox`. | | ||
| `inputPlaceholder` | `""` | Input field placeholder. | | ||
@@ -137,0 +137,0 @@ | `inputValue` | `""` | Input field initial value. | |
@@ -20,2 +20,3 @@ // SweetAlert2 | ||
select: 'sweet-select', | ||
checkbox: 'sweet-checkbox', | ||
validationError: 'sweet-validation-error', | ||
@@ -60,3 +61,3 @@ iconTypes: { | ||
background: '#fff', | ||
input: null, // 'text' | 'email' | 'password' | 'select' | ||
input: null, // 'text' | 'email' | 'password' | 'select' | 'checkbox' | ||
inputPlaceholder: '', | ||
@@ -394,4 +395,7 @@ inputValue: '', | ||
var $select = modal.querySelector('.' + window.swalClasses.select); | ||
var $checkbox = modal.querySelector('#' + window.swalClasses.checkbox); | ||
var $checkboxLabel = modal.querySelector('.' + window.swalClasses.checkbox); | ||
_hide($input); | ||
_hide($select); | ||
_hide($checkboxLabel); | ||
switch (params.input) { | ||
@@ -426,6 +430,18 @@ case 'text': | ||
break; | ||
case 'checkbox': | ||
$checkbox.value = 1; | ||
$checkbox.checked = Boolean(params.inputValue); | ||
var label = $checkboxLabel.getElementsByTagName('span'); | ||
if (label.length) { | ||
$checkboxLabel.removeChild(label[0]); | ||
} | ||
label = document.createElement('span'); | ||
label.innerHTML = params.inputPlaceholder; | ||
$checkboxLabel.appendChild(label); | ||
_show($checkboxLabel); | ||
break; | ||
case null: | ||
break; | ||
default: | ||
window.console.error('Unexpected type of input! Expected "text" or "email" or "password" or "select", got ' + typeof arguments[0]); | ||
window.console.error('Unexpected type of input! Expected "text" or "email" or "password", "select" or "checkbox", got ' + typeof arguments[0]); | ||
break; | ||
@@ -598,5 +614,14 @@ } | ||
return modal.querySelector('.' + window.swalClasses.select); | ||
} else if (params.input === 'checkbox') { | ||
return modal.querySelector('#' + window.swalClasses.checkbox); | ||
} | ||
return modal.querySelector('.' + window.swalClasses.input); | ||
}; | ||
var getInputValue = function() { | ||
var input = getInput(); | ||
if (params.input === 'checkbox') { | ||
return input.checked ? 1 : 0; | ||
} | ||
return input.value; | ||
}; | ||
@@ -611,8 +636,8 @@ if (params.input) { | ||
if (params.input) { | ||
var $input = getInput(); | ||
var inputValue = getInputValue(); | ||
if (params.inputValidator) { | ||
params.inputValidator($input.value).then( | ||
params.inputValidator(inputValue).then( | ||
function() { | ||
window.swal.closeModal(); | ||
resolve($input.value); | ||
resolve(inputValue); | ||
}, | ||
@@ -625,3 +650,3 @@ function(error) { | ||
window.swal.closeModal(); | ||
resolve($input.value); | ||
resolve(inputValue); | ||
} | ||
@@ -634,3 +659,3 @@ } else if (params.input) { | ||
} | ||
} | ||
}; | ||
@@ -972,2 +997,5 @@ // Mouse interactions | ||
'<select class="' + window.swalClasses.select + '"></select>' + | ||
'<label for="' + window.swalClasses.checkbox + '" class="' + window.swalClasses.checkbox + '">' + | ||
'<input type="checkbox" id="' + window.swalClasses.checkbox + '">' + | ||
'</label>' + | ||
'<div class="' + window.swalClasses.validationError + '"></div>' + | ||
@@ -989,2 +1017,3 @@ '<hr class="' + window.swalClasses.spacer + '">' + | ||
var $select = modal.querySelector('.' + window.swalClasses.select); | ||
var $checkbox = modal.querySelector('#' + window.swalClasses.checkbox); | ||
@@ -1004,2 +1033,6 @@ $input.oninput = function() { | ||
}; | ||
$checkbox.onchange = function() { | ||
window.swal.resetValidationError(); | ||
}; | ||
}; | ||
@@ -1006,0 +1039,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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
275836
2249