1 line
9.5 KiB
JavaScript
1 line
9.5 KiB
JavaScript
|
!function(e,t){function n(){var e='<div class="sweet-overlay" tabIndex="-1"></div><div class="sweet-alert" tabIndex="-1"><div class="icon error"><span class="x-mark"><span class="line left"></span><span class="line right"></span></span></div><div class="icon warning"> <span class="body"></span> <span class="dot"></span> </div> <div class="icon info"></div> <div class="icon success"> <span class="line tip"></span> <span class="line long"></span> <div class="placeholder"></div> <div class="fix"></div> </div> <div class="icon custom"></div> <h2>Title</h2><p>Text</p><button class="cancel" tabIndex="2">Cancel</button><button class="confirm" tabIndex="1">OK</button></div>',n=t.createElement("div");n.innerHTML=e,t.body.appendChild(n)}function o(t){var n=m(),o=n.querySelector("h2"),r=n.querySelector("p"),a=n.querySelector("button.cancel"),c=n.querySelector("button.confirm");if(o.innerHTML=b(t.title).split("\n").join("<br>"),r.innerHTML=b(t.text||"").split("\n").join("<br>"),t.text&&w(r),x(n.querySelectorAll(".icon")),t.type){for(var l=!1,s=0;s<d.length;s++)if(t.type===d[s]){l=!0;break}if(!l)return e.console.error("Unknown alert type: "+t.type),!1;var u=n.querySelector(".icon."+t.type);switch(w(u),t.type){case"success":p(u,"animate"),p(u.querySelector(".tip"),"animateSuccessTip"),p(u.querySelector(".long"),"animateSuccessLong");break;case"error":p(u,"animateErrorIcon"),p(u.querySelector(".x-mark"),"animateXMark");break;case"warning":p(u,"pulseWarning"),p(u.querySelector(".body"),"pulseWarningIns"),p(u.querySelector(".dot"),"pulseWarningIns")}}if(t.imageUrl){var f=n.querySelector(".icon.custom");f.style.backgroundImage="url("+t.imageUrl+")",w(f);var g=80,y=80;if(t.imageSize){var v=t.imageSize.split("x")[0],h=t.imageSize.split("x")[1];v&&h?(g=v,y=h,f.css({width:v+"px",height:h+"px"})):e.console.error("Parameter imageSize expects value with format WIDTHxHEIGHT, got "+t.imageSize)}f.setAttribute("style",f.getAttribute("style")+"width:"+g+"px; height:"+y+"px")}n.setAttribute("data-has-cancel-button",t.showCancelButton),t.showCancelButton?a.style.display="inline-block":x(a),t.cancelButtonText&&(a.innerHTML=b(t.cancelButtonText)),t.confirmButtonText&&(c.innerHTML=b(t.confirmButtonText)),c.style.backgroundColor=t.confirmButtonColor,i(c,t.confirmButtonColor),n.setAttribute("data-allow-ouside-click",t.allowOutsideClick);var S=t.doneFunction?!0:!1;n.setAttribute("data-has-done-function",S)}function r(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;var n="#",o,r;for(r=0;3>r;r++)o=parseInt(e.substr(2*r,2),16),o=Math.round(Math.min(Math.max(0,o+o*t),255)).toString(16),n+=("00"+o).substr(o.length);return n}function a(e){var t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);return t?parseInt(t[1],16)+", "+parseInt(t[2],16)+", "+parseInt(t[3],16):null}function i(e,t){var n=a(t);e.style.boxShadow="0 0 2px rgba("+n+", 0.8), inset 0 0 0 1px rgba(0, 0, 0, 0.05)"}function c(){var e=m();B(g(),10),w(e),p(e,"showSweetAlert"),v(e,"hideSweetAlert"),O=t.activeElement;var n=e.querySelector("button.confirm");n.focus(),setTimeout(function(){p(e,"visible")},500)}function l(){var n=m();T(g(),5),T(n,5),v(n,"showSweetAlert"),p(n,"hideSweetAlert"),v(n,"visible");var o=n.querySelector(".icon.success");v(o,"animate"),v(o.querySelector(".tip"),"animateSuccessTip"),v(o.querySelector(".long"),"animateSuccessLong");var r=n.querySelector(".icon.error");v(r,"animateErrorIcon"),v(r.querySelector(".x-mark"),"animateXMark");var a=n.querySelector(".icon.warning");v(a,"pulseWarning"),v(a.querySelector(".body"),"pulseWarningIns"),v(a.querySelector(".dot"),"pulseWarningIns"),e.onkeydown=A,t.onclick=I,O&&O.focus(),M=void 0}function s(){var e=m();e.style.marginTop=k(m())}var u=".sweet-alert",f=".sweet-overlay",d=["error","warning","info","success"],m=function(){return t.querySelector(u)},g=function(){return t.querySelector(f)},y=function(e,t){return new RegExp(" "+t+" ").test(" "+e.className+" ")},p=function(e,t){y(e,t)||(e.className+=" "+t)},v=function(e,t){var n=" "+e.className.replace(/[\t\r\n]/g," ")+" ";if(y(e,t)){for(;n.ind
|