forked from CodyWildtyto/Alert7.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alert7.min.js
9 lines (8 loc) · 4.38 KB
/
alert7.min.js
1
2
3
4
5
6
7
8
9
/*
* Alert7.js
* https://github.com/Wildtyto/Alert7.js
*
* Copyright (c) 2016 Wildtyto
* Licensed under the MIT licenses.
*/
!function(t){"use strict";function e(){return o.TYPE_DEFAULT=m,o.TYPE_CONFIRM=d,o.alert=n,o.confirm=i,o["break"]=l,a(),o}function n(){var t=r.apply(null,arguments);return t.present(),t}function i(){var t=[].splice.call(arguments,0,6);t.length<5&&(t[4]="Cancel");var e=r.apply(null,t);return e.setType(d),e.present(),e}function r(t,e){var n=new o,i=[].splice.call(arguments,2);for(n.setTitle(t),n.setMessage(e);i.length;)n.addAction(i.shift(),i.shift());return n}function l(){throw null}function a(){var t=document.createElement("style");t.innerHTML="#Alert7,#Alert7::after,#Alert7 .alert7-container {vertical-align: middle;}#Alert7 {position: fixed;top: 0;bottom: 0;left: 0;right: 0;z-index: 1001;background-color: rgba(0, 0, 0, 0.3);text-align: center;font-size: 16px;-webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none;}#Alert7.alert7-confirm {}#Alert7::after,#Alert7 .alert7-container {display: inline-block;}#Alert7::after {height: 100%;content: '';}#Alert7 .alert7-container {max-width: 240px;width: 80%;box-sizing: border-box;background-color: rgba(255, 255, 255, 0.9);border-radius: 18px;}#Alert7 .alert7-title,#Alert7 .alert7-message {padding-left: 20px;padding-right: 20px;line-height:1.3em;}#Alert7 .alert7-title {padding-top: 20px;font-size: 1.1em;font-weight: bolder;line-height: 2em;}#Alert7 .alert7-message {padding-bottom: 14px;font-size: 0.8em;}#Alert7 .alert7-actions {}#Alert7 .alert7-actions button.alert7-action-item {padding-top: 12px;padding-bottom: 12px;width: 100%;background: 0;border: 0;border-top: 1px solid #E7E7E7;outline: 0;color: #59F;}#Alert7 .alert7-actions button.alert7-action-item:last-of-type {border-bottom-left-radius: 18px;border-bottom-right-radius: 18px;}#Alert7 .alert7-actions button.alert7-action-item:active {background-color: #E7E7E7;}#Alert7.alert7-confirm .alert7-actions button.alert7-action-item {float: right;width: 50%;}#Alert7.alert7-confirm .alert7-actions button.alert7-action-item:first-of-type {border-left: 1px solid #E7E7E7;border-bottom-right-radius: 18px;}#Alert7.alert7-confirm .alert7-actions button.alert7-action-item:first-of-type:last-of-type {width: 100%;}#Alert7.alert7-confirm .alert7-actions button.alert7-action-item:nth-of-type(2) {border-bottom-left-radius: 18px;border-bottom-right-radius: 0;}#Alert7.alert7-confirm .alert7-actions button.alert7-action-item:nth-of-type(n+3) {display: none;}",document.getElementsByTagName("head")[0].appendChild(t)}function o(){this.title="",this.message="",this.type=m,this.actions=[],s(this)}function s(t){t.instanceElement=document.createElement("div"),t.instanceElement.id="Alert7",t.alertElement=document.createElement("div"),t.alertElement.className="alert7-container",t.instanceElement.appendChild(t.alertElement),t.titleElement=document.createElement("div"),t.titleElement.className="alert7-title",t.alertElement.appendChild(t.titleElement),t.messageElement=document.createElement("div"),t.messageElement.className="alert7-message",t.alertElement.appendChild(t.messageElement),t.actionsElement=document.createElement("div"),t.actionsElement.className="alert7-actions",t.alertElement.appendChild(t.actionsElement)}function c(t){function e(e){return function(){try{e&&e(),t.dismiss()}catch(n){}}}var n,i,r=t.actions,l=r.length;for(t.actionsElement.innerHTML="";l--;)i=r[l],n=document.createElement("button"),n.className="alert7-action-item",n.innerText=n.textContent=i.text||"OK",n.addEventListener("click",e(i.handler),!1),t.actionsElement.insertBefore(n,t.actionsElement.firstChild)}var m=0,d=1;!function(){t=window.Alert7=t||e()}(),o.prototype.setTitle=function(t){this.title=t||""},o.prototype.setMessage=function(t){this.message=t||""},o.prototype.setType=function(t){this.type=t||m},o.prototype.addAction=function(t,e){this.actions.push({text:t,handler:e})},o.prototype.present=function(){switch(this.titleElement.innerText=this.titleElement.textContent=this.title,this.messageElement.innerText=this.messageElement.textContent=this.message,this.type){case d:this.instanceElement.classList.add("alert7-confirm")}this.actions.length||this.actions.push({}),c(this),document.querySelector("body").appendChild(this.instanceElement)},o.prototype.dismiss=function(){this.instanceElement.parentNode&&this.instanceElement.parentNode.removeChild(this.instanceElement)}}(window.Alert7);