您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

SidePanelToggler.js 5.0KB

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