sweetalert2
Advanced tools
Comparing version 2.0.3 to 2.1.0
@@ -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({},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"radio":return a.querySelector("."+e.swalClasses.radio+" input:checked")||a.querySelector("."+e.swalClasses.radio+" input:first-child");case"checkbox":return a.querySelector("#"+e.swalClasses.checkbox);case"textarea":return a.querySelector("."+e.swalClasses.textarea);default:return a.querySelector("."+e.swalClasses.input)}},C=function(){var e=f();switch(s.input){case"checkbox":return e.checked?1:0;case"radio":return e.checked?e.value:null;default:return e.value}};s.input&&setTimeout(function(){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",radio:"sweet-radio",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.radio),M=a.querySelector("#"+e.swalClasses.checkbox),L=a.querySelector("."+e.swalClasses.checkbox),V=a.querySelector("."+e.swalClasses.textarea);switch(C(E),C(q),C(T),C(L),C(V),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 O=t.createElement("option");O.innerHTML=s.inputPlaceholder,O.disabled=!0,O.selected=!0,q.appendChild(O)}for(var H in s.inputOptions){var P=t.createElement("option");P.value=H,P.innerHTML=s.inputOptions[H],s.inputValue===H&&(P.selected=!0),q.appendChild(P)}f(q);break;case"radio":T.innerHTML="";for(var A in s.inputOptions){var N=1,I=t.createElement("input"),K=t.createElement("label"),U=t.createElement("span");I.type="radio",I.name=e.swalClasses.radio,I.value=A,I.id=e.swalClasses.radio+"-"+N++,s.inputValue===A&&(I.checked=!0),U.innerHTML=s.inputOptions[A],K.appendChild(I),K.appendChild(U),K["for"]=I.id,T.appendChild(K)}f(T);break;case"checkbox":M.value=1,M.checked=Boolean(s.inputValue);var j=L.getElementsByTagName("span");j.length&&L.removeChild(j[0]),j=t.createElement("span"),j.innerHTML=s.inputPlaceholder,L.appendChild(j),f(L);break;case"textarea":V.value=s.inputValue,V.placeholder=s.inputPlaceholder,f(V);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><fieldset class="'+e.swalClasses.radio+'"></fieldset><label for="'+e.swalClasses.checkbox+'" class="'+e.swalClasses.checkbox+'"><input type="checkbox" id="'+e.swalClasses.checkbox+'"></label><textarea class="'+e.swalClasses.textarea+'"></textarea><div class="'+e.swalClasses.validationError+'"></div><hr class="'+e.swalClasses.spacer+'"><button class="'+e.swalClasses.confirm+'">OK</button><button class="'+e.swalClasses.cancel+'">Cancel</button><span class="'+e.swalClasses.close+'">×</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); | ||
!function(e,t){"use strict";function s(){if(void 0===arguments[0])return e.console.error("sweetAlert2 expects at least 1 attribute!"),!1;var s=x({},c);switch(typeof arguments[0]){case"string":s.title=arguments[0],s.text=arguments[1]||"",s.type=arguments[2]||"";break;case"object":s.title=arguments[0].title||c.title,s.text=arguments[0].text||c.text,s.html=arguments[0].html||c.html,s.type=arguments[0].type||c.type,s.animation=void 0!==arguments[0].animation?arguments[0].animation:c.animation,s.customClass=arguments[0].customClass||s.customClass,s.allowOutsideClick=void 0!==arguments[0].allowOutsideClick?arguments[0].allowOutsideClick:c.allowOutsideClick,s.allowEscapeKey=void 0!==arguments[0].allowEscapeKey?arguments[0].allowEscapeKey:c.allowEscapeKey,s.showConfirmButton=void 0!==arguments[0].showConfirmButton?arguments[0].showConfirmButton:c.showConfirmButton,s.showCancelButton=void 0!==arguments[0].showCancelButton?arguments[0].showCancelButton:c.showCancelButton,s.preConfirm=arguments[0].preConfirm||c.preConfirm,s.timer=parseInt(arguments[0].timer,10)||c.timer,s.width=parseInt(arguments[0].width,10)||c.width,s.padding=parseInt(arguments[0].padding,10)||c.padding,s.background=void 0!==arguments[0].background?arguments[0].background:c.background,s.confirmButtonText=arguments[0].confirmButtonText||c.confirmButtonText,s.confirmButtonColor=arguments[0].confirmButtonColor||c.confirmButtonColor,s.confirmButtonClass=arguments[0].confirmButtonClass||s.confirmButtonClass,s.cancelButtonText=arguments[0].cancelButtonText||c.cancelButtonText,s.cancelButtonColor=arguments[0].cancelButtonColor||c.cancelButtonColor,s.cancelButtonClass=arguments[0].cancelButtonClass||s.cancelButtonClass,s.buttonsStyling=void 0!==arguments[0].buttonsStyling?arguments[0].buttonsStyling:c.buttonsStyling,s.reverseButtons=void 0!==arguments[0].reverseButtons?arguments[0].reverseButtons:c.reverseButtons,s.showCloseButton=void 0!==arguments[0].showCloseButton?arguments[0].showCloseButton:c.showCloseButton,s.imageUrl=arguments[0].imageUrl||c.imageUrl,s.imageWidth=arguments[0].imageWidth||c.imageWidth,s.imageHeight=arguments[0].imageHeight||c.imageHeight,s.imageClass=arguments[0].imageClass||c.imageClass,s.input=arguments[0].input||c.input,s.inputPlaceholder=arguments[0].inputPlaceholder||c.inputPlaceholder,s.inputValue=arguments[0].inputValue||c.inputValue,s.inputOptions=arguments[0].inputOptions||c.inputOptions,s.inputClass=arguments[0].inputClass||c.inputClass,s.inputValidator=arguments[0].inputValidator||c.inputValidator,"email"===s.input&&null===s.inputValidator&&(s.inputValidator=function(e){return new Promise(function(t,s){var a=/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;a.test(e)?t():s("Invalid email address")})});break;default:return e.console.error('Unexpected type of argument! Expected "string" or "object", got '+typeof arguments[0]),!1}T(s),L(),M();var a=u();return new Promise(function(l){function i(e,t){for(var s=0;s<T.length;s++)if(e+=t,e===T.length?e=0:-1===e&&(e=T.length-1),T[e].offsetWidth||T[e].offsetHeight||T[e].getClientRects().length)return void T[e].focus()}function c(t){var a=t||e.event,n=a.keyCode||a.which;if(-1!==[9,13,32,27].indexOf(n)){for(var o=a.target||a.srcElement,r=-1,c=0;c<T.length;c++)if(o===T[c]){r=c;break}9===n?(a.shiftKey?i(r,-1):i(r,1),S(a)):13===n||32===n?-1===r&&B(x,a):27===n&&s.allowEscapeKey===!0&&(e.swal.closeModal(),l(void 0))}}s.timer&&(a.timeout=setTimeout(function(){e.swal.closeModal(),l(void 0)},s.timer));var u=function(){switch(s.input){case"select":return a.querySelector("."+e.swalClasses.select);case"radio":return a.querySelector("."+e.swalClasses.radio+" input:checked")||a.querySelector("."+e.swalClasses.radio+" input:first-child");case"checkbox":return a.querySelector("#"+e.swalClasses.checkbox);case"textarea":return a.querySelector("."+e.swalClasses.textarea);default:return a.querySelector("."+e.swalClasses.input)}},m=function(){var e=u();switch(s.input){case"checkbox":return e.checked?1:0;case"radio":return e.checked?e.value:null;default:return e.value}};s.input&&setTimeout(function(){w(u())},0);var v,g=function(){if(s.input){var t=m();s.inputValidator?s.inputValidator(t).then(function(){e.swal.closeModal(),l(t)},function(t){e.swal.showValidationError(t)}):(e.swal.closeModal(),l(t))}else s.input||(e.swal.closeModal(),l(!0))},b=function(t){var n=t||e.event,o=n.target||n.srcElement,r=p(o,e.swalClasses.confirm),i=p(o,e.swalClasses.cancel),c=p(a,"visible");switch(n.type){case"mouseover":case"mouseup":case"focus":s.buttonsStyling&&(r?o.style.backgroundColor=q(s.confirmButtonColor,-.1):i&&(o.style.backgroundColor=q(s.cancelButtonColor,-.1)));break;case"mouseout":case"blur":s.buttonsStyling&&(r?o.style.backgroundColor=s.confirmButtonColor:i&&(o.style.backgroundColor=s.cancelButtonColor));break;case"mousedown":s.buttonsStyling&&(r?o.style.backgroundColor=q(s.confirmButtonColor,-.2):i&&(o.style.backgroundColor=q(s.cancelButtonColor,-.2)));break;case"click":r&&c?s.preConfirm?s.preConfirm().then(function(){g()}):g():i&&c?(e.swal.closeModal(),l(!1)):e.swal.closeModal()}},k=a.querySelectorAll("button");for(v=0;v<k.length;v++)k[v].onclick=b,k[v].onmouseover=b,k[v].onmouseout=b,k[v].onmousedown=b;n=t.onclick,t.onclick=function(t){var a=t||e.event,n=a.target||a.srcElement;(p(n,e.swalClasses.close)||n===d()&&s.allowOutsideClick)&&(e.swal.closeModal(),l(void 0))};var x=a.querySelector("button."+e.swalClasses.confirm),E=a.querySelector("button."+e.swalClasses.cancel),T=[x,E].concat(Array.prototype.slice.call(a.querySelectorAll("button:not([class^="+e.swalPrefix+"]), input:not([type=hidden]), textarea, select")));for(v=0;v<T.length;v++)T[v].onfocus=b,T[v].onblur=b;s.reverseButtons&&x.parentNode.insertBefore(E,x),i(-1,1),o=e.onkeydown,e.onkeydown=c,s.buttonsStyling&&(x.style.borderLeftColor=s.confirmButtonColor,x.style.borderRightColor=s.confirmButtonColor),e.swal.enableLoading=function(){f(x,"loading"),f(a,"loading"),E.disabled=!0},e.swal.disableLoading=function(){C(x,"loading"),C(a,"loading"),E.disabled=!1},e.swal.enableButtons=function(){x.disabled=!1,E.disabled=!1},e.swal.disableButtons=function(){x.disabled=!0,E.disabled=!0},e.swal.showValidationError=function(t){var s=a.querySelector("."+e.swalClasses.validationerror);s.innerHTML=t,y(s);var l=u();w(l),f(l,"error")},e.swal.resetValidationError=function(){var t=a.querySelector("."+e.swalClasses.validationerror);h(t);var s=u();C(s,"error")},e.swal.enableButtons(),e.swal.disableLoading(),e.swal.resetValidationError(),e.onfocus=function(){e.setTimeout(function(){void 0!==r&&(r.focus(),r=void 0)},0)}})}e.swalPrefix="swal2-";var a=function(t){var s={};for(var a in t)s[t[a]]=e.swalPrefix+t[a];return s};e.swalClasses=a(["container","modal","overlay","close","content","spacer","confirm","cancel","icon","image","input","select","radio","checkbox","textarea","validationerror"]),e.swalClasses.iconTypes=a(["success","warning","info","question","error"]);var l,n,o,r,i=e.swalPrefix+"mediaquery",c={title:"",text:"",html:"",type:null,animation:!0,allowOutsideClick:!0,allowEscapeKey:!0,showConfirmButton:!0,showCancelButton:!1,preConfirm:null,confirmButtonText:"OK",confirmButtonColor:"#3085d6",confirmButtonClass:null,cancelButtonText:"Cancel",cancelButtonColor:"#aaa",cancelButtonClass:null,buttonsStyling:!0,reverseButtons:!1,showCloseButton:!1,imageUrl:null,imageWidth:null,imageHeight:null,imageClass:null,timer:null,width:500,padding:20,background:"#fff",input:null,inputPlaceholder:"",inputValue:"",inputOptions:{},inputClass:null,inputValidator:null},u=function(){return t.querySelector("."+e.swalClasses.modal)},d=function(){return t.querySelector("."+e.swalClasses.overlay)},p=function(e,t){return new RegExp(" "+t+" ").test(" "+e.className+" ")},w=function(e){e.focus();var t=e.value;e.value="",e.value=t},f=function(e,t){t&&!p(e,t)&&(e.className+=" "+t)},C=function(e,t){var s=" "+e.className.replace(/[\t\r\n]/g," ")+" ";if(p(e,t)){for(;s.indexOf(" "+t+" ")>=0;)s=s.replace(" "+t+" "," ");e.className=s.replace(/^\s+|\s+$/g,"")}},m=function(e){e.style.opacity="",e.style.display="block"},y=function(e){if(e&&!e.length)return m(e);for(var t=0;t<e.length;++t)m(e[t])},v=function(e){e.style.opacity="",e.style.display="none"},h=function(e){if(e&&!e.length)return v(e);for(var t=0;t<e.length;++t)v(e[t])},g=function(e,t){e.style.removeProperty?e.style.removeProperty(t):e.style.removeAttribute(t)},b=function(e){e.style.left="-9999px",e.style.display="block";var t=e.clientHeight,s=parseInt(getComputedStyle(e).getPropertyValue("padding-top"),10);return e.style.left="",e.style.display="none","-"+parseInt(t/2+s,10)+"px"},k=function(e,t){if(+e.style.opacity<1){t=t||16,e.style.opacity=0,e.style.display="block";var s=+new Date,a=function(){e.style.opacity=+e.style.opacity+(new Date-s)/100,s=+new Date,+e.style.opacity<1&&setTimeout(a,t)};a()}},x=function(e,t){for(var s in t)t.hasOwnProperty(s)&&(e[s]=t[s]);return e},B=function(s){if("function"==typeof MouseEvent){var a=new MouseEvent("click",{view:e,bubbles:!1,cancelable:!0});s.dispatchEvent(a)}else if(t.createEvent){var l=t.createEvent("MouseEvents");l.initEvent("click",!1,!1),s.dispatchEvent(l)}else t.createEventObject?s.fireEvent("onclick"):"function"==typeof s.onclick&&s.onclick()},S=function(t){"function"==typeof t.stopPropagation?(t.stopPropagation(),t.preventDefault()):e.event&&e.event.hasOwnProperty("cancelBubble")&&(e.event.cancelBubble=!0)},E=function(){var s=u();e.onkeydown=o,t.onclick=n,l&&l.focus(),r=void 0,clearTimeout(s.timeout);var a=t.getElementsByTagName("head")[0],c=t.getElementById(i);c&&a.removeChild(c)},q=function(e,t){e=String(e).replace(/[^0-9a-f]/gi,""),e.length<6&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),t=t||0;for(var s="#",a=0;3>a;a++){var l=parseInt(e.substr(2*a,2),16);l=Math.round(Math.min(Math.max(0,l+l*t),255)).toString(16),s+=("00"+l).substr(l.length)}return s},T=function(s){var a,l=u();l.style.width=s.width+"px",l.style.padding=s.padding+"px",l.style.marginLeft=-s.width/2+"px",l.style.background=s.background;var n=t.getElementsByTagName("head")[0],o=t.createElement("style");o.type="text/css",o.id=i,o.innerHTML="@media screen and (max-width: "+s.width+"px) {."+e.swalClasses.modal+" {max-width: 100%;left: 0 !important;margin-left: 0 !important;}}",n.appendChild(o);var r=l.querySelector("h2"),c=l.querySelector("."+e.swalClasses.content),d=l.querySelector("button."+e.swalClasses.confirm),p=l.querySelector("button."+e.swalClasses.cancel),w=l.querySelector("."+e.swalClasses.spacer),b=l.querySelector("."+e.swalClasses.close);if(r.innerHTML=s.title.split("\n").join("<br>"),s.text||s.html){if("object"==typeof s.html)if(c.innerHTML="",0 in s.html)for(a=0;a in s.html;a++)c.appendChild(s.html[a]);else c.appendChild(s.html);else c.innerHTML=s.html||"<p>"+s.text.split("\n").join("<br>")+"</p>";y(c)}else h(c);if(s.showCloseButton?y(b):h(b),l.className=e.swalClasses.modal,s.customClass&&f(l,s.customClass),h(l.querySelectorAll("."+e.swalClasses.icon)),s.type){var k=!1;for(var x in e.swalClasses.iconTypes)if(s.type===x){k=!0;break}if(!k)return e.console.error("Unknown alert type: "+s.type),!1;var B=l.querySelector("."+e.swalClasses.icon+"."+e.swalClasses.iconTypes[s.type]);switch(y(B),s.type){case"success":f(B,"animate"),f(B.querySelector(".tip"),"animate-success-tip"),f(B.querySelector(".long"),"animate-success-long");break;case"error":f(B,"animate-error-icon"),f(B.querySelector(".x-mark"),"animate-x-mark");break;case"warning":f(B,"pulse-warning")}}var S=l.querySelector("."+e.swalClasses.image);s.imageUrl?(S.setAttribute("src",s.imageUrl),y(S),s.imageWidth&&S.setAttribute("width",s.imageWidth),s.imageHeight&&S.setAttribute("height",s.imageHeight),s.imageClass&&f(S,s.imageClass)):h(S);var E,q=["input","select","radio","checkbox","textarea"];for(a=0;a<q.length;a++){var T=e.swalClasses[q[a]];E=l.querySelector("."+T),v(E),E.className=T,s.inputClass&&f(E,s.inputClass)}switch(s.input){case"text":case"email":case"password":E=l.querySelector("."+e.swalClasses.input),E.value=s.inputValue,E.placeholder=s.inputPlaceholder,E.type=s.input,m(E);break;case"select":var M=l.querySelector("."+e.swalClasses.select);if(M.innerHTML="",s.inputPlaceholder){var L=t.createElement("option");L.innerHTML=s.inputPlaceholder,L.disabled=!0,L.selected=!0,M.appendChild(L)}for(var V in s.inputOptions){var P=t.createElement("option");P.value=V,P.innerHTML=s.inputOptions[V],s.inputValue===V&&(P.selected=!0),M.appendChild(P)}m(M);break;case"radio":var O=l.querySelector("."+e.swalClasses.radio);O.innerHTML="";for(var H in s.inputOptions){var A=1,N=t.createElement("input"),I=t.createElement("label"),K=t.createElement("span");N.type="radio",N.name=e.swalClasses.radio,N.value=H,N.id=e.swalClasses.radio+"-"+A++,s.inputValue===H&&(N.checked=!0),K.innerHTML=s.inputOptions[H],I.appendChild(N),I.appendChild(K),I["for"]=N.id,O.appendChild(I)}m(O);break;case"checkbox":var U=l.querySelector("."+e.swalClasses.checkbox),j=l.querySelector("#"+e.swalClasses.checkbox);j.value=1,j.checked=Boolean(s.inputValue);var D=U.getElementsByTagName("span");D.length&&U.removeChild(D[0]),D=t.createElement("span"),D.innerHTML=s.inputPlaceholder,U.appendChild(D),m(U);break;case"textarea":var W=l.querySelector("."+e.swalClasses.textarea);W.value=s.inputValue,W.placeholder=s.inputPlaceholder,m(W);break;case null:break;default:e.console.error('Unexpected type of input! Expected "text" or "email" or "password", "select", "checkbox" or "textarea", got '+typeof arguments[0])}s.showCancelButton?p.style.display="inline-block":h(p),s.showConfirmButton?g(d,"display"):h(d),s.showConfirmButton||s.showCancelButton?y(w):h(w),d.innerHTML=s.confirmButtonText,p.innerHTML=s.cancelButtonText,s.buttonsStyling&&(d.style.backgroundColor=s.confirmButtonColor,p.style.backgroundColor=s.cancelButtonColor),d.className=e.swalClasses.confirm,f(d,s.confirmButtonClass),p.className=e.swalClasses.cancel,f(p,s.cancelButtonClass),s.buttonsStyling?(f(d,"styled"),f(p,"styled")):(C(d,"styled"),C(p,"styled"),d.style.backgroundColor=d.style.borderLeftColor=d.style.borderRightColor="",p.style.backgroundColor=p.style.borderLeftColor=p.style.borderRightColor=""),s.animation===!0?C(l,"no-animation"):f(l,"no-animation")},M=function(){var e=u();k(d(),10),y(e),f(e,"show-swal2"),C(e,"hide-swal2"),l=t.activeElement,f(e,"visible")},L=function(){var e=u();e.style.marginTop=b(u())};e.sweetAlert=e.swal=function(){var t=arguments,a=u();return null===a&&(e.swal.init(),a=u()),p(a,"visible")&&E(),s.apply(this,t)},e.sweetAlert.close=e.swal.close=e.sweetAlert.closeModal=e.swal.closeModal=function(){var t=u();v(d()),v(t),C(t,"show-swal2"),f(t,"hide-swal2"),C(t,"visible");var s=t.querySelector("."+e.swalClasses.icon+"."+e.swalClasses.iconTypes.success);C(s,"animate"),C(s.querySelector(".tip"),"animate-success-tip"),C(s.querySelector(".long"),"animate-success-long");var a=t.querySelector("."+e.swalClasses.icon+"."+e.swalClasses.iconTypes.error);C(a,"animate-error-icon"),C(a.querySelector(".x-mark"),"animate-x-mark");var l=t.querySelector("."+e.swalClasses.icon+"."+e.swalClasses.iconTypes.warning);C(l,"pulse-warning"),E()},e.sweetAlert.clickConfirm=e.swal.clickConfirm=function(){var t=u(),s=t.querySelector("button."+e.swalClasses.confirm);s.click()},e.sweetAlert.clickCancel=e.swal.clickCancel=function(){var t=u(),s=t.querySelector("button."+e.swalClasses.cancel);s.click()},e.swal.init=function(){if(!t.getElementsByClassName(e.swalClasses.container).length){var s='<div class="'+e.swalClasses.overlay+'" tabIndex="-1"></div><div class="'+e.swalClasses.modal+'" style="display: none" tabIndex="-1"><div class="'+e.swalClasses.icon+" "+e.swalClasses.iconTypes.error+'"><span class="x-mark"><span class="line left"></span><span class="line right"></span></span></div><div class="'+e.swalClasses.icon+" "+e.swalClasses.iconTypes.question+'">?</div><div class="'+e.swalClasses.icon+" "+e.swalClasses.iconTypes.warning+'">!</div><div class="'+e.swalClasses.icon+" "+e.swalClasses.iconTypes.info+'">i</div><div class="'+e.swalClasses.icon+" "+e.swalClasses.iconTypes.success+'"><span class="line tip"></span> <span class="line long"></span><div class="placeholder"></div> <div class="fix"></div></div><img class="'+e.swalClasses.image+'"><h2>Title</h2><div class="'+e.swalClasses.content+'">Text</div><input class="'+e.swalClasses.input+'"><select class="'+e.swalClasses.select+'"></select><fieldset class="'+e.swalClasses.radio+'"></fieldset><label for="'+e.swalClasses.checkbox+'" class="'+e.swalClasses.checkbox+'"><input type="checkbox" id="'+e.swalClasses.checkbox+'"></label><textarea class="'+e.swalClasses.textarea+'"></textarea><div class="'+e.swalClasses.validationerror+'"></div><hr class="'+e.swalClasses.spacer+'"><button class="'+e.swalClasses.confirm+'">OK</button><button class="'+e.swalClasses.cancel+'">Cancel</button><span class="'+e.swalClasses.close+'">×</span></div>',a=t.createElement("div");a.className=e.swalClasses.container,a.innerHTML=s,t.body.appendChild(a);var l=u(),n=l.querySelector("."+e.swalClasses.input),o=l.querySelector("."+e.swalClasses.select),r=l.querySelector("#"+e.swalClasses.checkbox),i=l.querySelector("."+e.swalClasses.textarea);n.oninput=function(){e.swal.resetValidationError()},n.onkeyup=function(){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");x(c,e)},function(){"complete"===t.readyState||"interactive"===t.readyState&&t.body?e.swal.init():t.addEventListener?t.addEventListener("DOMContentLoaded",function s(){t.removeEventListener("DOMContentLoaded",s,!1),e.swal.init()},!1):t.attachEvent&&t.attachEvent("onreadystatechange",function a(){"complete"===t.readyState&&(t.detachEvent("onreadystatechange",a),e.swal.init())})}()}(window,document); |
{ | ||
"name": "sweetalert2", | ||
"version": "2.0.3", | ||
"version": "2.1.0", | ||
"repository": "git@github.com:limonte/sweetalert2.git", | ||
@@ -5,0 +5,0 @@ "description": "A replacement for JavaScript's popup boxes, supported fork of sweetalert", |
@@ -139,2 +139,3 @@ SweetAlert2 [![Build Status](https://travis-ci.org/limonte/sweetalert2.svg?branch=master)](https://travis-ci.org/limonte/sweetalert2) | ||
| `inputValidator` | `null` | Validator for input field, should return Promise, see <a href="https://limonte.github.io/sweetalert2/#select-box">usage example</a>. | | ||
| `inputClass` | `null` | A custom CSS class for the input field. | | ||
@@ -141,0 +142,0 @@ You can redefine default params by using `swal.setDefaults(customParams)` where `customParams` is an object. |
@@ -7,29 +7,19 @@ // SweetAlert2 | ||
window.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', | ||
radio: 'sweet-radio', | ||
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' | ||
window.swalPrefix = 'swal2-'; | ||
var prefix = function(items) { | ||
var result = {}; | ||
for (var i in items) { | ||
result[items[i]] = window.swalPrefix + items[i]; | ||
} | ||
return result; | ||
}; | ||
var mediaqueryId = 'sweet-alert-mediaquery'; | ||
window.swalClasses = prefix([ | ||
'container', 'modal', 'overlay', 'close', 'content', 'spacer', 'confirm', 'cancel', 'icon', 'image', | ||
'input', 'select', 'radio', 'checkbox', 'textarea', 'validationerror' | ||
]); | ||
window.swalClasses.iconTypes = prefix(['success', 'warning', 'info', 'question', 'error']); | ||
var mediaqueryId = window.swalPrefix + 'mediaquery'; | ||
var defaultParams = { | ||
@@ -67,2 +57,3 @@ title: '', | ||
inputOptions: {}, | ||
inputClass: null, | ||
inputValidator: null | ||
@@ -271,2 +262,3 @@ }; | ||
var setParameters = function(params) { | ||
var i; | ||
var modal = getModal(); | ||
@@ -310,3 +302,3 @@ | ||
if (0 in params.html) { | ||
for (var i = 0; i in params.html; i++) { | ||
for (i = 0; i in params.html; i++) { | ||
$content.appendChild(params.html[i]); | ||
@@ -397,13 +389,13 @@ } | ||
// input, select | ||
var $input = modal.querySelector('.' + window.swalClasses.input); | ||
var $select = modal.querySelector('.' + window.swalClasses.select); | ||
var $radio = modal.querySelector('.' + window.swalClasses.radio); | ||
var $checkbox = modal.querySelector('#' + window.swalClasses.checkbox); | ||
var $checkboxLabel = modal.querySelector('.' + window.swalClasses.checkbox); | ||
var $textarea = modal.querySelector('.' + window.swalClasses.textarea); | ||
_hide($input); | ||
_hide($select); | ||
_hide($radio); | ||
_hide($checkboxLabel); | ||
_hide($textarea); | ||
var inputTypes = ['input', 'select', 'radio', 'checkbox', 'textarea']; | ||
var input; | ||
for (i = 0; i < inputTypes.length; i++) { | ||
var inputClass = window.swalClasses[inputTypes[i]]; | ||
input = modal.querySelector('.' + inputClass); | ||
_hide(input); | ||
input.className = inputClass; | ||
if (params.inputClass) { | ||
addClass(input, params.inputClass); | ||
} | ||
} | ||
switch (params.input) { | ||
@@ -413,9 +405,11 @@ case 'text': | ||
case 'password': | ||
$input.value = params.inputValue; | ||
$input.placeholder = params.inputPlaceholder; | ||
$input.type = params.input; | ||
_show($input); | ||
input = modal.querySelector('.' + window.swalClasses.input); | ||
input.value = params.inputValue; | ||
input.placeholder = params.inputPlaceholder; | ||
input.type = params.input; | ||
_show(input); | ||
break; | ||
case 'select': | ||
$select.innerHTML = ''; | ||
var select = modal.querySelector('.' + window.swalClasses.select); | ||
select.innerHTML = ''; | ||
if (params.inputPlaceholder) { | ||
@@ -426,3 +420,3 @@ var placeholder = document.createElement('option'); | ||
placeholder.selected = true; | ||
$select.appendChild(placeholder); | ||
select.appendChild(placeholder); | ||
} | ||
@@ -436,8 +430,9 @@ for (var optionValue in params.inputOptions) { | ||
} | ||
$select.appendChild(option); | ||
select.appendChild(option); | ||
} | ||
_show($select); | ||
_show(select); | ||
break; | ||
case 'radio': | ||
$radio.innerHTML = ''; | ||
var radio = modal.querySelector('.' + window.swalClasses.radio); | ||
radio.innerHTML = ''; | ||
for (var radioValue in params.inputOptions) { | ||
@@ -459,22 +454,25 @@ var id = 1; | ||
radioLabel.for = radioInput.id; | ||
$radio.appendChild(radioLabel); | ||
radio.appendChild(radioLabel); | ||
} | ||
_show($radio); | ||
_show(radio); | ||
break; | ||
case 'checkbox': | ||
$checkbox.value = 1; | ||
$checkbox.checked = Boolean(params.inputValue); | ||
var label = $checkboxLabel.getElementsByTagName('span'); | ||
var checkbox = modal.querySelector('.' + window.swalClasses.checkbox); | ||
var checkboxInput = modal.querySelector('#' + window.swalClasses.checkbox); | ||
checkboxInput.value = 1; | ||
checkboxInput.checked = Boolean(params.inputValue); | ||
var label = checkbox.getElementsByTagName('span'); | ||
if (label.length) { | ||
$checkboxLabel.removeChild(label[0]); | ||
checkbox.removeChild(label[0]); | ||
} | ||
label = document.createElement('span'); | ||
label.innerHTML = params.inputPlaceholder; | ||
$checkboxLabel.appendChild(label); | ||
_show($checkboxLabel); | ||
checkbox.appendChild(label); | ||
_show(checkbox); | ||
break; | ||
case 'textarea': | ||
$textarea.value = params.inputValue; | ||
$textarea.placeholder = params.inputPlaceholder; | ||
_show($textarea); | ||
var textarea = modal.querySelector('.' + window.swalClasses.textarea); | ||
textarea.value = params.inputValue; | ||
textarea.placeholder = params.inputPlaceholder; | ||
_show(textarea); | ||
break; | ||
@@ -552,4 +550,4 @@ case null: | ||
show(modal); | ||
addClass(modal, 'show-sweet-alert'); | ||
removeClass(modal, 'hide-sweet-alert'); | ||
addClass(modal, 'show-swal2'); | ||
removeClass(modal, 'hide-swal2'); | ||
@@ -573,3 +571,3 @@ previousActiveElement = document.activeElement; | ||
if (arguments[0] === undefined) { | ||
window.console.error('sweetAlert expects at least 1 attribute!'); | ||
window.console.error('sweetAlert2 expects at least 1 attribute!'); | ||
return false; | ||
@@ -624,4 +622,18 @@ } | ||
params.inputOptions = arguments[0].inputOptions || defaultParams.inputOptions; | ||
params.inputClass = arguments[0].inputClass || defaultParams.inputClass; | ||
params.inputValidator = arguments[0].inputValidator || defaultParams.inputValidator; | ||
if (params.input === 'email' && params.inputValidator === null) { | ||
params.inputValidator = function(email) { | ||
return new Promise(function(resolve, reject) { | ||
var emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/; | ||
if (emailRegex.test(email)) { | ||
resolve(); | ||
} else { | ||
reject('Invalid email address'); | ||
} | ||
}); | ||
}; | ||
} | ||
break; | ||
@@ -801,3 +813,3 @@ | ||
var $modalElements = [$confirmButton, $cancelButton].concat(Array.prototype.slice.call( | ||
modal.querySelectorAll('button:not([class^=sweet-]), input:not([type=hidden]), textarea, select') | ||
modal.querySelectorAll('button:not([class^=' + window.swalPrefix + ']), input:not([type=hidden]), textarea, select') | ||
)); | ||
@@ -919,3 +931,3 @@ for (i = 0; i < $modalElements.length; i++) { | ||
window.swal.showValidationError = function(error) { | ||
var $validationError = modal.querySelector('.' + window.swalClasses.validationError); | ||
var $validationError = modal.querySelector('.' + window.swalClasses.validationerror); | ||
$validationError.innerHTML = error; | ||
@@ -930,3 +942,3 @@ show($validationError); | ||
window.swal.resetValidationError = function() { | ||
var $validationError = modal.querySelector('.' + window.swalClasses.validationError); | ||
var $validationError = modal.querySelector('.' + window.swalClasses.validationerror); | ||
hide($validationError); | ||
@@ -983,4 +995,4 @@ | ||
_hide(modal); | ||
removeClass(modal, 'showSweetAlert'); | ||
addClass(modal, 'hideSweetAlert'); | ||
removeClass(modal, 'show-swal2'); | ||
addClass(modal, 'hide-swal2'); | ||
removeClass(modal, 'visible'); | ||
@@ -1054,3 +1066,3 @@ | ||
'<textarea class="' + window.swalClasses.textarea + '"></textarea>' + | ||
'<div class="' + window.swalClasses.validationError + '"></div>' + | ||
'<div class="' + window.swalClasses.validationerror + '"></div>' + | ||
'<hr class="' + window.swalClasses.spacer + '">' + | ||
@@ -1057,0 +1069,0 @@ '<button class="' + window.swalClasses.confirm + '">OK</button>' + |
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
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
287458
2324
187