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.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. if($("#chatspace").css("display") === "none" ||
  35. !($("#usermsg").is(":focus") || $("#nickinput").is(":focus"))) {
  36. var keycode = e.which;
  37. if (typeof shortcuts[keycode] === "object") {
  38. shortcuts[keycode].function();
  39. } else if (keycode >= "1".charCodeAt(0) && keycode <= "9".charCodeAt(0)) {
  40. var remoteVideos = $(".videocontainer:not(#mixedstream)"),
  41. videoWanted = keycode - "0".charCodeAt(0);
  42. if (remoteVideos.length > videoWanted) {
  43. remoteVideos[videoWanted].click();
  44. }
  45. }
  46. }
  47. };
  48. window.onkeydown = function(e) {
  49. if($("#chatspace").css("display") === "none") {
  50. if(e.which === "T".charCodeAt(0)) {
  51. if(isAudioMuted()) {
  52. toggleAudio();
  53. }
  54. }
  55. }
  56. };
  57. /**
  58. *
  59. * @param id indicates the popover associated with the shortcut
  60. * @returns {string} the keyboard shortcut used for the id given
  61. */
  62. my.getShortcut = function(id) {
  63. for(var keycode in shortcuts) {
  64. if(shortcuts.hasOwnProperty(keycode)) {
  65. if (shortcuts[keycode].id === id) {
  66. return " (" + shortcuts[keycode].character + ")";
  67. }
  68. }
  69. }
  70. return "";
  71. };
  72. return my;
  73. }(KeyboardShortcut || {}));