keyboard.js 2.2 KB

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