Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

JitsiPopover.js 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Copyright @ 2015 Atlassian Pty Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. var JitsiPopover = (function () {
  17. /**
  18. * Constructs new JitsiPopover and attaches it to the element
  19. * @param element jquery selector
  20. * @param options the options for the popover.
  21. * @constructor
  22. */
  23. function JitsiPopover(element, options)
  24. {
  25. this.options = {
  26. skin: "white",
  27. content: ""
  28. };
  29. if(options)
  30. {
  31. if(options.skin)
  32. this.options.skin = options.skin;
  33. if(options.content)
  34. this.options.content = options.content;
  35. }
  36. this.elementIsHovered = false;
  37. this.popoverIsHovered = false;
  38. this.popoverShown = false;
  39. element.data("jitsi_popover", this);
  40. this.element = element;
  41. this.template = ' <div class="jitsipopover ' + this.options.skin +
  42. '"><div class="arrow"></div><div class="jitsipopover-content"></div>' +
  43. '<div class="jitsiPopupmenuPadding"></div></div>';
  44. var self = this;
  45. this.element.on("mouseenter", function () {
  46. self.elementIsHovered = true;
  47. self.show();
  48. }).on("mouseleave", function () {
  49. self.elementIsHovered = false;
  50. setTimeout(function () {
  51. self.hide();
  52. }, 10);
  53. });
  54. }
  55. /**
  56. * Shows the popover
  57. */
  58. JitsiPopover.prototype.show = function () {
  59. this.createPopover();
  60. this.popoverShown = true;
  61. };
  62. /**
  63. * Hides the popover
  64. */
  65. JitsiPopover.prototype.hide = function () {
  66. if(!this.elementIsHovered && !this.popoverIsHovered && this.popoverShown)
  67. {
  68. this.forceHide();
  69. }
  70. };
  71. /**
  72. * Hides the popover
  73. */
  74. JitsiPopover.prototype.forceHide = function () {
  75. $(".jitsipopover").remove();
  76. this.popoverShown = false;
  77. };
  78. /**
  79. * Creates the popover html
  80. */
  81. JitsiPopover.prototype.createPopover = function () {
  82. $("body").append(this.template);
  83. $(".jitsipopover > .jitsipopover-content").html(this.options.content);
  84. var self = this;
  85. $(".jitsipopover").on("mouseenter", function () {
  86. self.popoverIsHovered = true;
  87. }).on("mouseleave", function () {
  88. self.popoverIsHovered = false;
  89. self.hide();
  90. });
  91. this.refreshPosition();
  92. };
  93. /**
  94. * Refreshes the position of the popover
  95. */
  96. JitsiPopover.prototype.refreshPosition = function () {
  97. $(".jitsipopover").position({
  98. my: "bottom",
  99. at: "top",
  100. collision: "fit",
  101. of: this.element,
  102. using: function (position, elements) {
  103. var calcLeft = elements.target.left - elements.element.left + elements.target.width/2;
  104. $(".jitsipopover").css({top: position.top, left: position.left, display: "table"});
  105. $(".jitsipopover > .arrow").css({left: calcLeft});
  106. $(".jitsipopover > .jitsiPopupmenuPadding").css({left: calcLeft - 50});
  107. }
  108. });
  109. };
  110. /**
  111. * Updates the content of popover.
  112. * @param content new content
  113. */
  114. JitsiPopover.prototype.updateContent = function (content) {
  115. this.options.content = content;
  116. if(!this.popoverShown)
  117. return;
  118. $(".jitsipopover").remove();
  119. this.createPopover();
  120. };
  121. return JitsiPopover;
  122. })();
  123. module.exports = JitsiPopover;