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

JitsiPopover.js 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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><div class="jitsipopover-content"></div>' +
  29. '<div class="jitsiPopupmenuPadding"></div></div>';
  30. var self = this;
  31. this.element.on("mouseenter", function () {
  32. self.elementIsHovered = true;
  33. self.show();
  34. }).on("mouseleave", function () {
  35. self.elementIsHovered = false;
  36. setTimeout(function () {
  37. self.hide();
  38. }, 10);
  39. });
  40. }
  41. /**
  42. * Shows the popover
  43. */
  44. JitsiPopover.prototype.show = function () {
  45. if(!JitsiPopover.enabled)
  46. return;
  47. this.createPopover();
  48. this.popoverShown = true;
  49. };
  50. /**
  51. * Hides the popover
  52. */
  53. JitsiPopover.prototype.hide = function () {
  54. if(!this.elementIsHovered && !this.popoverIsHovered &&
  55. this.popoverShown) {
  56. this.forceHide();
  57. }
  58. };
  59. /**
  60. * Hides the popover.
  61. */
  62. JitsiPopover.prototype.forceHide = function () {
  63. $(".jitsipopover").remove();
  64. this.popoverShown = false;
  65. };
  66. /**
  67. * Creates the popover html.
  68. */
  69. JitsiPopover.prototype.createPopover = function () {
  70. $("body").append(this.template);
  71. $(".jitsipopover > .jitsipopover-content").html(this.options.content);
  72. var self = this;
  73. $(".jitsipopover").on("mouseenter", function () {
  74. self.popoverIsHovered = true;
  75. }).on("mouseleave", function () {
  76. self.popoverIsHovered = false;
  77. self.hide();
  78. });
  79. this.refreshPosition();
  80. };
  81. /**
  82. * Refreshes the position of the popover.
  83. */
  84. JitsiPopover.prototype.refreshPosition = function () {
  85. $(".jitsipopover").position({
  86. my: "bottom",
  87. at: "top",
  88. collision: "fit",
  89. of: this.element,
  90. using: function (position, elements) {
  91. var calcLeft = elements.target.left - elements.element.left +
  92. elements.target.width/2;
  93. $(".jitsipopover").css(
  94. {top: position.top, left: position.left, display: "table"});
  95. $(".jitsipopover > .arrow").css({left: calcLeft});
  96. $(".jitsipopover > .jitsiPopupmenuPadding").css(
  97. {left: calcLeft - 50});
  98. }
  99. });
  100. };
  101. /**
  102. * Updates the content of popover.
  103. * @param content new content
  104. */
  105. JitsiPopover.prototype.updateContent = function (content) {
  106. this.options.content = content;
  107. if(!this.popoverShown)
  108. return;
  109. $(".jitsipopover").remove();
  110. this.createPopover();
  111. };
  112. JitsiPopover.enabled = true;
  113. return JitsiPopover;
  114. })();
  115. module.exports = JitsiPopover;