2015-01-23 13:09:30 +00:00
|
|
|
/**
|
2015-03-06 23:33:54 +00:00
|
|
|
* Class to handle popups.
|
2015-01-23 13:09:30 +00:00
|
|
|
**/
|
|
|
|
Htk.Popup = new Class
|
|
|
|
({
|
2015-03-06 23:33:54 +00:00
|
|
|
Extends: Htk.Widget
|
|
|
|
,Tag: 'htk-popup'
|
|
|
|
|
|
|
|
,child: null
|
|
|
|
,parent: null
|
|
|
|
|
|
|
|
,initialize: function ()
|
|
|
|
{
|
|
|
|
this.createElement ('div');
|
|
|
|
this.node.className = 'htk-popup';
|
|
|
|
}
|
|
|
|
|
|
|
|
,setChild: function (child)
|
|
|
|
{
|
|
|
|
this.setChildNode (child.getNode ());
|
|
|
|
}
|
|
|
|
|
|
|
|
,setChildNode: function (childNode)
|
|
|
|
{
|
|
|
|
Vn.Node.removeChilds (this.node);
|
|
|
|
this.node.appendChild (childNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
,show: function (parent)
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
|
|
|
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-01-23 13:09:30 +00:00
|
|
|
|
2015-03-06 23:33:54 +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-07-21 14:16:07 +00:00
|
|
|
if (!this.parent)
|
|
|
|
return;
|
|
|
|
|
2015-01-23 13:09:30 +00:00
|
|
|
var spacing = 5;
|
2015-03-06 23:33:54 +00:00
|
|
|
var rect = this.parent.getBoundingClientRect ();
|
2015-01-23 13:09:30 +00:00
|
|
|
var left = rect.left;
|
2015-03-06 23:33:54 +00:00
|
|
|
var top = rect.top + spacing + this.parent.offsetHeight;
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
var width = this.node.offsetWidth;
|
|
|
|
var height = this.node.offsetHeight;
|
|
|
|
|
2015-03-06 23:33:54 +00:00
|
|
|
if (left + width > Vn.Browser.getInnerWidth ())
|
|
|
|
left -= width - this.parent.offsetWidth;
|
|
|
|
if (top + height > Vn.Browser.getInnerHeight ())
|
|
|
|
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-01-23 13:09:30 +00:00
|
|
|
|
2015-03-06 23:33:54 +00:00
|
|
|
this.node.style.top = (top) +'px';
|
|
|
|
this.node.style.left = (left) +'px';
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
2015-07-07 15:27:47 +00:00
|
|
|
|
|
|
|
,showCenter: function ()
|
|
|
|
{
|
|
|
|
this.parent = null;
|
|
|
|
|
|
|
|
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-01-23 13:09:30 +00:00
|
|
|
|
2015-03-06 23:33:54 +00:00
|
|
|
,hide: function ()
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
2015-07-07 15:27:47 +00:00
|
|
|
if (this.background)
|
|
|
|
Vn.Node.remove (this.background);
|
|
|
|
|
2015-01-23 13:09:30 +00:00
|
|
|
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-03-06 23:33:54 +00:00
|
|
|
this.parent = null;
|
2015-01-23 13:09:30 +00:00
|
|
|
this.signalEmit ('closed');
|
|
|
|
}
|
|
|
|
|
|
|
|
,stopEvent: function (event)
|
|
|
|
{
|
|
|
|
event.stopPropagation ();
|
|
|
|
}
|
|
|
|
});
|