-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathNote.js
More file actions
56 lines (52 loc) · 1.46 KB
/
Note.js
File metadata and controls
56 lines (52 loc) · 1.46 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
export default class Note {
constructor({title, body}, noteManager) {
this.el = null;
this.title = title;
this.body = body;
this.noteManager = noteManager;
}
static getNoteTpl() {
return `
<div class="tc-note">
<div class="tc-note-header">
<span class="tc-note-close">
<i class="fas fa-times"></i>
</span>
</div>
<div class="tc-note-title" contenteditable="">
{{title}}
</div>
<div class="tc-note-body" contenteditable="">
{{body}}
</div>
</div>`;
}
createNoteEl() {
let tpl = Note.getNoteTpl();
tpl = tpl
.replace('{{title}}', this.title)
.replace('{{body}}', this.body)
;
const div = document.createElement('div');
div.innerHTML = tpl;
this.el = div.children[0];
this.attachEventListeners();
return this.el;
}
attachEventListeners(){
const btnClose = this.el.querySelector('.tc-note-close');
btnClose.onclick = () => {
this.noteManager.removeNote(this);
};
const title = this.el.querySelector('.tc-note-title');
title.oninput = (ev) => {
this.title = ev.target.innerText;
this.noteManager.onNoteChange(this);
};
const body = this.el.querySelector('.tc-note-body');
body.oninput = (ev) => {
this.body = ev.target.innerText;
this.noteManager.onNoteChange(this);
}
}
}