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.

keyboard_shortcut.js 2.5KB

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