Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

keyboardshortcut.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* global APP, $ */
  2. //maps keycode to character, id of popover for given function and function
  3. var shortcuts = {};
  4. function initShortcutHandlers() {
  5. shortcuts = {
  6. 27: {
  7. character: "Esc",
  8. function: function() {
  9. APP.UI.showKeyboardShortcutsPanel(false);
  10. }
  11. },
  12. 67: {
  13. character: "C",
  14. id: "toggleChatPopover",
  15. function: function() {
  16. APP.UI.toggleChat();
  17. }
  18. },
  19. 68: {
  20. character: "D",
  21. id: "toggleDesktopSharingPopover",
  22. function: function () {
  23. APP.conference.toggleScreenSharing();
  24. }
  25. },
  26. 70: {
  27. character: "F",
  28. id: "filmstripPopover",
  29. function: function() {
  30. APP.UI.toggleFilmStrip();
  31. }
  32. },
  33. 77: {
  34. character: "M",
  35. id: "mutePopover",
  36. function: function() {
  37. APP.conference.toggleAudioMuted();
  38. }
  39. },
  40. 82: {
  41. character: "R",
  42. function: function() {
  43. APP.conference.maybeToggleRaisedHand();
  44. }
  45. },
  46. 84: {
  47. character: "T",
  48. function: function() {
  49. APP.conference.muteAudio(true);
  50. }
  51. },
  52. 86: {
  53. character: "V",
  54. id: "toggleVideoPopover",
  55. function: function() {
  56. APP.conference.toggleVideoMuted();
  57. }
  58. },
  59. 191: {
  60. character: "/",
  61. function: function(e) {
  62. // Only trigger on "?", not on "/".
  63. if (e.shiftKey) {
  64. APP.UI.toggleKeyboardShortcutsPanel();
  65. }
  66. }
  67. }
  68. };
  69. }
  70. var KeyboardShortcut = {
  71. init: function () {
  72. initShortcutHandlers();
  73. window.onkeyup = function(e) {
  74. var keycode = e.which;
  75. if(!($(":focus").is("input[type=text]") ||
  76. $(":focus").is("input[type=password]") ||
  77. $(":focus").is("textarea"))) {
  78. if (typeof shortcuts[keycode] === "object") {
  79. shortcuts[keycode].function(e);
  80. }
  81. else if (keycode >= "0".charCodeAt(0) &&
  82. keycode <= "9".charCodeAt(0)) {
  83. APP.UI.clickOnVideo(keycode - "0".charCodeAt(0) + 1);
  84. }
  85. //esc while the smileys are visible hides them
  86. } else if (keycode === 27 &&
  87. $('#smileysContainer').is(':visible')) {
  88. APP.UI.toggleSmileys();
  89. }
  90. };
  91. window.onkeydown = function(e) {
  92. if(!($(":focus").is("input[type=text]") ||
  93. $(":focus").is("input[type=password]") ||
  94. $(":focus").is("textarea"))) {
  95. if(e.which === "T".charCodeAt(0)) {
  96. if(APP.conference.isLocalAudioMuted())
  97. APP.conference.muteAudio(false);
  98. }
  99. }
  100. };
  101. var self = this;
  102. $('body').popover({ selector: '[data-toggle=popover]',
  103. trigger: 'click hover',
  104. content: function() {
  105. return this.getAttribute("content") +
  106. self.getShortcut(this.getAttribute("shortcut"));
  107. }
  108. });
  109. },
  110. /**
  111. *
  112. * @param id indicates the popover associated with the shortcut
  113. * @returns {string} the keyboard shortcut used for the id given
  114. */
  115. getShortcut: function (id) {
  116. for (var keycode in shortcuts) {
  117. if (shortcuts.hasOwnProperty(keycode)) {
  118. if (shortcuts[keycode].id === id) {
  119. return " (" + shortcuts[keycode].character + ")";
  120. }
  121. }
  122. }
  123. return "";
  124. }
  125. };
  126. module.exports = KeyboardShortcut;