-
Notifications
You must be signed in to change notification settings - Fork 1
/
comment.js
38 lines (34 loc) · 908 Bytes
/
comment.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import autosize from 'autosize';
/**
* The comment class is manages dynamic UI elements related to comments
*
* - submit form and throw event up to live_view
* - autosize comment boxes to fit text
*
* @module Comment
*/
export default class Comment {
constructor(container) {
this.container = container;
this.attach();
this.autosize();
}
attach() {
this.replyForm = this.container;
this.replyTextArea = this.container.querySelector('textarea');
if (this.replyForm) {
this.replyForm.addEventListener('keydown', event => {
if ((event.metaKey || event.ctrlKey) && event.key == 'Enter') {
this.replyForm.dispatchEvent(
new Event('submit', { bubbles: true, cancelable: true, detail: undefined })
);
}
});
}
}
autosize() {
setTimeout(function() {
autosize(this.replyTextArea);
}, 50);
}
}