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

52 lines
1.2 KiB
JavaScript
Raw Normal View History

/**
* Interface for use a widget as a popup.
**/
Htk.Popup = new Class
({
showPopup: function (parent)
{
document.body.appendChild (this.node);
this.node.addEventListener ('mousedown', this.stopEvent);
this.hidePopupHandler = this.hidePopup.bind (this);
document.addEventListener ('mousedown', this.hidePopupHandler);
var spacing = 5;
var rect = parent.getBoundingClientRect ();
var left = rect.left;
var top = rect.top + spacing + parent.offsetHeight;
var width = this.node.offsetWidth;
var height = this.node.offsetHeight;
if (left + width > getInnerWidth ())
left -= width - parent.offsetWidth;
if (top + height > getInnerHeight ())
2015-02-08 15:38:38 +00:00
top -= height + parent.offsetHeight + spacing * 2;
if (left < 0)
left = 0;
if (top < 0)
top = 0;
this.node.style.top = (top) + 'px';
this.node.style.left = (left) + 'px';
this.node.style.position = 'fixed';
2015-02-08 15:38:38 +00:00
this.node.style.zIndex = 100;
}
,hidePopup: function ()
{
this.node.removeEventListener ('mousedown', this.stopEvent)
document.removeEventListener ('mousedown', this.hidePopupHandler);
document.body.removeChild (this.node);
this.signalEmit ('closed');
}
,stopEvent: function (event)
{
event.stopPropagation ();
}
});