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.

side_panel_toggler.js 7.4KB

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