-
Notifications
You must be signed in to change notification settings - Fork 0
/
alert.min.js
9 lines (9 loc) · 4.15 KB
/
alert.min.js
1
2
3
4
5
6
7
8
9
function Alert(a){a.tagName?(this.alertTitleText=a.getAttribute("data-alert-title")||"",this.alertContentText=a.getAttribute("data-alert-content")||"",this.alertAfterFunction=a.getAttribute("data-alert-after-function")||"",this.alertButton=a.getAttribute("data-alert-button")||"yes",this.alertOkName=a.getAttribute("data-alert-ok-name")||"OK",this.alertOkFunction=a.getAttribute("data-alert-ok-function")||"",this.alertCancel=a.getAttribute("data-alert-cancel")||"no",this.alertCancelName=a.getAttribute("data-alert-cancel-name")||
"Cancel",this.alertCancelFunction=a.getAttribute("data-alert-cancel-function")||"",this.alertType=a.getAttribute("data-alert-type")||""):(this.alertTitleText=a.alertTitleText||"",this.alertContentText=a.alertContentText||"",this.alertAfterFunction=a.alertAfterFunction||"",this.alertButton=a.alertButton||"yes",this.alertOkName=a.alertOkName||"OK",this.alertOkFunction=a.alertOkFunction||"",this.alertCancel=a.alertCancel||"no",this.alertCancelName=a.alertCancelName||"Cancel",this.alertCancelFunction=
a.alertCancelFunction||"",this.alertType=a.alertType||"");this.showAlert()}
Alert.prototype.createAlert=function(){console.log();this.idNum=(new Date).getMilliseconds();var a=this;this.alertOverlay=document.createElement("div");this.alertOverlay.setAttribute("class","alertOverlay");this.alertOverlay.setAttribute("id","alertOverlayId"+this.idNum);this.alertBlock=document.createElement("div");this.alertBlock.setAttribute("class","alertBlock");this.alertBlock.setAttribute("id","alertBlockId"+this.idNum);this.alertTitle=document.createElement("div");this.alertTitle.setAttribute("class",
"alertTitle");this.alertTitle.innerHTML=this.alertTitleText;this.alertBlock.appendChild(this.alertTitle);this.alertContent=document.createElement("div");this.alertContent.innerHTML=this.alertContentText;this.alertBlock.appendChild(this.alertContent);""!=this.alertType?(this.alertContent.setAttribute("class","alertContent alertContentType"),this.alertTypeBlock=document.createElement("div"),this.alertTypeBlock.setAttribute("class","alertType alert_"+this.alertType),this.alertContent.appendChild(this.alertTypeBlock)):
this.alertContent.setAttribute("class","alertContent");this.alertClose=document.createElement("div");this.alertClose.setAttribute("class","alertClose alertCloseButton");this.alertClose.setAttribute("id","alertCloseId"+this.idNum);this.alertClose.addEventListener("click",function(){a.hideAlert(a.alertAfterFunction)});this.alertBlock.appendChild(this.alertClose);"yes"===this.alertButton&&(this.alertButtons=document.createElement("div"),this.alertButtons.setAttribute("class","alertButtons"),this.alertBlock.appendChild(this.alertButtons),
this.alertOkButton=document.createElement("div"),this.alertOkButton.setAttribute("class","button alertOk"),this.alertOkButton.setAttribute("id","alertOkId"+this.idNum),this.alertOkButton.innerHTML=this.alertOkName,this.alertOkButton.addEventListener("click",function(){a.hideAlert(a.alertOkFunction)}),this.alertButtons.appendChild(this.alertOkButton),"no"!==this.alertCancel&&(this.alertCancelButton=document.createElement("div"),this.alertCancelButton.setAttribute("class","button alertCansel"),this.alertCancelButton.setAttribute("id",
"alertCloseId"+this.idNum),this.alertCancelButton.innerHTML=this.alertCancelName,this.alertCancelButton.addEventListener("click",function(){a.hideAlert(a.alertCancelFunction)}),this.alertButtons.appendChild(this.alertCancelButton)));document.body.appendChild(this.alertOverlay);document.body.appendChild(this.alertBlock);this.enterKey(this)};Alert.prototype.showAlert=function(){this.createAlert();this.alertOverlay.classList.add("showAlert");this.alertBlock.classList.add("showAlert")};
Alert.prototype.hideAlert=function(a){this.alertOverlay.classList.remove("showAlert");this.alertBlock.classList.remove("showAlert");this.alertOverlay.parentNode.removeChild(this.alertOverlay);this.alertBlock.parentNode.removeChild(this.alertBlock);(new Function("",a))()};Alert.prototype.enterKey=function(a){document.addEventListener("keydown",function(b){b=b||window.event;document.getElementById(a.alertBlock.getAttribute("id"))&&(13===b.keyCode&&a.hideAlert(a.alertOkFunction),27===b.keyCode&&a.hideAlert(a.alertAfterFunction))})};