Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

SidePanelToggler.js 7.8KB

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