Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

JitsiPopover.js 3.5KB

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