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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. var Chat = require("./chat/Chat");
  2. var ContactList = require("./contactlist/ContactList");
  3. var Settings = require("./../../settings/Settings");
  4. var SettingsMenu = require("./settings/SettingsMenu");
  5. var VideoLayout = require("../videolayout/VideoLayout");
  6. var ToolbarToggler = require("../toolbars/ToolbarToggler");
  7. var UIUtil = require("../util/UIUtil");
  8. /**
  9. * Toggler for the chat, contact list, settings menu, etc..
  10. */
  11. var PanelToggler = (function(my) {
  12. var currentlyOpen = null;
  13. var buttons = {
  14. '#chatspace': '#chatBottomButton',
  15. '#contactlist': '#contactListButton',
  16. '#settingsmenu': '#settingsButton'
  17. };
  18. /**
  19. * Resizes the video area
  20. * @param isClosing whether the side panel is going to be closed or is going to open / remain opened
  21. * @param completeFunction a function to be called when the video space is resized
  22. */
  23. var resizeVideoArea = function(isClosing, completeFunction) {
  24. var videospace = $('#videospace');
  25. var panelSize = isClosing ? [0, 0] : PanelToggler.getPanelSize();
  26. var videospaceWidth = window.innerWidth - panelSize[0];
  27. var videospaceHeight = window.innerHeight;
  28. var videoSize
  29. = VideoLayout.getVideoSize(null, null, videospaceWidth, videospaceHeight);
  30. var videoWidth = videoSize[0];
  31. var videoHeight = videoSize[1];
  32. var videoPosition = VideoLayout.getVideoPosition(videoWidth,
  33. videoHeight,
  34. videospaceWidth,
  35. videospaceHeight);
  36. var horizontalIndent = videoPosition[0];
  37. var verticalIndent = videoPosition[1];
  38. var thumbnailSize = VideoLayout.calculateThumbnailSize(videospaceWidth);
  39. var thumbnailsWidth = thumbnailSize[0];
  40. var thumbnailsHeight = thumbnailSize[1];
  41. //for chat
  42. videospace.animate({
  43. right: panelSize[0],
  44. width: videospaceWidth,
  45. height: videospaceHeight
  46. },
  47. {
  48. queue: false,
  49. duration: 500,
  50. complete: completeFunction
  51. });
  52. $('#remoteVideos').animate({
  53. height: thumbnailsHeight
  54. },
  55. {
  56. queue: false,
  57. duration: 500
  58. });
  59. $('#remoteVideos>span').animate({
  60. height: thumbnailsHeight,
  61. width: thumbnailsWidth
  62. },
  63. {
  64. queue: false,
  65. duration: 500,
  66. complete: function () {
  67. $(document).trigger(
  68. "remotevideo.resized",
  69. [thumbnailsWidth,
  70. thumbnailsHeight]);
  71. }
  72. });
  73. $('#largeVideoContainer').animate({
  74. width: videospaceWidth,
  75. height: videospaceHeight
  76. },
  77. {
  78. queue: false,
  79. duration: 500
  80. });
  81. $('#largeVideo').animate({
  82. width: videoWidth,
  83. height: videoHeight,
  84. top: verticalIndent,
  85. bottom: verticalIndent,
  86. left: horizontalIndent,
  87. right: horizontalIndent
  88. },
  89. {
  90. queue: false,
  91. duration: 500
  92. });
  93. };
  94. /**
  95. * Toggles the windows in the side panel
  96. * @param object the window that should be shown
  97. * @param selector the selector for the element containing the panel
  98. * @param onOpenComplete function to be called when the panel is opened
  99. * @param onOpen function to be called if the window is going to be opened
  100. * @param onClose function to be called if the window is going to be closed
  101. */
  102. var toggle = function(object, selector, onOpenComplete, onOpen, onClose) {
  103. UIUtil.buttonClick(buttons[selector], "active");
  104. if (object.isVisible()) {
  105. $("#toast-container").animate({
  106. right: '5px'
  107. },
  108. {
  109. queue: false,
  110. duration: 500
  111. });
  112. $(selector).hide("slide", {
  113. direction: "right",
  114. queue: false,
  115. duration: 500
  116. });
  117. if(typeof onClose === "function") {
  118. onClose();
  119. }
  120. currentlyOpen = null;
  121. }
  122. else {
  123. // Undock the toolbar when the chat is shown and if we're in a
  124. // video mode.
  125. if (VideoLayout.isLargeVideoVisible()) {
  126. ToolbarToggler.dockToolbar(false);
  127. }
  128. if(currentlyOpen) {
  129. var current = $(currentlyOpen);
  130. UIUtil.buttonClick(buttons[currentlyOpen], "active");
  131. current.css('z-index', 4);
  132. setTimeout(function () {
  133. current.css('display', 'none');
  134. current.css('z-index', 5);
  135. }, 500);
  136. }
  137. $("#toast-container").animate({
  138. right: (PanelToggler.getPanelSize()[0] + 5) + 'px'
  139. },
  140. {
  141. queue: false,
  142. duration: 500
  143. });
  144. $(selector).show("slide", {
  145. direction: "right",
  146. queue: false,
  147. duration: 500,
  148. complete: onOpenComplete
  149. });
  150. if(typeof onOpen === "function") {
  151. onOpen();
  152. }
  153. currentlyOpen = selector;
  154. }
  155. };
  156. /**
  157. * Opens / closes the chat area.
  158. */
  159. my.toggleChat = function() {
  160. var chatCompleteFunction = Chat.isVisible() ?
  161. function() {} : function () {
  162. Chat.scrollChatToBottom();
  163. $('#chatspace').trigger('shown');
  164. };
  165. resizeVideoArea(Chat.isVisible(), chatCompleteFunction);
  166. toggle(Chat,
  167. '#chatspace',
  168. function () {
  169. // Request the focus in the nickname field or the chat input field.
  170. if ($('#nickname').css('visibility') === 'visible') {
  171. $('#nickinput').focus();
  172. } else {
  173. $('#usermsg').focus();
  174. }
  175. },
  176. null,
  177. Chat.resizeChat,
  178. null);
  179. };
  180. /**
  181. * Opens / closes the contact list area.
  182. */
  183. my.toggleContactList = function () {
  184. var completeFunction = ContactList.isVisible() ?
  185. function() {} : function () { $('#contactlist').trigger('shown');};
  186. resizeVideoArea(ContactList.isVisible(), completeFunction);
  187. toggle(ContactList,
  188. '#contactlist',
  189. null,
  190. function() {
  191. ContactList.setVisualNotification(false);
  192. },
  193. null);
  194. };
  195. /**
  196. * Opens / closes the settings menu
  197. */
  198. my.toggleSettingsMenu = function() {
  199. resizeVideoArea(SettingsMenu.isVisible(), function (){});
  200. toggle(SettingsMenu,
  201. '#settingsmenu',
  202. null,
  203. function() {
  204. var settings = Settings.getSettings();
  205. $('#setDisplayName').get(0).value = settings.displayName;
  206. $('#setEmail').get(0).value = settings.email;
  207. },
  208. null);
  209. };
  210. /**
  211. * Returns the size of the side panel.
  212. */
  213. my.getPanelSize = function () {
  214. var availableHeight = window.innerHeight;
  215. var availableWidth = window.innerWidth;
  216. var panelWidth = 200;
  217. if (availableWidth * 0.2 < 200) {
  218. panelWidth = availableWidth * 0.2;
  219. }
  220. return [panelWidth, availableHeight];
  221. };
  222. my.isVisible = function() {
  223. return (Chat.isVisible() || ContactList.isVisible() || SettingsMenu.isVisible());
  224. };
  225. return my;
  226. }(PanelToggler || {}));
  227. module.exports = PanelToggler;