You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

JitsiPopover.js 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* global $ */
  2. var JitsiPopover = (function () {
  3. /**
  4. * Constructs new JitsiPopover and attaches it to the element
  5. * @param element jquery selector
  6. * @param options the options for the popover.
  7. * @constructor
  8. */
  9. function JitsiPopover(element, options)
  10. {
  11. this.options = {
  12. skin: "white",
  13. content: ""
  14. };
  15. if(options)
  16. {
  17. if(options.skin)
  18. this.options.skin = options.skin;
  19. if(options.content)
  20. this.options.content = options.content;
  21. }
  22. this.elementIsHovered = false;
  23. this.popoverIsHovered = false;
  24. this.popoverShown = false;
  25. element.data("jitsi_popover", this);
  26. this.element = element;
  27. this.template = ' <div class="jitsipopover ' + this.options.skin +
  28. '"><div class="arrow"></div>' +
  29. '<div class="jitsipopover-content"></div>' +
  30. '<div class="jitsiPopupmenuPadding"></div></div>';
  31. var self = this;
  32. this.element.on("mouseenter", function () {
  33. self.elementIsHovered = true;
  34. self.show();
  35. }).on("mouseleave", function () {
  36. self.elementIsHovered = false;
  37. setTimeout(function () {
  38. self.hide();
  39. }, 10);
  40. });
  41. }
  42. /**
  43. * Shows the popover
  44. */
  45. JitsiPopover.prototype.show = function () {
  46. if(!JitsiPopover.enabled)
  47. return;
  48. this.createPopover();
  49. this.popoverShown = true;
  50. };
  51. /**
  52. * Hides the popover
  53. */
  54. JitsiPopover.prototype.hide = function () {
  55. if(!this.elementIsHovered && !this.popoverIsHovered &&
  56. this.popoverShown) {
  57. this.forceHide();
  58. }
  59. };
  60. /**
  61. * Hides the popover.
  62. */
  63. JitsiPopover.prototype.forceHide = function () {
  64. $(".jitsipopover").remove();
  65. this.popoverShown = false;
  66. };
  67. /**
  68. * Creates the popover html.
  69. */
  70. JitsiPopover.prototype.createPopover = function () {
  71. $("body").append(this.template);
  72. $(".jitsipopover > .jitsipopover-content").html(this.options.content);
  73. var self = this;
  74. $(".jitsipopover").on("mouseenter", function () {
  75. self.popoverIsHovered = true;
  76. }).on("mouseleave", function () {
  77. self.popoverIsHovered = false;
  78. self.hide();
  79. });
  80. this.refreshPosition();
  81. };
  82. /**
  83. * Refreshes the position of the popover.
  84. */
  85. JitsiPopover.prototype.refreshPosition = function () {
  86. $(".jitsipopover").position({
  87. my: "bottom",
  88. at: "top",
  89. collision: "fit",
  90. of: this.element,
  91. using: function (position, elements) {
  92. var calcLeft = elements.target.left - elements.element.left +
  93. elements.target.width/2;
  94. $(".jitsipopover").css(
  95. {top: position.top, left: position.left, display: "table"});
  96. $(".jitsipopover > .arrow").css({left: calcLeft});
  97. $(".jitsipopover > .jitsiPopupmenuPadding").css(
  98. {left: calcLeft - 50});
  99. }
  100. });
  101. };
  102. /**
  103. * Updates the content of popover.
  104. * @param content new content
  105. */
  106. JitsiPopover.prototype.updateContent = function (content) {
  107. this.options.content = content;
  108. if(!this.popoverShown)
  109. return;
  110. $(".jitsipopover").remove();
  111. this.createPopover();
  112. };
  113. JitsiPopover.enabled = true;
  114. return JitsiPopover;
  115. })();
  116. module.exports = JitsiPopover;