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

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