pm2-gui-fr
Version:
Une interface web et terminal élégante pour Unitech / PM2.
21 lines • 3.53 kB
JavaScript
(function(b){var a={timers:{},queue:{}};b.each([b.fn,b],function(d,e){e.extend({sticky:c})});function c(d,e){if(!d){return}
e=e||{};if(typeof d=="string"){e.body=d}else{e=d}
e=b.extend({icon:"",title:"",body:"",width:300,speed:500,position:"top-right",hideAfter:3000,closeable:true,useAnimateCss:false,animations:{"top-left":["zoomInRight","zoomOutRight"],"top-mid":["zoomInUp","zoomOutUp"],"top-right":["zoomInLeft","zoomOutLeft"],"mid-left":["zoomInRight","zoomOutRight"],"mid-mid":["zoomIn","zoomOut"],"mid-right":["zoomInLeft","zoomOutLeft"],"bottom-left":["zoomInRight","zoomOutRight"],"bottom-mid":["zoomInDown","zoomOutDown"],"bottom-right":["zoomInLeft","zoomOutLeft"]},iconClassName:"sticky-icon",bodyClassName:"sticky-body",titleClassName:"sticky-title",stickyClassName:"sticky",holderClassName:"sticky-holder"},e);if(!e.body){return}
e.animationend="webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend";e.id="sticky-"+Math.random().toString().replace(".","");var h=[["top","mid","bottom"],["left","mid","right"]],i;if(!e.position||(i=e.position.split("-")).length!=2||h[0].indexOf(i[0])<0||h[1].indexOf(i[1])<0){i=["top","right"];e.position=i.join("-")}
var d=b("body").eq(0),f;if((f=d.find(".sticky-holder.sticky-"+e.position)).length==0){f=b("<div />",{"class":"sticky-holder sticky-"+e.position}).css({width:e.width})}
a.queue[e.position]=a.queue[e.position]||[];a.queue[e.position].push(e);if(!f.is(":empty")){return}
(function g(r){var p=b("<div />",{"id":r.id,"class":r.stickyClassName}).css({width:r.width,opacity:0.01});if(r.title){b("<div />",{"class":r.titleClassName}).html(r.title).appendTo(p)}
if(r.icon){r.body='<img src="'+r.icon+'" class="'+r.iconClassName+'" />'+r.body}
b("<p />",{"class":r.bodyClassName}).html(r.body).appendTo(p);b.each(["speed","hideAfter"],function(s,t){p.data(t,r[t])});function n(u){if(u.target){u=b(u.target)}
var w=u.attr("id"),v=a.timers[w];if(v){try{clearTimeout(v)}catch(s){}
delete a.timers[w]}
function t(){var y=b(this).remove().attr("id");r.onHidden&&r.onHidden(y);var x=a.queue[r.position];if(x&&x.length>0){g(x.splice(0,1)[0])}else{f.remove()}}
if(r.useAnimateCss){u.addClass("animated "+r.animations[r.position][1]).one(r.animationend,t)}else{u.stop().dequeue().animate(p.data("anim-exit"),u.data("speed"),t)}}
if(r.closeable){p.append("<span>×</span>").one("click",">span",function(){n(b(this).parent())})}
p.appendTo(f);f.appendTo(d);var l={},j={},k={opacity:1},q=p.height()+10,m=(i[1]=="mid"?"top":i[1]);j[m]=({left:-r.width,top:-q-10,right:-r.width})[m];k[m]=0;b.extend(l,({left:{left:5},mid:{left:"50%",marginLeft:-r.width/2},right:{right:5}})[i[1]],{top:5});if(i[0]=="mid"){l.top="50%";l.marginTop=-q/2-10;if(i[1]=="mid"){j.top=0}}else{if(i[0]=="bottom"){delete l.top;l.bottom=q;if(i[1]=="mid"){j.top=q}}}
f.css(l);p.data("anim-exit",j);function o(){var s=b(this).attr("class",r.stickyClassName).attr("id");r.onShown&&r.onShown(s)}
if(!r.useAnimateCss){p.css(j).animate(k,r.speed,o)}else{p.css("opacity",1).addClass("animated "+r.animations[r.position][0]).one(r.animationend,o)}
p.on("dismiss",n);j.opacity=0.01;if(r.hideAfter){a.timers[r.id]=setTimeout(n,p.data("hideAfter"),p)}})(a.queue[e.position].splice(0,1)[0])}
c.dequeue=function(f){if(!f){for(var d in a.timers){try{clearTimeout(a.timers[d])}catch(e){}}
a.timers={};a.queue=[]}else{try{clearTimeout(a.timers[f])}catch(e){}}
f=(f?"#"+f:"div[id^=sticky-]");b(f).trigger("dismiss")}})(jQuery);