-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
104 lines (69 loc) · 2.64 KB
/
script.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
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
let noteButton = document.querySelector('.noteButton')
let notetextInput = document.querySelector('.notetextInput')
let notesGroup = document.querySelector('.notesGroup')
noteButton.addEventListener('click', () => {
if (notetextInput.value === '') {
alert(`Please Write Down Title`)
} else {
let noteWriting = document.createElement('div')
noteWriting.classList.add('noteWriting')
noteWriting.innerHTML = `
<i class="fa-solid fa-trash" id="delteNote"></i>
<i class="fa-solid fa-floppy-disk" id="saveNote"></i>
<i class="fa-solid fa-arrow-up-right-from-square" id="openNote"></i>
<header class="NoteTitle"><h1 class="headerTitle">${notetextInput.value}<h1></header>
<div class="noteDescription"> </div>`;
notesGroup.prepend(noteWriting);
// Create a new timer
const timerId = setTimeout(() => {
noteWriting.classList.toggle('borderActive');
storingNotes();
}, 0000);
// Cancel the timer after it has completed
setTimeout(() => {
noteWriting.classList.toggle('borderActive');
clearTimeout(timerId);
storingNotes();
}, 3000);
notetextInput.value = '';
storingNotes();
}
})
notesGroup.addEventListener('click', (elem) => {
let editNoteWrite = elem.target.closest('.noteWriting');
if (elem.target.closest('#delteNote')) {
editNoteWrite.remove();
storingNotes();
} else if (elem.target.closest('#openNote')) {
editNoteWrite.querySelector('.headerTitle').contentEditable = true;
editNoteWrite.querySelector('.noteDescription').contentEditable = true;
editNoteWrite.classList.toggle('active');
if (editNoteWrite.classList.contains('active')) {
editNoteWrite.querySelector('.headerTitle').contentEditable = true;
editNoteWrite.querySelector('.noteDescription').contentEditable = true;
storingNotes();
} else {
editNoteWrite.querySelector('.headerTitle').contentEditable = false;
editNoteWrite.querySelector('.noteDescription').contentEditable = false;
storingNotes();
}
} else if (elem.target.closest('#saveNote')) {
storingNotes();
alert('Do You want to Save The Notes?')
}
});
//Add at local storage
const storingNotes = () => {
localStorage.setItem('setNotes', notesGroup.innerHTML);
}
const gettingNotes = () => {
notesGroup.innerHTML = localStorage.getItem('setNotes')
};
gettingNotes();
// notesGroup.addEventListener('click', (event) => {
// if (event.target.matches('#closeNote')) {
// event.target.closest('.noteWriting').remove();
// } else {
// return 0;
// }
// });