NxTIC/js/lib/notif-min.js

5 lines
1.3 KiB
JavaScript
Raw Normal View History

var NotificationClass=function(a){this.container=a};NotificationClass.prototype={container:this.container,stack:[],types:["warning","info","success","error"],defaultTimeout:2E3};NotificationClass.prototype.pushStack=function(a,d,e){if(!(a instanceof Array&&e instanceof Array))return null;var c=-1,b;for(b in a)if(-1<e.indexOf(a[b])){c=b;break}if(-1==c)return a.push(d)-1;a[c]=d;return c};
NotificationClass.prototype.hide=function(a){if(isNaN(a))return!1;a=parseInt(a);this.container.removeChild(this.stack[a].element);this.stack[a]=null};
NotificationClass.prototype.show=function(a,d,e,c){a=-1<this.types.indexOf(a)?a:this.types[0];d="string"==typeof d?d:"";e="string"==typeof e?e:"...";c="number"==typeof c?c:this.defaultTimeout;var b={element:document.createElement("div"),type:a,title:d,message:e,timeout:null};b.element.className="notification-element";b.element.innerHTML='<p><strong class="'+a+'">'+d+":</strong> "+e+"<p>";this.container.appendChild(b.element);var f=this.pushStack(this.stack,b,[null]);b.element.id=f;var g=this;b.element.className=
"notification-element notification-visible";setTimeout(function(){b.element.className="notification-element"},500+c);b.timeout=setTimeout(function(){g.hide(f)},500+c+500);b.element.addEventListener("click",function(a){g.hide(f)},!1)};