sweetalert2
Advanced tools
Comparing version 1.3.4 to 1.4.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=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.closeOnConfirm=void 0!==arguments[0].closeOnConfirm?arguments[0].closeOnConfirm:r.closeOnConfirm,s.closeOnCancel=void 0!==arguments[0].closeOnCancel?arguments[0].closeOnCancel:r.closeOnCancel,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;break;default:return e.console.error('Unexpected type of argument! Expected "string" or "object", got '+typeof arguments[0]),!1}T(s),q(),E();var n=c();return new Promise(function(i){function r(e,t){for(var s=0;s<v.length;s++)if(e+=t,e===v.length?e=0:-1===e&&(e=v.length-1),v[e].offsetWidth||v[e].offsetHeight||v[e].getClientRects().length)return void v[e].focus()}function c(t){var n=t||e.event,o=n.keyCode||n.which;if(-1!==[9,13,32,27].indexOf(o)){for(var l=n.target||n.srcElement,a=-1,c=0;c<v.length;c++)if(l===v[c]){a=c;break}9===o?(n.shiftKey?r(a,-1):r(a,1),k(n)):13===o||32===o?-1===a&&B(p,n):27===o&&s.allowEscapeKey===!0&&(e.swal.closeModal(),i(void 0))}}s.timer&&(n.timeout=setTimeout(function(){e.swal.closeModal(),i(void 0)},s.timer));var y,f=function(t){var o=t||e.event,l=o.target||o.srcElement,a=d(l,e.swalClasses.confirm),r=d(l,e.swalClasses.cancel),c=d(n,"visible");switch(o.type){case"mouseover":case"mouseup":case"focus":s.buttonsStyling&&(a?l.style.backgroundColor=x(s.confirmButtonColor,-.1):r&&(l.style.backgroundColor=x(s.cancelButtonColor,-.1)));break;case"mouseout":case"blur":s.buttonsStyling&&(a?l.style.backgroundColor=s.confirmButtonColor:r&&(l.style.backgroundColor=s.cancelButtonColor));break;case"mousedown":s.buttonsStyling&&(a?l.style.backgroundColor=x(s.confirmButtonColor,-.2):r&&(l.style.backgroundColor=x(s.cancelButtonColor,-.2)));break;case"click":a&&c?(s.closeOnConfirm&&e.swal.closeModal(),i(!0)):r&&c?(s.closeOnCancel&&e.swal.closeModal(),i(!1)):e.swal.closeModal()}},C=n.querySelectorAll("button");for(y=0;y<C.length;y++)C[y].onclick=f,C[y].onmouseover=f,C[y].onmouseout=f,C[y].onmousedown=f;o=t.onclick,t.onclick=function(t){var n=t||e.event,o=n.target||n.srcElement;(d(o,e.swalClasses.close)||o===u()&&s.allowOutsideClick)&&(e.swal.closeModal(),i(void 0))};var p=n.querySelector("button."+e.swalClasses.confirm),g=n.querySelector("button."+e.swalClasses.cancel),v=[p,g].concat(Array.prototype.slice.call(n.querySelectorAll("button:not([class^=sweet-]), input:not([type=hidden]), textarea, select")));for(y=0;y<v.length;y++)v[y].onfocus=f,v[y].onblur=f;s.reverseButtons&&p.parentNode.insertBefore(g,p),r(-1,1),l=e.onkeydown,e.onkeydown=c,s.buttonsStyling&&(p.style.borderLeftColor=s.confirmButtonColor,p.style.borderRightColor=s.confirmButtonColor),e.swal.enableLoading=function(){m(p,"loading"),m(n,"loading"),g.disabled=!0},e.swal.disableLoading=function(){w(p,"loading"),w(n,"loading"),g.disabled=!1},e.swal.enableButtons=function(){p.disabled=!1,g.disabled=!1},e.swal.disableButtons=function(){p.disabled=!0,g.disabled=!0},e.swal.enableButtons(),e.swal.disableLoading(),e.onfocus=function(){e.setTimeout(function(){void 0!==a&&(a.focus(),a=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",iconTypes:{success:"sweet-success",warning:"sweet-warning",info:"sweet-info",question:"sweet-question",error:"sweet-error"}};var n,o,l,a,i="sweet-alert-mediaquery",r={title:"",text:"",html:"",type:null,animation:!0,allowOutsideClick:!0,allowEscapeKey:!0,showConfirmButton:!0,showCancelButton:!1,closeOnConfirm:!0,closeOnCancel:!0,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"},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+" ")},m=function(e,t){t&&!d(e,t)&&(e.className+=" "+t)},w=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,"")}},y=function(e){e.style.opacity="",e.style.display="block"},f=function(e){if(e&&!e.length)return y(e);for(var t=0;t<e.length;++t)y(e[t])},C=function(e){e.style.opacity="",e.style.display="none"},p=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)},v=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"},h=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},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 o=t.createEvent("MouseEvents");o.initEvent("click",!1,!1),s.dispatchEvent(o)}else t.createEventObject?s.fireEvent("onclick"):"function"==typeof s.onclick&&s.onclick()},k=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=l,t.onclick=o,n&&n.focus(),a=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 o=parseInt(e.substr(2*n,2),16);o=Math.round(Math.min(Math.max(0,o+o*t),255)).toString(16),s+=("00"+o).substr(o.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 o=t.getElementsByTagName("head")[0],l=t.createElement("style");l.type="text/css",l.id=i,l.innerHTML="@media screen and (max-width: "+s.width+"px) {."+e.swalClasses.modal+" {max-width: 100%;left: 0 !important;margin-left: 0 !important;}}",o.appendChild(l);var a=n.querySelector("h2"),r=n.querySelector("."+e.swalClasses.content),u=n.querySelector("button."+e.swalClasses.confirm),d=n.querySelector("button."+e.swalClasses.cancel),y=n.querySelector("."+e.swalClasses.spacer),C=n.querySelector("."+e.swalClasses.close);if(a.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 v=0;v in s.html;v++)r.appendChild(s.html[v]);else r.appendChild(s.html);else r.innerHTML=s.html||"<p>"+s.text.split("\n").join("<br>")+"</p>";f(r)}else p(r);if(s.showCloseButton?f(C):p(C),n.className=e.swalClasses.modal,s.customClass&&m(n,s.customClass),p(n.querySelectorAll("."+e.swalClasses.icon)),s.type){var h=!1;for(var b in e.swalClasses.iconTypes)if(s.type===b){h=!0;break}if(!h)return e.console.error("Unknown alert type: "+s.type),!1;var B=n.querySelector("."+e.swalClasses.icon+"."+e.swalClasses.iconTypes[s.type]);switch(f(B),s.type){case"success":m(B,"animate"),m(B.querySelector(".tip"),"animate-success-tip"),m(B.querySelector(".long"),"animate-success-long");break;case"error":m(B,"animate-error-icon"),m(B.querySelector(".x-mark"),"animate-x-mark");break;case"warning":m(B,"pulse-warning")}}var k=n.querySelector("."+e.swalClasses.image);s.imageUrl?(k.setAttribute("src",s.imageUrl),f(k),s.imageWidth&&k.setAttribute("width",s.imageWidth),s.imageHeight&&k.setAttribute("height",s.imageHeight),s.imageClass&&m(k,s.imageClass)):p(k),s.showCancelButton?d.style.display="inline-block":p(d),s.showConfirmButton?g(u,"display"):p(u),s.showConfirmButton||s.showCancelButton?f(y):p(y),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,m(u,s.confirmButtonClass),d.className=e.swalClasses.cancel,m(d,s.cancelButtonClass),s.buttonsStyling?(m(u,"styled"),m(d,"styled")):(w(u,"styled"),w(d,"styled"),u.style.backgroundColor=u.style.borderLeftColor=u.style.borderRightColor="",d.style.backgroundColor=d.style.borderLeftColor=d.style.borderRightColor=""),s.animation===!0?w(n,"no-animation"):m(n,"no-animation")},E=function(){var e=c();h(u(),10),f(e),m(e,"show-sweet-alert"),w(e,"hide-sweet-alert"),n=t.activeElement,m(e,"visible")},q=function(){var e=c();e.style.marginTop=v(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),w(t,"showSweetAlert"),m(t,"hideSweetAlert"),w(t,"visible");var s=t.querySelector("."+e.swalClasses.icon+"."+e.swalClasses.iconTypes.success);w(s,"animate"),w(s.querySelector(".tip"),"animate-success-tip"),w(s.querySelector(".long"),"animate-success-long");var n=t.querySelector("."+e.swalClasses.icon+"."+e.swalClasses.iconTypes.error);w(n,"animate-error-icon"),w(n.querySelector(".x-mark"),"animate-x-mark");var o=t.querySelector("."+e.swalClasses.icon+"."+e.swalClasses.iconTypes.warning);w(o,"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><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)}},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=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.closeOnConfirm=void 0!==arguments[0].closeOnConfirm?arguments[0].closeOnConfirm:r.closeOnConfirm,s.closeOnCancel=void 0!==arguments[0].closeOnCancel?arguments[0].closeOnCancel:r.closeOnCancel,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),O(),q();var n=c();return new Promise(function(i){function r(e,t){for(var s=0;s<E.length;s++)if(e+=t,e===E.length?e=0:-1===e&&(e=E.length-1),E[e].offsetWidth||E[e].offsetHeight||E[e].getClientRects().length)return void E[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<E.length;c++)if(a===E[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(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":if(o&&c){if(s.closeOnConfirm)if(s.input){var u=f();s.inputValidator?s.inputValidator(u.value).then(function(){e.swal.closeModal(),i(u.value)},function(t){e.swal.showValidationError(t)}):(e.swal.closeModal(),i(u.value))}else s.input||(e.swal.closeModal(),i(!0))}else r&&c?s.closeOnCancel&&(e.swal.closeModal(),i(!1)):e.swal.closeModal()}},h=n.querySelectorAll("button");for(C=0;C<h.length;C++)h[C].onclick=g,h[C].onmouseover=g,h[C].onmouseout=g,h[C].onmousedown=g;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),B=n.querySelector("button."+e.swalClasses.cancel),E=[b,B].concat(Array.prototype.slice.call(n.querySelectorAll("button:not([class^=sweet-]), input:not([type=hidden]), textarea, select")));for(C=0;C<E.length;C++)E[C].onfocus=g,E[C].onblur=g;s.reverseButtons&&b.parentNode.insertBefore(B,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"),B.disabled=!0},e.swal.disableLoading=function(){m(b,"loading"),m(n,"loading"),B.disabled=!1},e.swal.enableButtons=function(){b.disabled=!1,B.disabled=!1},e.swal.disableButtons=function(){b.disabled=!0,B.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,closeOnConfirm:!0,closeOnCancel:!0,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 O in s.inputOptions){var M=t.createElement("option");M.value=O,M.innerHTML=s.inputOptions[O],s.inputValue===O&&(M.selected=!0),T.appendChild(M)}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")},O=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()},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); |
{ | ||
"name": "sweetalert2", | ||
"version": "1.3.4", | ||
"version": "1.4.0", | ||
"repository": "git@github.com:limonte/sweetalert2.git", | ||
@@ -5,0 +5,0 @@ "description": "A replacement for JavaScript's popup boxes, supported fork of sweetalert", |
@@ -134,2 +134,7 @@ 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`. | | ||
| `inputPlaceholder` | `""` | Input field placeholder. | | ||
| `inputValue` | `""` | Input field initial value. | | ||
| `inputOptions` | `{}` | If `input` parameter is set to `select`, you can provide options. Object keys will represent options values, object values will represent options text values. | | ||
| `inputValidator` | `null` | Validator for input field, should return Promise, see <a href="https://limonte.github.io/sweetalert2/#select-box">usage example</a>. | | ||
@@ -152,2 +157,4 @@ You can redefine default params by using `swal.setDefaults(customParams)` where `customParams` is an object. | ||
| `swal.clickCancel()` | Click "Cancel"-button programmatically. | | ||
| `swal.showValidationError(error)` | Show validation error message. | | ||
| `swal.resetValidationError()` | Hide validation error message. | | ||
@@ -154,0 +161,0 @@ |
@@ -18,2 +18,5 @@ // SweetAlert2 | ||
image: 'sweet-image', | ||
input: 'sweet-input', | ||
select: 'sweet-select', | ||
validationError: 'sweet-validation-error', | ||
iconTypes: { | ||
@@ -57,3 +60,8 @@ success: 'sweet-success', | ||
padding: 20, | ||
background: '#fff' | ||
background: '#fff', | ||
input: null, // 'text' | 'email' | 'password' | 'select' | ||
inputPlaceholder: '', | ||
inputValue: '', | ||
inputOptions: {}, | ||
inputValidator: null | ||
}; | ||
@@ -76,2 +84,11 @@ | ||
var focusInput = function(input) { | ||
input.focus(); | ||
// http://stackoverflow.com/a/2345915/1331425 | ||
var val = input.value; | ||
input.value = ''; | ||
input.value = val; | ||
}; | ||
var addClass = function(elem, className) { | ||
@@ -376,2 +393,43 @@ if (className && !hasClass(elem, className)) { | ||
// input, select | ||
var $input = modal.querySelector('.' + window.swalClasses.input); | ||
var $select = modal.querySelector('.' + window.swalClasses.select); | ||
_hide($input); | ||
_hide($select); | ||
switch (params.input) { | ||
case 'text': | ||
case 'email': | ||
case 'password': | ||
$input.value = params.inputValue; | ||
$input.placeholder = params.inputPlaceholder; | ||
$input.type = params.input; | ||
_show($input); | ||
break; | ||
case 'select': | ||
$select.innerHTML = ''; | ||
if (params.inputPlaceholder) { | ||
var placeholder = document.createElement('option'); | ||
placeholder.innerHTML = params.inputPlaceholder; | ||
placeholder.disabled = true; | ||
placeholder.selected = true; | ||
$select.appendChild(placeholder); | ||
} | ||
for (var optionValue in params.inputOptions) { | ||
var option = document.createElement('option'); | ||
option.value = optionValue; | ||
option.innerHTML = params.inputOptions[optionValue]; | ||
if (params.inputValue === optionValue) { | ||
option.selected = true; | ||
} | ||
$select.appendChild(option); | ||
} | ||
_show($select); | ||
break; | ||
case null: | ||
break; | ||
default: | ||
window.console.error('Unexpected type of input! Expected "text" or "email" or "password" or "select", got ' + typeof arguments[0]); | ||
break; | ||
} | ||
// Cancel button | ||
@@ -508,2 +566,8 @@ if (params.showCancelButton) { | ||
params.input = arguments[0].input || defaultParams.input; | ||
params.inputPlaceholder = arguments[0].inputPlaceholder || defaultParams.inputPlaceholder; | ||
params.inputValue = arguments[0].inputValue || defaultParams.inputValue; | ||
params.inputOptions = arguments[0].inputOptions || defaultParams.inputOptions; | ||
params.inputValidator = arguments[0].inputValidator || defaultParams.inputValidator; | ||
break; | ||
@@ -533,2 +597,16 @@ | ||
// input/select autofocus | ||
var getInput = function() { | ||
if (params.input === 'select') { | ||
return modal.querySelector('.' + window.swalClasses.select); | ||
} | ||
return modal.querySelector('.' + window.swalClasses.input); | ||
}; | ||
if (params.input) { | ||
setTimeout(function() { | ||
focusInput(getInput()); | ||
}, 0); | ||
} | ||
// Mouse interactions | ||
@@ -578,7 +656,26 @@ var onButtonEvent = function(event) { | ||
if (params.closeOnConfirm) { | ||
window.swal.closeModal(); | ||
if (params.input) { | ||
var $input = getInput(); | ||
if (params.inputValidator) { | ||
params.inputValidator($input.value).then( | ||
function() { | ||
window.swal.closeModal(); | ||
resolve($input.value); | ||
}, | ||
function(error) { | ||
window.swal.showValidationError(error); | ||
} | ||
); | ||
} else { | ||
window.swal.closeModal(); | ||
resolve($input.value); | ||
} | ||
} else if (params.input) { | ||
} else { | ||
window.swal.closeModal(); | ||
resolve(true); | ||
} | ||
} | ||
resolve(true); | ||
// Clicked 'cancel' | ||
@@ -589,6 +686,5 @@ } else if (targetedCancel && modalIsVisible) { | ||
window.swal.closeModal(); | ||
resolve(false); | ||
} | ||
resolve(false); | ||
} else { | ||
@@ -744,4 +840,23 @@ window.swal.closeModal(); | ||
window.swal.showValidationError = function(error) { | ||
var $validationError = modal.querySelector('.' + window.swalClasses.validationError); | ||
$validationError.innerHTML = error; | ||
show($validationError); | ||
var input = getInput(); | ||
focusInput(input); | ||
addClass(input, 'error'); | ||
}; | ||
window.swal.resetValidationError = function() { | ||
var $validationError = modal.querySelector('.' + window.swalClasses.validationError); | ||
hide($validationError); | ||
var input = getInput(); | ||
removeClass(input, 'error'); | ||
}; | ||
window.swal.enableButtons(); | ||
window.swal.disableLoading(); | ||
window.swal.resetValidationError(); | ||
@@ -852,2 +967,5 @@ window.onfocus = function() { | ||
'<div class="' + window.swalClasses.content + '">Text</div>' + | ||
'<input class="' + window.swalClasses.input + '">' + | ||
'<select class="' + window.swalClasses.select + '"></select>' + | ||
'<div class="' + window.swalClasses.validationError + '"></div>' + | ||
'<hr class="' + window.swalClasses.spacer + '">' + | ||
@@ -864,2 +982,14 @@ '<button class="' + window.swalClasses.confirm + '">OK</button>' + | ||
document.body.appendChild(sweetWrap); | ||
var modal = getModal(); | ||
var $input = modal.querySelector('.' + window.swalClasses.input); | ||
var $select = modal.querySelector('.' + window.swalClasses.select); | ||
$input.oninput = function() { | ||
window.swal.resetValidationError(); | ||
}; | ||
$select.onchange = function() { | ||
window.swal.resetValidationError(); | ||
}; | ||
}; | ||
@@ -866,0 +996,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
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
271869
2204
186