forked from verdnatura/hedera-web
52 lines
1.2 KiB
JavaScript
Executable File
52 lines
1.2 KiB
JavaScript
Executable File
/**
|
|
* 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 ())
|
|
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';
|
|
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 ();
|
|
}
|
|
});
|