hedera-web/web/js/htk/popup.js

107 lines
2.2 KiB
JavaScript
Raw Normal View History

/**
2015-03-06 23:33:54 +00:00
* Class to handle popups.
**/
Htk.Popup = new Class
({
2015-03-06 23:33:54 +00:00
Extends: Htk.Widget
,Tag: 'htk-popup'
2015-11-09 08:14:33 +00:00
,_parent: null
2015-03-06 23:33:54 +00:00
2015-11-09 08:14:33 +00:00
,initialize: function (props)
2015-03-06 23:33:54 +00:00
{
2015-11-09 08:14:33 +00:00
var div = this.createElement ('div');
div.className = 'htk-popup';
this.parent (props);
2015-03-06 23:33:54 +00:00
}
,setChild: function (child)
{
this.setChildNode (child.getNode ());
}
,setChildNode: function (childNode)
{
Vn.Node.removeChilds (this.node);
this.node.appendChild (childNode);
}
,show: function (parent)
{
document.body.appendChild (this.node);
this.node.addEventListener ('mousedown', this.stopEvent);
2015-03-06 23:33:54 +00:00
this.hideHandler = this.hide.bind (this);
document.addEventListener ('mousedown', this.hideHandler);
2015-11-09 08:14:33 +00:00
this._parent = parent;
2015-07-21 14:16:07 +00:00
this.reset ();
2015-03-06 23:33:54 +00:00
}
2015-07-21 14:16:07 +00:00
,reset: function ()
2015-03-06 23:33:54 +00:00
{
2015-11-09 08:14:33 +00:00
if (!this._parent)
2015-07-21 14:16:07 +00:00
return;
var spacing = 5;
2015-11-09 08:14:33 +00:00
var rect = this._parent.getBoundingClientRect ();
var left = rect.left;
2015-11-09 08:14:33 +00:00
var top = rect.top + spacing + this._parent.offsetHeight;
var width = this.node.offsetWidth;
var height = this.node.offsetHeight;
2015-03-06 23:33:54 +00:00
if (left + width > Vn.Browser.getInnerWidth ())
2015-11-09 08:14:33 +00:00
left -= width - this._parent.offsetWidth;
2015-03-06 23:33:54 +00:00
if (top + height > Vn.Browser.getInnerHeight ())
2015-11-09 08:14:33 +00:00
top -= height + this._parent.offsetHeight + spacing * 2;
2015-02-08 15:38:38 +00:00
if (left < 0)
left = 0;
if (top < 0)
top = 0;
2015-03-06 23:33:54 +00:00
this.node.style.top = (top) +'px';
this.node.style.left = (left) +'px';
}
2015-07-07 15:27:47 +00:00
,showCenter: function ()
{
2015-11-09 08:14:33 +00:00
this._parent = null;
2015-07-07 15:27:47 +00:00
this.background = document.createElement ('div');
this.background.className = 'htk-background';
document.body.appendChild (this.background);
document.body.appendChild (this.node);
var width = this.node.offsetWidth;
var height = this.node.offsetHeight;
this.node.style.top = '50%';
this.node.style.left = '50%';
this.node.style.marginLeft = (-this.node.offsetWidth / 2) +'px';
this.node.style.marginTop = (-this.node.offsetHeight / 2) +'px';
}
2015-03-06 23:33:54 +00:00
,hide: function ()
{
2015-07-07 15:27:47 +00:00
if (this.background)
Vn.Node.remove (this.background);
this.node.removeEventListener ('mousedown', this.stopEvent)
2015-03-06 23:33:54 +00:00
document.removeEventListener ('mousedown', this.hideHandler);
2015-07-07 15:27:47 +00:00
Vn.Node.remove (this.node);
2015-11-09 08:14:33 +00:00
this._parent = null;
this.signalEmit ('closed');
}
,stopEvent: function (event)
{
event.stopPropagation ();
}
});