| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 | const commentFormIsOpen = new ReactiveVar(false);BlazeComponent.extendComponent({  onDestroyed() {    commentFormIsOpen.set(false);  },  commentFormIsOpen() {    return commentFormIsOpen.get();  },  getInput() {    return this.$('.js-new-comment-input');  },  events() {    return [      {        'click .js-new-comment:not(.focus)'() {          commentFormIsOpen.set(true);        },        'submit .js-new-comment-form'(evt) {          const input = this.getInput();          const text = input.val().trim();          const card = this.currentData();          let boardId = card.boardId;          let cardId = card._id;          if (card.isLinkedCard()) {            boardId = Cards.findOne(card.linkedId).boardId;            cardId = card.linkedId;          }          if (text) {            CardComments.insert({              text,              boardId,              cardId,            });            resetCommentInput(input);            Tracker.flush();            autosize.update(input);          }          evt.preventDefault();        },        // Pressing Ctrl+Enter should submit the form        'keydown form textarea'(evt) {          if (evt.keyCode === 13 && (evt.metaKey || evt.ctrlKey)) {            this.find('button[type=submit]').click();          }        },      },    ];  },}).register('commentForm');// XXX This should be a static method of the `commentForm` componentfunction resetCommentInput(input) {  input.val('');  input.blur();  commentFormIsOpen.set(false);}// XXX This should handled a `onUpdated` callback of the `commentForm` component// but since this callback doesn't exists, and `onRendered` is not called if the// data is not destroyed and recreated, we simulate the desired callback using// Tracker.autorun to register the component dependencies, and re-run when these// dependencies are invalidated. A better component API would remove this hack.Tracker.autorun(() => {  Session.get('currentCard');  Tracker.afterFlush(() => {    autosize.update($('.js-new-comment-input'));  });});EscapeActions.register(  'inlinedForm',  () => {    const draftKey = {      fieldName: 'cardComment',      docId: Session.get('currentCard'),    };    const commentInput = $('.js-new-comment-input');    const draft = commentInput.val().trim();    if (draft) {      UnsavedEdits.set(draftKey, draft);    } else {      UnsavedEdits.reset(draftKey);    }    resetCommentInput(commentInput);  },  () => {    return commentFormIsOpen.get();  },  {    noClickEscapeOn: '.js-new-comment',  },);
 |