in static/src/javascripts/projects/common/modules/discussion/comment-box.js [361:431]
ready() {
if (this.getDiscussionId() === null) {
throw new Error(
'CommentBox: You need to set the "data-discussion-key" on your element'
);
}
const commentBody = this.getElem('body');
this.setFormState();
if (this.options.newCommenter) {
bean.on(document.body, 'submit', [this.elem], (event) =>
this.showOnboarding(event)
);
bean.on(
document.body,
'click',
this.getClass('onboarding-cancel'),
(event) => this.hideOnboarding(event)
);
} else {
bean.on(document.body, 'submit', [this.elem], (event) =>
this.submitPostComment(event)
);
}
bean.on(document.body, 'change keyup', [commentBody], () =>
this.setFormState()
);
bean.on(commentBody, 'focus', () => this.setExpanded());
this.on('change', '.d-comment-box__body', () =>
this.resetPreviewComment()
);
this.on('click', this.getClass('preview'), () =>
this.previewComment('previewCommentSuccess')
);
this.on('click', this.getClass('hide-preview'), () =>
this.resetPreviewComment()
);
this.on('click', this.getClass('cancel'), () => this.cancelComment());
this.on('click', this.getClass('show-parent'), () =>
this.setState('parent-visible')
);
this.on('click', this.getClass('hide-parent'), () =>
this.removeState('parent-visible')
);
['bold', 'italic', 'quote', 'link'].forEach(format => {
const selector = this.getClass(`formatting-${format}`);
this.on('click', selector, () => this.formatComment(format));
});
if (this.options.state) {
this.setState(this.options.state);
}
if (this.options.focus) {
const body = this.getElem('body');
if (body) {
window.setTimeout(() => {
body.focus();
}, 0);
}
}
}