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.

keyboardshortcut.js 3.0KB

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