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.

keyboardshortcut.js 3.3KB

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