main/view/lib/infobox-es6.js

64 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

/* classe InfoBox */
export class InfoBox{
constructor(msgObject){
/* (1) get reference target */
this.target = msgObject;
/* (2) Init useful variables */
this.stack = []; // message stack
this.pending = false; // if currently waiting/showing
}
show(msg, type, timeout=2000){
/* (1) If pending -> add to stack */
if( this.pending )
this.stack.push( {message: msg, type: type, to: timeout} );
/* (2) Else -> display message */
else
this._display(msg, type, timeout);
}
_next(){
/* (1) Init */
this.target.active = false;
/* (2) Get last active message + pop stack */
var buf = this.stack.pop();
/* (3) If no more msg -> exit */
if( buf == null )
return (this.pending = false);
/* (4) Send current message */
this._display(buf.message, buf.type, buf.to);
}
_display(msg, type, timeout=2000){
/* (1) Set pending */
this.pending = true;
/* (2) Set message data */
this.target.message = msg;
this.target.type = type;
this.target.active = true;
/* (3) Timeout to next */
setTimeout(this._next.bind(this), timeout);
}
}