-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.js
95 lines (84 loc) · 2.32 KB
/
app.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
show();
let clearbtn = document.getElementById("clearBtn");
clearbtn.addEventListener("click", function(e){
let txt = document.getElementById("addTxt");
txt.value = "";
})
let addbtn = document.getElementById("addBtn");
addbtn.addEventListener("click", function(e){
let txt = document.getElementById("addTxt");
if (txt.value == "") {
alert("OOPs!! Note is Empty");
}
else {
let notes = localStorage.getItem("notes");
if(notes == null){
notesObj = [];
}
else{
notesObj = JSON.parse(notes);
}
notesObj.push(txt.value);
localStorage.setItem("notes",JSON.stringify(notesObj));
txt.value = "";
show();
}
});
function show(){
let notes = localStorage.getItem("notes");
if(notes == null){
notesObj = [];
}
else{
notesObj = JSON.parse(notes);
}
let html = "";
notesObj.forEach(function(element,index){
html += `
<div class="noteCard my-2 mx-2 card" style="width:18rem;">
<div class="card-body">
<h5 class="card-title">Note ${index+1}</h5>
<p class="card-text">${element}</p>
<button id="${index}" onclick="deleteEle(this.id)" class="btn btn-primary del" data-toggle="tooltip" title="Delete Note Permanently">Delete</button>
<button onclick="markimp(this)" class="btn imp btn-primary">Mark Important</button>
</div>
</div>`;
});
let notesElm = document.getElementById("notes");
if(notesObj.length != 0){
notesElm.innerHTML = html;
}
else{
notesElm.innerHTML = `<h4 style="color:grey;">No Notes Yet !</h4>`;
}
}
function deleteEle(index){
let notes = localStorage.getItem("notes");
if(notes == null){
notesObj = [];
}
else{
notesObj = JSON.parse(notes);
}
notesObj.splice(index,1);
localStorage.setItem("notes",JSON.stringify(notesObj));
show();
}
let search = document.getElementById("searchTxt");
search.addEventListener("input",function(){
let val = search.value.toLowerCase();
let note = document.getElementsByClassName("noteCard");
Array.from(note).forEach(function(element){
let cardTxt = element.getElementsByTagName("p")[0].innerHTML;
if(cardTxt.includes(val)){
element.style.display = "block"
}
else{
element.style.display = "none"
}
});
});
function markimp(card){
card.parentElement.style.background = "#ffeecb";
card.parentElement.style.borderRadius="40px";
}