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.6KB

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