Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

JitsiPopover.js 4.1KB

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