-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtoast.min.js
1 lines (1 loc) · 2.64 KB
/
toast.min.js
1
var Toast=function(){return{DEFAULT_CLASS:"toast-item",DURATION_LONG:4e3,DURATION_NORMAL:2e3,DURATION_SHORT:1e3,POSITION_TOP:"top",POSITION_BOTTOM:"bottom",POSITION_MIDDLE:"middle",ALIGN_CENTER:"center",ALIGN_LEFT:"left",ALIGN_RIGHT:"right",QUEUE:new Array,TIMEOUT:null,TIMEOUT_HIDE:null,show:function(t){var o={position:Toast.POSITION_BOTTOM,duration:Toast.DURATION_NORMAL,align:Toast.ALIGN_CENTER,"class":Toast.DEFAULT_CLASS,background:"#000000",color:"#ffffff",opacity:"0.6",radius:"16",fontSize:"14px",appearTime:.3,message:"",top:"40px",left:"40px"};"string"==typeof t?o.message=t:t&&$.extend(o,t);var a=!1;return $(Toast.QUEUE).each(function(t,e){return e.message==o.message?(a=!0,!1):void 0}),a?!1:(Toast.QUEUE.push(o),void(Toast.QUEUE.length>1||Toast.processQueue(Toast.QUEUE[0])))},processQueue:function(t){var o=$("."+Toast.DEFAULT_CLASS);o.length>0&&o.remove();var a=Toast.DEFAULT_CLASS+(""!=t["class"]?" "+t["class"]:""),e="position:absolute; display:block; text-align:center; height: auto; overflow: hidden; padding:10px 18px 10px 18px; opacity:0; z-index:100000;";e+="border-radius: "+t.radius+"px; -webkit-border-radius: "+t.radius+"px; -ms-border-radius: "+t.radius+"px; -o-border-radius:"+t.radius+"px; -moz-border-radius: "+t.radius+"px;",e+="-webkit-transition: opacity "+t.appearTime+"s; -o-transition: opacity "+t.appearTime+"s; transition: opacity "+t.appearTime+"s; -moz-transition: opacity "+t.appearTime+"s; -ms-transition: opacity "+t.appearTime+"s;",e+="background: "+t.background+"; color: "+t.color+"; font-size:"+t.fontSize+";",$("body").append('<div style="'+e+'" class="'+a+'">'+t.message+"</div>"),setTimeout(function(){switch(o=$("."+t["class"]),t.position){case Toast.POSITION_TOP:o.css("top",t.top);break;case Toast.POSITION_MIDDLE:o.css("top",($(window).height()-o.outerHeight(!0))/2);break;default:o.css("bottom",t.top)}switch(t.align){case Toast.ALIGN_LEFT:o.css("left",t.left);break;case Toast.ALIGN_RIGHT:o.css("right",t.left);break;default:o.css("left",($(window).width()-o.outerWidth(!0))/2)}o.css("opacity",t.opacity)},50),Toast.TIMEOUT=setTimeout(function(){return o=$("."+Toast.DEFAULT_CLASS),Toast.QUEUE.length<=0?void o.remove():(Toast.QUEUE.splice(0,1),o.css("opacity",0),void(Toast.TIMEOUT_HIDE=setTimeout(function(){return o=$("."+Toast.DEFAULT_CLASS),o.remove(),Toast.QUEUE.length<=0?void clearTimeout(Toast.TIMEOUT_HIDE):void Toast.processQueue(Toast.QUEUE[0])},1e3*t.appearTime)))},t.duration)},clear:function(){var t=$("."+Toast.DEFAULT_CLASS);t.remove(),Toast.QUEUE=new Array,null!=Toast.TIMEOUT&&clearTimeout(Toast.TIMEOUT),null!=Toast.TIMEOUT_HIDE&&clearTimeout(Toast.TIMEOUT_HIDE)}}}();