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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. // Set the size to 0 at the end of the animation to ensure that
  41. // the is(":visible") function on this selector will return {false}
  42. // when the element is hidden.
  43. complete: function() {$(selector).css("width", "0");}
  44. });
  45. resizeVideoArea(false, onVideoResizeComplete);
  46. if(typeof onClose === "function") {
  47. onClose();
  48. }
  49. currentlyOpen = null;
  50. } else {
  51. resizeVideoArea(true, onVideoResizeComplete);
  52. // Undock the toolbar when the chat is shown and if we're in a
  53. // video mode.
  54. if (VideoLayout.isLargeVideoVisible()) {
  55. ToolbarToggler.dockToolbar(false);
  56. }
  57. if (currentlyOpen) {
  58. var current = $(currentlyOpen);
  59. UIUtil.buttonClick(buttons[currentlyOpen], "active");
  60. current.css('z-index', 4);
  61. setTimeout(function () {
  62. current.css('display', 'none');
  63. current.css('z-index', 5);
  64. }, 500);
  65. }
  66. $("#toast-container").animate({
  67. right: (UIUtil.getSidePanelSize()[0] + 5)
  68. }, {
  69. queue: false,
  70. duration: 500
  71. });
  72. // Set the size dynamically (not in the css), so that we're sure that
  73. // when is(":visible") is called on this selector the result is {false}
  74. // before it's actually visible.
  75. // (Chrome seems to return {true} for an element which is in the DOM and
  76. // has non-null size set).
  77. $(selector).css("width", "20%");
  78. $(selector).show("slide", {
  79. direction: "right",
  80. queue: false,
  81. duration: 500,
  82. complete: onOpenComplete
  83. });
  84. if(typeof onOpen === "function") {
  85. onOpen();
  86. }
  87. currentlyOpen = selector;
  88. }
  89. }
  90. function resizeVideoArea(isSidePanelVisible, completeFunction) {
  91. VideoLayout.resizeVideoArea(isSidePanelVisible,
  92. false,//don't force thumbnail count update
  93. true, //animate
  94. completeFunction);
  95. }
  96. /**
  97. * Toggler for the chat, contact list, settings menu, etc..
  98. */
  99. var PanelToggler = {
  100. /**
  101. * Opens / closes the chat area.
  102. */
  103. toggleChat () {
  104. var chatCompleteFunction = Chat.isVisible()
  105. ? function () {}
  106. : function () {
  107. Chat.scrollChatToBottom();
  108. $('#chatspace').trigger('shown');
  109. };
  110. toggle(Chat, //Object
  111. '#chatspace', // Selector
  112. function () { //onOpenComplete
  113. // Request the focus in the nickname field or the chat input
  114. // field.
  115. if ($('#nickname').css('visibility') === 'visible') {
  116. $('#nickinput').focus();
  117. } else {
  118. $('#usermsg').focus();
  119. }
  120. },
  121. () => this.resizeChat(), //OnOpen
  122. null,
  123. chatCompleteFunction); //OnClose
  124. },
  125. resizeChat () {
  126. let [width, height] = UIUtil.getSidePanelSize();
  127. Chat.resizeChat(width, height);
  128. },
  129. /**
  130. * Opens / closes the contact list area.
  131. */
  132. toggleContactList () {
  133. var completeFunction = ContactList.isVisible()
  134. ? function () {}
  135. : function () {
  136. $('#contactlist').trigger('shown');
  137. };
  138. toggle(ContactList,
  139. '#contactlist',
  140. null,
  141. function() {
  142. ContactList.setVisualNotification(false);
  143. },
  144. null,
  145. completeFunction);
  146. },
  147. /**
  148. * Opens / closes the settings menu
  149. */
  150. toggleSettingsMenu () {
  151. toggle(SettingsMenu,
  152. '#settingsmenu',
  153. null,
  154. function() {},
  155. null);
  156. },
  157. isVisible () {
  158. return (Chat.isVisible() ||
  159. ContactList.isVisible() ||
  160. SettingsMenu.isVisible());
  161. }
  162. };
  163. export default PanelToggler;