Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

jitsipopover.js 3.3KB

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