選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

keyboardshortcut.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * Copyright @ 2015 Atlassian Pty Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. //maps keycode to character, id of popover for given function and function
  17. var shortcuts = {
  18. 67: {
  19. character: "C",
  20. id: "toggleChatPopover",
  21. function: APP.UI.toggleChat
  22. },
  23. 70: {
  24. character: "F",
  25. id: "filmstripPopover",
  26. function: APP.UI.toggleFilmStrip
  27. },
  28. 77: {
  29. character: "M",
  30. id: "mutePopover",
  31. function: APP.UI.toggleAudio
  32. },
  33. 84: {
  34. character: "T",
  35. function: function() {
  36. if(!APP.RTC.localAudio.isMuted()) {
  37. APP.UI.toggleAudio();
  38. }
  39. }
  40. },
  41. 86: {
  42. character: "V",
  43. id: "toggleVideoPopover",
  44. function: APP.UI.toggleVideo
  45. }
  46. };
  47. var KeyboardShortcut = {
  48. init: function () {
  49. window.onkeyup = function(e) {
  50. var keycode = e.which;
  51. if(!($(":focus").is("input[type=text]") ||
  52. $(":focus").is("input[type=password]") ||
  53. $(":focus").is("textarea"))) {
  54. if (typeof shortcuts[keycode] === "object") {
  55. shortcuts[keycode].function();
  56. }
  57. else if (keycode >= "0".charCodeAt(0) &&
  58. keycode <= "9".charCodeAt(0)) {
  59. APP.UI.clickOnVideo(keycode - "0".charCodeAt(0) + 1);
  60. }
  61. //esc while the smileys are visible hides them
  62. } else if (keycode === 27 && $('#smileysContainer').is(':visible')) {
  63. APP.UI.toggleSmileys();
  64. }
  65. };
  66. window.onkeydown = function(e) {
  67. if(!($(":focus").is("input[type=text]") ||
  68. $(":focus").is("input[type=password]") ||
  69. $(":focus").is("textarea"))) {
  70. if(e.which === "T".charCodeAt(0)) {
  71. if(APP.RTC.localAudio.isMuted()) {
  72. APP.UI.toggleAudio();
  73. }
  74. }
  75. }
  76. };
  77. var self = this;
  78. $('body').popover({ selector: '[data-toggle=popover]',
  79. trigger: 'click hover',
  80. content: function() {
  81. return this.getAttribute("content") +
  82. self.getShortcut(this.getAttribute("shortcut"));
  83. }
  84. });
  85. },
  86. /**
  87. *
  88. * @param id indicates the popover associated with the shortcut
  89. * @returns {string} the keyboard shortcut used for the id given
  90. */
  91. getShortcut: function (id) {
  92. for (var keycode in shortcuts) {
  93. if (shortcuts.hasOwnProperty(keycode)) {
  94. if (shortcuts[keycode].id === id) {
  95. return " (" + shortcuts[keycode].character + ")";
  96. }
  97. }
  98. }
  99. return "";
  100. }
  101. };
  102. module.exports = KeyboardShortcut;