您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

JitsiPopover.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* global $, APP */
  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. let popoverElem = $(".jitsipopover > .jitsipopover-content");
  73. popoverElem.html(this.options.content);
  74. APP.translation.translateElement(popoverElem);
  75. var self = this;
  76. $(".jitsipopover").on("mouseenter", function () {
  77. self.popoverIsHovered = true;
  78. }).on("mouseleave", function () {
  79. self.popoverIsHovered = false;
  80. self.hide();
  81. });
  82. this.refreshPosition();
  83. };
  84. /**
  85. * Refreshes the position of the popover.
  86. */
  87. JitsiPopover.prototype.refreshPosition = function () {
  88. $(".jitsipopover").position({
  89. my: "bottom",
  90. at: "top",
  91. collision: "fit",
  92. of: this.element,
  93. using: function (position, elements) {
  94. var calcLeft = elements.target.left - elements.element.left +
  95. elements.target.width/2;
  96. $(".jitsipopover").css(
  97. {top: position.top, left: position.left, display: "table"});
  98. $(".jitsipopover > .arrow").css({left: calcLeft});
  99. $(".jitsipopover > .jitsiPopupmenuPadding").css(
  100. {left: calcLeft - 50});
  101. }
  102. });
  103. };
  104. /**
  105. * Updates the content of popover.
  106. * @param content new content
  107. */
  108. JitsiPopover.prototype.updateContent = function (content) {
  109. this.options.content = content;
  110. if(!this.popoverShown)
  111. return;
  112. $(".jitsipopover").remove();
  113. this.createPopover();
  114. };
  115. JitsiPopover.enabled = true;
  116. return JitsiPopover;
  117. })();
  118. module.exports = JitsiPopover;