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

SideContainerToggler.js 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /* global $ */
  2. import UIEvents from "../../../service/UI/UIEvents";
  3. /**
  4. * Handles open and close of the extended toolbar side panel
  5. * (chat, settings, etc.).
  6. *
  7. * @type {{init, toggle, isVisible, hide, show, resize}}
  8. */
  9. const SideContainerToggler = {
  10. /**
  11. * Initialises this toggler by registering the listeners.
  12. *
  13. * @param eventEmitter
  14. */
  15. init(eventEmitter) {
  16. this.eventEmitter = eventEmitter;
  17. // We may not have a side toolbar container, for example, in
  18. // filmstrip-only mode.
  19. const sideToolbarContainer
  20. = document.getElementById("sideToolbarContainer");
  21. if (!sideToolbarContainer)
  22. return;
  23. // Adds a listener for the animationend event that would take care of
  24. // hiding all internal containers when the extendedToolbarPanel is
  25. // closed.
  26. sideToolbarContainer.addEventListener(
  27. "animationend",
  28. function(e) {
  29. if (e.animationName === "slideOutExt")
  30. $("#sideToolbarContainer").children().each(function() {
  31. if ($(this).hasClass("show"))
  32. SideContainerToggler.hideInnerContainer($(this));
  33. });
  34. },
  35. false);
  36. },
  37. /**
  38. * Toggles the container with the given element id.
  39. *
  40. * @param {String} elementId the identifier of the container element to
  41. * toggle
  42. */
  43. toggle(elementId) {
  44. let elementSelector = $(`#${elementId}`);
  45. let isSelectorVisible = elementSelector.hasClass("show");
  46. if (isSelectorVisible) {
  47. this.hide();
  48. }
  49. else {
  50. if (this.isVisible())
  51. $("#sideToolbarContainer").children().each(function() {
  52. if ($(this).id !== elementId && $(this).hasClass("show"))
  53. SideContainerToggler.hideInnerContainer($(this));
  54. });
  55. if (!this.isVisible())
  56. this.show();
  57. this.showInnerContainer(elementSelector);
  58. }
  59. },
  60. /**
  61. * Returns {true} if the side toolbar panel is currently visible,
  62. * otherwise returns {false}.
  63. */
  64. isVisible() {
  65. return $("#sideToolbarContainer").hasClass("slideInExt");
  66. },
  67. /**
  68. * Returns {true} if the side toolbar panel is currently hovered and
  69. * {false} otherwise.
  70. */
  71. isHovered() {
  72. return $("#sideToolbarContainer:hover").length > 0;
  73. },
  74. /**
  75. * Hides the side toolbar panel with a slide out animation.
  76. */
  77. hide() {
  78. $("#sideToolbarContainer")
  79. .removeClass("slideInExt").addClass("slideOutExt");
  80. },
  81. /**
  82. * Shows the side toolbar panel with a slide in animation.
  83. */
  84. show() {
  85. if (!this.isVisible())
  86. $("#sideToolbarContainer")
  87. .removeClass("slideOutExt").addClass("slideInExt");
  88. },
  89. /**
  90. * Hides the inner container given by the selector.
  91. *
  92. * @param {Object} containerSelector the jquery selector for the
  93. * element to hide
  94. */
  95. hideInnerContainer(containerSelector) {
  96. containerSelector.removeClass("show").addClass("hide");
  97. this.eventEmitter.emit(UIEvents.SIDE_TOOLBAR_CONTAINER_TOGGLED,
  98. containerSelector.attr('id'), false);
  99. },
  100. /**
  101. * Shows the inner container given by the selector.
  102. *
  103. * @param {Object} containerSelector the jquery selector for the
  104. * element to show
  105. */
  106. showInnerContainer(containerSelector) {
  107. // Before showing the container, make sure there is no other visible.
  108. // If we quickly show a container, while another one is animating
  109. // and animation never ends, so we do not really hide the first one and
  110. // we end up with to shown panels
  111. $("#sideToolbarContainer").children().each(function() {
  112. if ($(this).hasClass("show"))
  113. SideContainerToggler.hideInnerContainer($(this));
  114. });
  115. containerSelector.removeClass("hide").addClass("show");
  116. this.eventEmitter.emit(UIEvents.SIDE_TOOLBAR_CONTAINER_TOGGLED,
  117. containerSelector.attr('id'), true);
  118. },
  119. /**
  120. * TO FIX: do we need to resize the chat?
  121. */
  122. resize () {
  123. //let [width, height] = UIUtil.getSidePanelSize();
  124. //Chat.resizeChat(width, height);
  125. }
  126. };
  127. export default SideContainerToggler;