-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmessagebox.min.js
More file actions
12 lines (11 loc) · 8.39 KB
/
messagebox.min.js
File metadata and controls
12 lines (11 loc) · 8.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
/**
* jQuery MessageBox Plugin
* Github: http://github.com/yali4/messagebox/
* Link: http://yalcinceylan.net/messagebox
* Copyright: October 2013
* Creator: Yalçın CEYLAN
* Github: http://github.com/yali4/
* Website: http://yalcinceylan.net
* License: MIT <http://opensource.org/licenses/mit-license.php>
*/
(function(e){var t=new Array;e.fn.MessageBox=function(t,n,r,i,s){var o=e(this);o[t](function(t){if(i&&i==true){t.returnValue=false;if(t.preventDefault){t.preventDefault()}}if(s&&s==true){t.cancelBubble=true;if(t.stopPropagation){t.stopPropagation()}}if(o.blur){o.blur()}e.MessageBox(n,r,o)})};e.MessageBox=function(n,r,i){var n=e.extend({title:"Title",content:"Description",type:"information",buttons:{confirm:{title:"Continue",style:"continue"},cancel:{title:"Cancel",style:"cancel"}},style:{modal:"messagebox-background",dialog:"messagebox-dialog",content:"messagebox-content",buttons:"messagebox-buttons",timeout:"messagebox-timer"},background:"#000",opacity:"0.6",animate:{open:false,close:false,speed:false},timeout:{second:false,screen:false},usekey:false,modalclose:false},n);var s={};s.hideDialog=function(e){if(typeof e==="undefined"){s.display=false}s.removeUseKey();s.dialog.hide();s.background.hide()};s.showDialog=function(e){if(typeof e==="undefined"){s.display=true}s.addUseKey();s.dialog.show();s.background.show()};s.createDialog=function(){s.background=e("<div/>",{"class":n.style.modal,css:{background:n.background,opacity:n.opacity}});s.background.appendTo("body");s.background.show();s.display=true;if(n.modalclose){s.background.click(function(){s.response=false;s.removeDialog()})}s.dialog=e("<div/>",{"class":n.style.dialog});s.content=e("<div/>",{"class":n.style.content});s.content.appendTo(s.dialog);s.title=e("<h1/>",{"class":"title",html:n.title});s.title.appendTo(s.content);s.description=e("<div/>",{"class":"description",html:n.content});s.description.appendTo(s.content);s.buttons=e("<div/>",{"class":n.style.buttons});s.buttons.appendTo(s.dialog);var t={};if(n.type=="confirmation"||n.type=="information"){if(n.buttons.confirm.title){t.confirm=e("<button/>",{"class":n.buttons.confirm.style,html:n.buttons.confirm.title});t.confirm.appendTo(s.buttons);t.confirm.click(function(){s.response=true;s.removeDialog()})}}if(n.type=="confirmation"){if(n.buttons.cancel.title){t.cancel=e("<button/>",{"class":n.buttons.cancel.style,html:n.buttons.cancel.title});t.cancel.appendTo(s.buttons);t.cancel.click(function(){s.response=false;s.removeDialog()})}}s.dialog.appendTo("body");s.width=s.dialog.width();s.height=s.dialog.height();s.windowWidth=document.documentElement.clientWidth;s.windowHeight=document.documentElement.clientHeight;s.leftCenter=(s.windowWidth-s.width)*.5;s.topCenter=(s.windowHeight-s.height)*.5;s.bottom=s.windowHeight-s.height;s.right=s.windowWidth-s.width;if(n.animate.speed&&n.animate.open){switch(n.animate.open){case"top":s.dialog.css({opacity:0,left:s.leftCenter}).animate({opacity:1,top:s.topCenter},n.animate.speed);break;case"left":s.dialog.css({opacity:0,top:s.topCenter}).animate({opacity:1,left:s.leftCenter},n.animate.speed);break;case"right":s.dialog.css({opacity:0,top:s.topCenter,left:s.right}).animate({opacity:1,left:s.leftCenter},n.animate.speed);break;case"bottom":s.dialog.css({opacity:0,left:s.leftCenter,top:s.bottom}).animate({opacity:1,top:s.topCenter},n.animate.speed);break;case"topLeft":s.dialog.css({opacity:0,top:0,left:0}).animate({opacity:1,top:s.topCenter,left:s.leftCenter},n.animate.speed);break;case"topRight":s.dialog.css({opacity:0,top:0,left:s.right}).animate({opacity:1,top:s.topCenter,left:s.leftCenter},n.animate.speed);break;case"bottomLeft":s.dialog.css({opacity:0,top:s.bottom,left:0}).animate({opacity:1,top:s.topCenter,left:s.leftCenter},n.animate.speed);break;case"bottomRight":s.dialog.css({opacity:0,top:s.bottom,left:s.right}).animate({opacity:1,top:s.topCenter,left:s.leftCenter},n.animate.speed);break;case"topFade":s.dialog.css({opacity:0,top:s.topCenter-25,left:s.leftCenter}).animate({opacity:1,top:s.topCenter},n.animate.speed);break;case"bottomFade":s.dialog.css({opacity:0,top:s.topCenter+25,left:s.leftCenter}).animate({opacity:1,top:s.topCenter},n.animate.speed);break}}else{s.background.show();s.dialog.css({left:s.leftCenter,top:s.topCenter})}s.timeout=e("<div/>",{"class":n.style.timeout,css:{display:"none"}});s.timeout.appendTo(s.buttons)};var o=function(){s.leftCenter=(document.documentElement.clientWidth-s.dialog.width())*.5;s.topCenter=(document.documentElement.clientHeight-s.dialog.height())*.5;s.dialog.stop().animate({left:s.leftCenter,top:s.topCenter})};var u={enter:13,space:32,escape:27};var a=function(e){e=e||window.event;if(n.type=="confirmation"||n.type=="information"){if(e.keyCode==u.escape){e.returnValue=false;if(e.preventDefault){e.preventDefault()}s.response=false;s.removeDialog()}if(e.keyCode==u.enter||e.keyCode==u.space){e.returnValue=false;if(e.preventDefault){e.preventDefault()}s.response=true;s.removeDialog()}}};s.addEventListener=function(e,t,n,r){if(typeof e.addEventListener==="function"){e.addEventListener(t,n,r)}else if(e.attachEvent){e.attachEvent(t,n,r)}};s.removeEventListener=function(e,t,n,r){if(typeof e.removeEventListener==="function"){e.removeEventListener(t,n,r)}else if(e.detachEvent){e.detachEvent(t,n,r)}};s.getUniqueId=function(e){var t=[];for(var n=0;n<e;n++){t.push(Math.floor(Math.random()*10))}return t.join("")};s.addUseKey=function(){if(n.usekey){s.addEventListener(document,"keydown",a,false);s.addEventListener(document,"onkeydown",a,false)}};s.removeUseKey=function(){if(n.usekey){s.removeEventListener(document,"keydown",a,false);s.removeEventListener(document,"onkeydown",a,false)}};s.closeDialog=function(){s.dialog.remove();s.background.remove();s.removeEventListener(window,"resize",o,false);s.removeEventListener(window,"onresize",o,false);s.removeUseKey();if(typeof parseInt(n.timeout.second)=="number"&&parseInt(n.timeout.second)>0){clearInterval(s.interval)}if(typeof r==="function"){r.call(i,s.response)}delete t[s.id];var e=false;for(var u in t){e=u}if(e){if(t[e].display()){t[e].show()}}n=undefined;s=undefined};s.removeDialog=function(){if(typeof s.response==="undefined"){s.response=false}if(n.animate.speed&&n.animate.close){switch(n.animate.close){case"top":s.dialog.animate({top:"+=50"},"fast",function(){s.dialog.animate({opacity:0,top:0},n.animate.speed,function(){s.closeDialog()})});break;case"left":s.dialog.animate({left:"+=50"},"fast",function(){s.dialog.animate({opacity:0,left:0},n.animate.speed,function(){s.closeDialog()})});break;case"right":s.dialog.animate({left:"-=50"},"fast",function(){s.dialog.animate({opacity:0,left:s.right},n.animate.speed,function(){s.closeDialog()})});break;case"bottom":s.dialog.animate({top:"-=50"},"fast",function(){s.dialog.animate({opacity:0,top:s.bottom},n.animate.speed,function(){s.closeDialog()})});break;case"topLeft":s.dialog.animate({left:"+=50",top:"+=50"},"fast",function(){s.dialog.animate({opacity:0,left:0,top:0},n.animate.speed,function(){s.closeDialog()})});break;case"topRight":s.dialog.animate({left:"-=50",top:"+=50"},"fast",function(){s.dialog.animate({opacity:0,left:s.right,top:0},n.animate.speed,function(){s.closeDialog()})});break;case"bottomLeft":s.dialog.animate({left:"+=50",top:"-=50"},"fast",function(){s.dialog.animate({opacity:0,left:0,top:s.bottom},n.animate.speed,function(){s.closeDialog()})});break;case"bottomRight":s.dialog.animate({left:"-=50",top:"-=50"},"fast",function(){s.dialog.animate({opacity:0,left:s.right,top:s.bottom},n.animate.speed,function(){s.closeDialog()})});break;case"fadeOut":s.dialog.animate({opacity:0},n.animate.speed,function(){s.closeDialog()});break}}else{s.closeDialog()}};s.insertDialog=function(){for(var e in t){t[e].hide()}if(typeof s.id==="undefined"){s.id=s.getUniqueId(48)}s.createDialog();s.addEventListener(window,"resize",o,false);s.addEventListener(window,"onresize",o,false);s.addUseKey();if(typeof parseInt(n.timeout.second)=="number"&&parseInt(n.timeout.second)>0){s.remaining=parseInt(n.timeout.second);s.timeout.html(s.remaining);if(n.timeout.screen){s.timeout.css({display:"block"})}s.interval=setInterval(function(){if(s.remaining>0){s.remaining--;s.timeout.html(s.remaining)}if(s.remaining<=0){s.removeDialog()}},1e3)}t[s.id]={display:function(){return s.display},hide:function(){s.hideDialog(true)},show:function(){s.showDialog(true)}};return{title:function(e){s.title.html(e)},content:function(e){s.description.html(e)},hide:function(){s.hideDialog()},show:function(){s.showDialog()},close:function(){s.removeDialog()}}};return s.insertDialog()}})(jQuery)