comments.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. var commentFormIsOpen = new ReactiveVar(false);
  2. Template.commentForm.helpers({
  3. commentFormIsOpen: function() {
  4. return commentFormIsOpen.get();
  5. }
  6. });
  7. Template.commentForm.events({
  8. 'click .js-new-comment:not(.focus)': function() {
  9. commentFormIsOpen.set(true);
  10. },
  11. 'submit .js-new-comment-form': function(evt, tpl) {
  12. var input = tpl.$('.js-new-comment-input');
  13. if ($.trim(input.val())) {
  14. CardComments.insert({
  15. boardId: this.boardId,
  16. cardId: this._id,
  17. text: input.val()
  18. });
  19. input.val('');
  20. input.blur();
  21. commentFormIsOpen.set(false);
  22. Tracker.flush();
  23. autosize.update(input);
  24. }
  25. evt.preventDefault();
  26. },
  27. // Pressing Ctrl+Enter should submit the form
  28. 'keydown form textarea': function(evt, tpl) {
  29. if (evt.keyCode === 13 && (evt.metaKey || evt.ctrlKey)) {
  30. tpl.find('button[type=submit]').click();
  31. }
  32. }
  33. });
  34. Template.commentForm.onDestroyed(function() {
  35. commentFormIsOpen.set(false);
  36. });
  37. EscapeActions.register('inlinedForm',
  38. function() {
  39. commentFormIsOpen.set(false);
  40. $('.js-new-comment-input').blur();
  41. },
  42. function() { return commentFormIsOpen.get(); }, {
  43. noClickEscapeOn: '.js-new-comment'
  44. }
  45. );