-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinterface.js
More file actions
75 lines (66 loc) · 2.06 KB
/
Copy pathinterface.js
File metadata and controls
75 lines (66 loc) · 2.06 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
var notebook = new Notebook();
function setCookie(name, value) {
var data = [name, '=', JSON.stringify(value), ';'].join('');
document.cookie = data;
}
function getCookie(name) {
var cookie = document.cookie.match(new RegExp(name + '=([^;]+)'));
cookie && (cookie = JSON.parse(cookie[1]));
return cookie;
}
function importCookieToNotes() {
var notesArr = getCookie('notes');
if (notesArr) {
notesArr.reverse().forEach(function(obj){
notebook.createNote(obj.body, new Date(Date.parse(obj.createdAt)));
});}
}
function getNoteFromId(noteId){
return notebook.notes.filter(function(note){return note.id == noteId})[0];
}
function saveNote(){
var notebody = document.getElementById('content').textContent
if (notebody == "") {
notebook.createNote()
} else {
notebook.createNote(notebody);
}
document.getElementById('content').textContent = ""
showNotes();
}
function showNotes(){
var notesList = document.getElementById('list-of-notes');
notesList.innerHTML = "";
notebook.printNoteAbbr().forEach(function(element){
notesList.appendChild(element);
var thisNote = getNoteFromId(element.id)
var listTimeElement = document.createElement('span');
listTimeElement.className = 'time'
listTimeElement.innerHTML = thisNote.getFormattedDate();
element.insertBefore(listTimeElement, element.firstChild);
});
setCookie('notes', notebook.notes);
}
function toggleNoteView(noteId){
var noteLi = document.getElementById(noteId);
var thisNote = getNoteFromId(noteId)
if (noteLi.getAttribute("abbr") === "true") {
noteLi.childNodes[1].textContent = thisNote.body
noteLi.style.maxHeight= "9001px";
setTimeout(function(){
noteLi.setAttribute("abbr","false");
},500);
}
else {
noteLi.style.maxHeight= "18.4px";
setTimeout(function(){
noteLi.childNodes[1].textContent = thisNote.abbr();
noteLi.setAttribute("abbr","true");
},1000);
}
}
function showNotesFromCookie() {
importCookieToNotes();
showNotes();
};
document.addEventListener('DOMContentLoaded', showNotesFromCookie, false);