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 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 && $('#smileysContainer').is(':visible')) {
  53. APP.UI.toggleSmileys();
  54. }
  55. };
  56. window.onkeydown = function(e) {
  57. if(!($(":focus").is("input[type=text]") ||
  58. $(":focus").is("input[type=password]") ||
  59. $(":focus").is("textarea"))) {
  60. if(e.which === "T".charCodeAt(0)) {
  61. if(APP.RTC.localAudio.isMuted()) {
  62. APP.UI.toggleAudio();
  63. }
  64. }
  65. }
  66. };
  67. var self = this;
  68. $('body').popover({ selector: '[data-toggle=popover]',
  69. trigger: 'click hover',
  70. content: function() {
  71. return this.getAttribute("content") +
  72. self.getShortcut(this.getAttribute("shortcut"));
  73. }
  74. });
  75. },
  76. /**
  77. *
  78. * @param id indicates the popover associated with the shortcut
  79. * @returns {string} the keyboard shortcut used for the id given
  80. */
  81. getShortcut: function (id) {
  82. for (var keycode in shortcuts) {
  83. if (shortcuts.hasOwnProperty(keycode)) {
  84. if (shortcuts[keycode].id === id) {
  85. return " (" + shortcuts[keycode].character + ")";
  86. }
  87. }
  88. }
  89. return "";
  90. }
  91. };
  92. module.exports = KeyboardShortcut;