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

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