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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. // Adds a listener for the animation end event that would take care
  18. // of hiding all internal containers when the extendedToolbarPanel is
  19. // closed.
  20. document.getElementById("sideToolbarContainer")
  21. .addEventListener("animationend", function(e) {
  22. if(e.animationName === "slideOutExt")
  23. $("#sideToolbarContainer").children().each(function() {
  24. if ($(this).hasClass("show"))
  25. SideContainerToggler.hideInnerContainer($(this));
  26. });
  27. }, false);
  28. },
  29. /**
  30. * Toggles the container with the given element id.
  31. *
  32. * @param {String} elementId the identifier of the container element to
  33. * toggle
  34. */
  35. toggle(elementId) {
  36. let elementSelector = $(`#${elementId}`);
  37. let isSelectorVisible = elementSelector.hasClass("show");
  38. if (isSelectorVisible) {
  39. this.hide();
  40. }
  41. else {
  42. if (this.isVisible())
  43. $("#sideToolbarContainer").children().each(function() {
  44. if ($(this).id !== elementId && $(this).hasClass("show"))
  45. SideContainerToggler.hideInnerContainer($(this));
  46. });
  47. if (!this.isVisible())
  48. this.show();
  49. this.showInnerContainer(elementSelector);
  50. }
  51. },
  52. /**
  53. * Returns {true} if the extended toolbar panel is currently visible,
  54. * otherwise returns {false}.
  55. */
  56. isVisible() {
  57. return $("#sideToolbarContainer").hasClass("slideInExt");
  58. },
  59. /**
  60. * Hides the extended toolbar panel with a slide out animation.
  61. */
  62. hide() {
  63. $("#sideToolbarContainer")
  64. .removeClass("slideInExt").addClass("slideOutExt");
  65. },
  66. /**
  67. * Shows the extended toolbar panel with a slide in animation.
  68. */
  69. show() {
  70. if (!this.isVisible())
  71. $("#sideToolbarContainer")
  72. .removeClass("slideOutExt").addClass("slideInExt");
  73. },
  74. hideInnerContainer(containerSelector) {
  75. containerSelector.removeClass("show").addClass("hide");
  76. this.eventEmitter.emit(UIEvents.SIDE_TOOLBAR_CONTAINER_TOGGLED,
  77. containerSelector.attr('id'), false);
  78. },
  79. showInnerContainer(containerSelector) {
  80. containerSelector.removeClass("hide").addClass("show");
  81. this.eventEmitter.emit(UIEvents.SIDE_TOOLBAR_CONTAINER_TOGGLED,
  82. containerSelector.attr('id'), true);
  83. },
  84. /**
  85. * TO FIX: do we need to resize the chat?
  86. */
  87. resize () {
  88. //let [width, height] = UIUtil.getSidePanelSize();
  89. //Chat.resizeChat(width, height);
  90. }
  91. };
  92. export default SideContainerToggler;