Skip to content

Commit 4c63b6d

Browse files
committed
add Notes class, change Note constructor
1 parent 55b2ea8 commit 4c63b6d

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

public/javascript/notes.js

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
class Note {
2-
constructor(id, noteDiv) {
3-
this.id = id
4-
this.noteDiv = noteDiv
2+
constructor(noteDiv) {
3+
this.noteDiv = noteDiv;
4+
this.id = noteDiv.getAttribute('data-note-id');
5+
6+
(noteDiv.querySelectorAll('.edit-note') || []).forEach(editNoteButton => {
7+
editNoteButton.addEventListener('click', () => {
8+
this.toggleEditForm()
9+
})
10+
})
11+
12+
noteDiv.querySelector('.delete-note').addEventListener('click', () => {
13+
this.delete()
14+
})
15+
16+
noteDiv.querySelector('.update-note').addEventListener('click', () => {
17+
this.toggleEditForm()
18+
this.update()
19+
})
520
}
621

722
update() {
@@ -53,28 +68,16 @@ class Note {
5368
}
5469
}
5570

56-
const Notes = {
57-
init() {
58-
(document.querySelectorAll('.note-div') || []).forEach(noteDiv => {
59-
const noteId = noteDiv.getAttribute('data-note-id')
60-
const note = new Note(noteId, noteDiv)
61-
62-
noteDiv.querySelector('.delete-note').addEventListener('click', () => {
63-
note.delete()
64-
});
65-
66-
(noteDiv.querySelectorAll('.edit-note') || []).forEach(editNoteButton => {
67-
editNoteButton.addEventListener('click', () => {
68-
note.toggleEditForm()
69-
})
70-
})
71+
class Notes {
72+
constructor() {
73+
this.notes = [];
7174

72-
noteDiv.querySelector('.update-note').addEventListener('click', () => {
73-
note.toggleEditForm()
74-
note.update()
75-
})
75+
(document.querySelectorAll('.note-div') || []).forEach(noteDiv => {
76+
this.notes.push(new Note(noteDiv))
7677
})
7778
}
7879
};
7980

80-
ready(Notes.init);
81+
ready(() => {
82+
new Notes();
83+
});

0 commit comments

Comments
 (0)