You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SideContainerToggler.js 5.0KB

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