Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

keyboardshortcut.js 3.6KB

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