NxTIC/js/lib/notif-min.js

5 lines
1.0 KiB
JavaScript

var NotificationClass=function(a){this.container=a};NotificationClass.prototype={container:this.container,stack:[],types:["warning","info","success","error"]};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:400;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.timeout=setTimeout(function(){g.hide(f)},
c)};