keyboard.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // XXX There is no reason to define these shortcuts globally, they should be
  2. // attached to a template (most of them will go in the `board` template).
  3. Mousetrap.bind('?', () => {
  4. FlowRouter.go('shortcuts');
  5. });
  6. Mousetrap.bind('w', () => {
  7. if (Sidebar.isOpen() && Sidebar.getView() === 'home') {
  8. Sidebar.toggle();
  9. } else {
  10. Sidebar.setView();
  11. }
  12. });
  13. Mousetrap.bind('q', () => {
  14. const currentBoardId = Session.get('currentBoard');
  15. const currentUserId = Meteor.userId();
  16. if (currentBoardId && currentUserId) {
  17. Filter.members.toggle(currentUserId);
  18. }
  19. });
  20. Mousetrap.bind('x', () => {
  21. if (Filter.isActive()) {
  22. Filter.reset();
  23. }
  24. });
  25. Mousetrap.bind('f', () => {
  26. if (Sidebar.isOpen() && Sidebar.getView() === 'filter') {
  27. Sidebar.toggle();
  28. } else {
  29. Sidebar.setView('filter');
  30. }
  31. });
  32. Mousetrap.bind(['down', 'up'], (evt, key) => {
  33. if (!Session.get('currentCard')) {
  34. return;
  35. }
  36. const nextFunc = (key === 'down' ? 'next' : 'prev');
  37. const nextCard = $('.js-minicard.is-selected')[nextFunc]('.js-minicard').get(0);
  38. if (nextCard) {
  39. const nextCardId = Blaze.getData(nextCard)._id;
  40. Utils.goCardId(nextCardId);
  41. }
  42. });
  43. // XXX This shortcut should also work when hovering over a card in board view
  44. Mousetrap.bind('space', (evt) => {
  45. if (!Session.get('currentCard')) {
  46. return;
  47. }
  48. const currentUserId = Meteor.userId();
  49. if (currentUserId === null) {
  50. return;
  51. }
  52. if (Meteor.user().isBoardMember()) {
  53. const card = Cards.findOne(Session.get('currentCard'));
  54. card.toggleMember(currentUserId);
  55. // We should prevent scrolling in card when spacebar is clicked
  56. // This should do it according to Mousetrap docs, but it doesn't
  57. evt.preventDefault();
  58. }
  59. });
  60. Template.keyboardShortcuts.helpers({
  61. mapping: [{
  62. keys: ['W'],
  63. action: 'shortcut-toggle-sidebar',
  64. }, {
  65. keys: ['Q'],
  66. action: 'shortcut-filter-my-cards',
  67. }, {
  68. keys: ['F'],
  69. action: 'shortcut-toggle-filterbar',
  70. }, {
  71. keys: ['X'],
  72. action: 'shortcut-clear-filters',
  73. }, {
  74. keys: ['?'],
  75. action: 'shortcut-show-shortcuts',
  76. }, {
  77. keys: ['ESC'],
  78. action: 'shortcut-close-dialog',
  79. }, {
  80. keys: ['@'],
  81. action: 'shortcut-autocomplete-members',
  82. }, {
  83. keys: [':'],
  84. action: 'shortcut-autocomplete-emoji',
  85. }, {
  86. keys: ['SPACE'],
  87. action: 'shortcut-assign-self',
  88. }],
  89. });