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.

SidePanelToggler.js 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /* global require, $ */
  2. import Chat from "./chat/Chat";
  3. import ContactList from "./contactlist/ContactList";
  4. import Settings from "./../../settings/Settings";
  5. import SettingsMenu from "./settings/SettingsMenu";
  6. import VideoLayout from "../videolayout/VideoLayout";
  7. import ToolbarToggler from "../toolbars/ToolbarToggler";
  8. import UIUtil from "../util/UIUtil";
  9. const buttons = {
  10. '#chatspace': '#chatBottomButton',
  11. '#contactlist': '#contactListButton',
  12. '#settingsmenu': '#toolbar_button_settings'
  13. };
  14. var currentlyOpen = null;
  15. /**
  16. * Toggles the windows in the side panel
  17. * @param object the window that should be shown
  18. * @param selector the selector for the element containing the panel
  19. * @param onOpenComplete function to be called when the panel is opened
  20. * @param onOpen function to be called if the window is going to be opened
  21. * @param onClose function to be called if the window is going to be closed
  22. * @param onVideoResizeComplete function to be called after the video area
  23. * is resized
  24. */
  25. function toggle (object, selector, onOpenComplete,
  26. onOpen, onClose, onVideoResizeComplete) {
  27. let isSideBarVisible = object.isVisible();
  28. UIUtil.buttonClick(buttons[selector], "active");
  29. if (isSideBarVisible) {
  30. $("#toast-container").animate({
  31. right: 5
  32. }, {
  33. queue: false,
  34. duration: 500
  35. });
  36. $(selector).hide("slide", {
  37. direction: "right",
  38. queue: false,
  39. duration: 500
  40. });
  41. resizeVideoArea(isSideBarVisible, onVideoResizeComplete);
  42. if(typeof onClose === "function") {
  43. onClose();
  44. }
  45. currentlyOpen = null;
  46. } else {
  47. resizeVideoArea(isSideBarVisible, onVideoResizeComplete);
  48. // Undock the toolbar when the chat is shown and if we're in a
  49. // video mode.
  50. if (VideoLayout.isLargeVideoVisible()) {
  51. ToolbarToggler.dockToolbar(false);
  52. }
  53. if (currentlyOpen) {
  54. var current = $(currentlyOpen);
  55. UIUtil.buttonClick(buttons[currentlyOpen], "active");
  56. current.css('z-index', 4);
  57. setTimeout(function () {
  58. current.css('display', 'none');
  59. current.css('z-index', 5);
  60. }, 500);
  61. }
  62. $("#toast-container").animate({
  63. right: (UIUtil.getSidePanelSize()[0] + 5)
  64. }, {
  65. queue: false,
  66. duration: 500
  67. });
  68. $(selector).show("slide", {
  69. direction: "right",
  70. queue: false,
  71. duration: 500,
  72. complete: onOpenComplete
  73. });
  74. if(typeof onOpen === "function") {
  75. onOpen();
  76. }
  77. currentlyOpen = selector;
  78. }
  79. }
  80. function resizeVideoArea(isSidePanelVisible, completeFunction) {
  81. VideoLayout.resizeVideoArea(!isSidePanelVisible,
  82. false,
  83. true,
  84. completeFunction);
  85. }
  86. /**
  87. * Toggler for the chat, contact list, settings menu, etc..
  88. */
  89. var PanelToggler = {
  90. /**
  91. * Opens / closes the chat area.
  92. */
  93. toggleChat () {
  94. var chatCompleteFunction = Chat.isVisible()
  95. ? function () {}
  96. : function () {
  97. Chat.scrollChatToBottom();
  98. $('#chatspace').trigger('shown');
  99. };
  100. toggle(Chat, //Object
  101. '#chatspace', // Selector
  102. function () { //onOpenComplete
  103. // Request the focus in the nickname field or the chat input
  104. // field.
  105. if ($('#nickname').css('visibility') === 'visible') {
  106. $('#nickinput').focus();
  107. } else {
  108. $('#usermsg').focus();
  109. }
  110. },
  111. () => this.resizeChat(), //OnOpen
  112. null,
  113. chatCompleteFunction); //OnClose
  114. },
  115. resizeChat () {
  116. let [width, height] = UIUtil.getSidePanelSize();
  117. Chat.resizeChat(width, height);
  118. },
  119. /**
  120. * Opens / closes the contact list area.
  121. */
  122. toggleContactList () {
  123. var completeFunction = ContactList.isVisible()
  124. ? function () {}
  125. : function () {
  126. $('#contactlist').trigger('shown');
  127. };
  128. toggle(ContactList,
  129. '#contactlist',
  130. null,
  131. function() {
  132. ContactList.setVisualNotification(false);
  133. },
  134. null,
  135. completeFunction);
  136. },
  137. /**
  138. * Opens / closes the settings menu
  139. */
  140. toggleSettingsMenu () {
  141. toggle(SettingsMenu,
  142. '#settingsmenu',
  143. null,
  144. function() {
  145. $('#setDisplayName').val(Settings.getDisplayName());
  146. $('#setEmail').val(Settings.getEmail());
  147. },
  148. null);
  149. },
  150. isVisible () {
  151. return (Chat.isVisible() ||
  152. ContactList.isVisible() ||
  153. SettingsMenu.isVisible());
  154. }
  155. };
  156. export default PanelToggler;