0
1
Fork 0
hedera-web-mindshore/package/usr/share/hedera-web/js/htk/toast.js

70 lines
1.3 KiB
JavaScript
Raw Normal View History

2015-03-06 23:33:54 +00:00
/**
* 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)
{
2015-03-15 12:44:57 +00:00
this.hide ();
2015-03-06 23:33:54 +00:00
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);
2015-03-15 12:44:57 +00:00
// var marginLeft = -parseInt (this.node.offsetWidth / 2);
// this.node.style.marginLeft = (marginLeft) +'px';
2015-03-06 23:33:54 +00:00
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 ()
{
2015-03-15 12:44:57 +00:00
if (this.timerId)
{
clearTimeout (this.timerId);
this.timerId = null;
document.removeEventListener ('mousedown', this.hideHandler);
document.body.removeChild (this.node);
this.signalEmit ('closed');
}
2015-03-06 23:33:54 +00:00
}
,stopEvent: function (event)
{
event.stopPropagation ();
}
});