diff options
Diffstat (limited to 'client/components/activities/comments.js')
-rw-r--r-- | client/components/activities/comments.js | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/client/components/activities/comments.js b/client/components/activities/comments.js index e69de29b..d41b86dd 100644 --- a/client/components/activities/comments.js +++ b/client/components/activities/comments.js @@ -0,0 +1,49 @@ +var commentFormIsOpen = new ReactiveVar(false); + +Template.commentForm.helpers({ + commentFormIsOpen: function() { + return commentFormIsOpen.get(); + } +}); + +Template.commentForm.events({ + 'click .js-new-comment:not(.focus)': function() { + commentFormIsOpen.set(true); + }, + 'submit .js-new-comment-form': function(evt, tpl) { + var input = tpl.$('.js-new-comment-input'); + if ($.trim(input.val())) { + CardComments.insert({ + boardId: this.boardId, + cardId: this._id, + text: input.val() + }); + input.val(''); + input.blur(); + commentFormIsOpen.set(false); + Tracker.flush(); + autosize.update(input); + } + evt.preventDefault(); + }, + // Pressing Ctrl+Enter should submit the form + 'keydown form textarea': function(evt, tpl) { + if (evt.keyCode === 13 && (evt.metaKey || evt.ctrlKey)) { + tpl.find('button[type=submit]').click(); + } + } +}); + +Template.commentForm.onDestroyed(function() { + commentFormIsOpen.set(false); +}); + +EscapeActions.register('inlinedForm', + function() { + commentFormIsOpen.set(false); + $('.js-new-comment-input').blur(); + }, + function() { return commentFormIsOpen.get(); }, { + noClickEscapeOn: '.js-new-comment' + } +); |