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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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(!($(":focus").is("input[type=text]") || $(":focus").is("textarea"))) {
  35. var keycode = e.which;
  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. }
  46. };
  47. window.onkeydown = function(e) {
  48. if($("#chatspace").css("display") === "none") {
  49. if(e.which === "T".charCodeAt(0)) {
  50. if(isAudioMuted()) {
  51. toggleAudio();
  52. }
  53. }
  54. }
  55. };
  56. /**
  57. *
  58. * @param id indicates the popover associated with the shortcut
  59. * @returns {string} the keyboard shortcut used for the id given
  60. */
  61. my.getShortcut = function(id) {
  62. for(var keycode in shortcuts) {
  63. if(shortcuts.hasOwnProperty(keycode)) {
  64. if (shortcuts[keycode].id === id) {
  65. return " (" + shortcuts[keycode].character + ")";
  66. }
  67. }
  68. }
  69. return "";
  70. };
  71. return my;
  72. }(KeyboardShortcut || {}));