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 4.9KB

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