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

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