forked from verdnatura/hedera-web
70 lines
1.3 KiB
JavaScript
Executable File
70 lines
1.3 KiB
JavaScript
Executable File
/**
|
|
* Class to show toast messages.
|
|
**/
|
|
Htk.Toast = new Class
|
|
({
|
|
Extends: Htk.Widget
|
|
,Tag: 'htk-toast'
|
|
|
|
,child: null
|
|
,timerId: null
|
|
|
|
,initialize: function ()
|
|
{
|
|
this.createElement ('div');
|
|
this.node.addEventListener ('mousedown', this.stopEvent);
|
|
}
|
|
|
|
,showText: function (message, className)
|
|
{
|
|
this.hide ();
|
|
|
|
var textNode = document.createTextNode (message);
|
|
|
|
Vn.Node.removeChilds (this.node);
|
|
this.node.appendChild (textNode);
|
|
this.node.className = 'htk-toast '+ className;
|
|
document.body.appendChild (this.node);
|
|
|
|
this.hideHandler = this.hide.bind (this);
|
|
document.addEventListener ('mousedown', this.hideHandler);
|
|
|
|
// var marginLeft = -parseInt (this.node.offsetWidth / 2);
|
|
// this.node.style.marginLeft = (marginLeft) +'px';
|
|
|
|
this.timerId = setTimeout (this.hide.bind (this), 10000);
|
|
}
|
|
|
|
,showMessage: function (message)
|
|
{
|
|
this.showText (message, 'message');
|
|
}
|
|
|
|
,showWarning: function (message)
|
|
{
|
|
this.showText (message, 'warning');
|
|
}
|
|
|
|
,showError: function (message)
|
|
{
|
|
this.showText (message, 'error');
|
|
}
|
|
|
|
,hide: function ()
|
|
{
|
|
if (this.timerId)
|
|
{
|
|
clearTimeout (this.timerId);
|
|
this.timerId = null;
|
|
document.removeEventListener ('mousedown', this.hideHandler);
|
|
document.body.removeChild (this.node);
|
|
this.signalEmit ('closed');
|
|
}
|
|
}
|
|
|
|
,stopEvent: function (event)
|
|
{
|
|
event.stopPropagation ();
|
|
}
|
|
});
|