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

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