keyboard.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // XXX Pressing `?` should display a list of all shortcuts available.
  2. //
  3. // XXX There is no reason to define these shortcuts globally, they should be
  4. // attached to a template (most of them will go in the `board` template).
  5. // Pressing `Escape` should close the last opened “element” and only the last
  6. // one -- curently we handle popups and the card detailed view of the sidebar.
  7. Mousetrap.bind('esc', function() {
  8. if (currentlyOpenedForm.get() !== null) {
  9. currentlyOpenedForm.get().close();
  10. } else if (Popup.isOpen()) {
  11. Popup.back();
  12. // XXX We should have a higher level API
  13. } else if (Session.get('currentCard')) {
  14. Utils.goBoardId(Session.get('currentBoard'));
  15. }
  16. });
  17. Mousetrap.bind('w', function() {
  18. if (! Session.get('currentCard')) {
  19. Sidebar.toogle();
  20. } else {
  21. Utils.goBoardId(Session.get('currentBoard'));
  22. Sidebar.hide();
  23. }
  24. });
  25. Mousetrap.bind('q', function() {
  26. var currentBoardId = Session.get('currentBoard');
  27. var currentUserId = Meteor.userId();
  28. if (currentBoardId && currentUserId) {
  29. Filter.members.toogle(currentUserId);
  30. }
  31. });
  32. Mousetrap.bind('x', function() {
  33. if (Filter.isActive()) {
  34. Filter.reset();
  35. }
  36. });
  37. Mousetrap.bind(['down', 'up'], function(evt, key) {
  38. if (! Session.get('currentCard')) {
  39. return;
  40. }
  41. var nextFunc = (key === 'down' ? 'next' : 'prev');
  42. var nextCard = $('.js-minicard.is-selected')[nextFunc]('.js-minicard').get(0);
  43. if (nextCard) {
  44. var nextCardId = Blaze.getData(nextCard)._id;
  45. Utils.goCardId(nextCardId);
  46. }
  47. });