2015-07-28 21:52:32 +00:00
|
|
|
/* global $ */
|
2014-10-16 15:11:26 +00:00
|
|
|
var JitsiPopover = (function () {
|
|
|
|
/**
|
|
|
|
* Constructs new JitsiPopover and attaches it to the element
|
|
|
|
* @param element jquery selector
|
|
|
|
* @param options the options for the popover.
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
function JitsiPopover(element, options)
|
|
|
|
{
|
|
|
|
this.options = {
|
|
|
|
skin: "white",
|
|
|
|
content: ""
|
|
|
|
};
|
|
|
|
if(options)
|
|
|
|
{
|
|
|
|
if(options.skin)
|
|
|
|
this.options.skin = options.skin;
|
|
|
|
|
|
|
|
if(options.content)
|
|
|
|
this.options.content = options.content;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.elementIsHovered = false;
|
|
|
|
this.popoverIsHovered = false;
|
|
|
|
this.popoverShown = false;
|
|
|
|
|
|
|
|
element.data("jitsi_popover", this);
|
|
|
|
this.element = element;
|
|
|
|
this.template = ' <div class="jitsipopover ' + this.options.skin +
|
2015-09-11 02:42:15 +00:00
|
|
|
'"><div class="arrow"></div>' +
|
|
|
|
'<div class="jitsipopover-content"></div>' +
|
2014-10-16 15:11:26 +00:00
|
|
|
'<div class="jitsiPopupmenuPadding"></div></div>';
|
|
|
|
var self = this;
|
|
|
|
this.element.on("mouseenter", function () {
|
|
|
|
self.elementIsHovered = true;
|
|
|
|
self.show();
|
|
|
|
}).on("mouseleave", function () {
|
|
|
|
self.elementIsHovered = false;
|
|
|
|
setTimeout(function () {
|
|
|
|
self.hide();
|
|
|
|
}, 10);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows the popover
|
|
|
|
*/
|
|
|
|
JitsiPopover.prototype.show = function () {
|
2015-08-06 23:34:40 +00:00
|
|
|
if(!JitsiPopover.enabled)
|
|
|
|
return;
|
2014-10-16 15:11:26 +00:00
|
|
|
this.createPopover();
|
|
|
|
this.popoverShown = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hides the popover
|
|
|
|
*/
|
|
|
|
JitsiPopover.prototype.hide = function () {
|
2015-07-28 21:52:32 +00:00
|
|
|
if(!this.elementIsHovered && !this.popoverIsHovered &&
|
|
|
|
this.popoverShown) {
|
2014-10-17 13:51:23 +00:00
|
|
|
this.forceHide();
|
2014-10-16 15:11:26 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-10-17 13:51:23 +00:00
|
|
|
/**
|
2015-07-28 21:52:32 +00:00
|
|
|
* Hides the popover.
|
2014-10-17 13:51:23 +00:00
|
|
|
*/
|
|
|
|
JitsiPopover.prototype.forceHide = function () {
|
|
|
|
$(".jitsipopover").remove();
|
|
|
|
this.popoverShown = false;
|
|
|
|
};
|
|
|
|
|
2014-10-16 15:11:26 +00:00
|
|
|
/**
|
2015-07-28 21:52:32 +00:00
|
|
|
* Creates the popover html.
|
2014-10-16 15:11:26 +00:00
|
|
|
*/
|
|
|
|
JitsiPopover.prototype.createPopover = function () {
|
|
|
|
$("body").append(this.template);
|
|
|
|
$(".jitsipopover > .jitsipopover-content").html(this.options.content);
|
|
|
|
var self = this;
|
|
|
|
$(".jitsipopover").on("mouseenter", function () {
|
|
|
|
self.popoverIsHovered = true;
|
|
|
|
}).on("mouseleave", function () {
|
|
|
|
self.popoverIsHovered = false;
|
|
|
|
self.hide();
|
|
|
|
});
|
|
|
|
|
|
|
|
this.refreshPosition();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2015-07-28 21:52:32 +00:00
|
|
|
* Refreshes the position of the popover.
|
2014-10-16 15:11:26 +00:00
|
|
|
*/
|
|
|
|
JitsiPopover.prototype.refreshPosition = function () {
|
|
|
|
$(".jitsipopover").position({
|
|
|
|
my: "bottom",
|
|
|
|
at: "top",
|
|
|
|
collision: "fit",
|
|
|
|
of: this.element,
|
|
|
|
using: function (position, elements) {
|
2015-07-28 21:52:32 +00:00
|
|
|
var calcLeft = elements.target.left - elements.element.left +
|
|
|
|
elements.target.width/2;
|
|
|
|
$(".jitsipopover").css(
|
|
|
|
{top: position.top, left: position.left, display: "table"});
|
2014-10-16 15:11:26 +00:00
|
|
|
$(".jitsipopover > .arrow").css({left: calcLeft});
|
2015-07-28 21:52:32 +00:00
|
|
|
$(".jitsipopover > .jitsiPopupmenuPadding").css(
|
|
|
|
{left: calcLeft - 50});
|
2014-10-16 15:11:26 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the content of popover.
|
|
|
|
* @param content new content
|
|
|
|
*/
|
|
|
|
JitsiPopover.prototype.updateContent = function (content) {
|
|
|
|
this.options.content = content;
|
|
|
|
if(!this.popoverShown)
|
|
|
|
return;
|
|
|
|
$(".jitsipopover").remove();
|
|
|
|
this.createPopover();
|
|
|
|
};
|
|
|
|
|
2015-08-06 23:34:40 +00:00
|
|
|
JitsiPopover.enabled = true;
|
|
|
|
|
2014-10-16 15:11:26 +00:00
|
|
|
return JitsiPopover;
|
2015-01-07 14:54:03 +00:00
|
|
|
})();
|
|
|
|
|
|
|
|
module.exports = JitsiPopover;
|