-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.js
45 lines (42 loc) · 1.29 KB
/
application.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
39
40
41
42
43
44
45
const Application = {
save(){
var object= {
idCounter: document.querySelectorAll('.column').length,
columns: []
}
// column pass
document.querySelectorAll('.column').forEach(columnElement => {
const column = {
id: +columnElement.getAttribute ('data-column-id'),
title: columnElement.querySelector('.column-header').innerText,
notes: []
}
// note pass
columnElement.querySelectorAll('.note').forEach(noteElement => {
let noteId = +noteElement.getAttribute('data-note-id');
let noteItem = {
id: noteId,
content: noteElement.textContent
}
column.notes.push(noteItem);
});
object.columns.push(column);
});
localStorage.setItem('trello', JSON.stringify(object));
},
load(){
if (!localStorage.getItem('trello')) return;
const object = JSON.parse(localStorage.getItem('trello'));
var mountPoint = document.querySelector('.columns');
mountPoint.innerHTML = '';
for (const column of object.columns){
let newColumn = new Column(column.id);
newColumn.element.querySelector('.column-header').innerText = column.title;
for (const note of column.notes){
let newNote = new Note(note.id, note.content);
newColumn.add(newNote);
}
mountPoint.append(newColumn.element);
}
}
}