-
Notifications
You must be signed in to change notification settings - Fork 0
/
notesApp.html
191 lines (171 loc) · 6.74 KB
/
notesApp.html
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>ANotes</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css" integrity="sha512-KfkfwYDsLkIlwQp6LFnl8zNdLGxu9YAA1QvwINks4PhcElQSvqcyVLLD9aMhXd13uQjoXtEKNosOWaZqXgel0g==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<style>
*{
font-family: monospace;
}
</style>
</head>
<body class="bg-light">
<div class="container">
<div class="row mb-5" style="margin-top: 100px;">
<div class="col-12 col-sm-10 mx-auto">
<div class="card">
<div class="card-header text-center">
<i class="fa-regular fa-note-sticky"></i>
Notes App
<span class="badge bg-secondary">v1.0.0</span>
</div>
<div class="card-body border-bottom">
<p>Let's start</p>
<textarea class="w-100" id="text-area" rows="5"></textarea>
<button onclick="addNote()" type="button" style="font-size: 10px;" class="btn btn-secondary">
<i class="fa-solid fa-circle-plus"></i>
Add Note
</button>
<button type="button" onclick="clear_text()" style="font-size: 10px;" class="btn btn-danger">
<i class="fa-solid fa-eraser"></i>
Clear
</button>
</div>
<div class="card-body">
<div class="container-fluid">
<div class="row">
<div class="col-12" id="diss">
</div>
</div>
</div>
</div>
<div class="card-footer pt-4 text-center">
<div class="blockquote-footer mb-0">
Made by
<strong>Aadil Mugal</strong>
made with <span class="text-danger">🎔</span>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- tost when note delete -->
<div class="position-fixed top-0 end-0 p-3" style="z-index: 11">
<div id="toast" class="toast align-items-center text-white bg-danger border-0" role="alert" aria-live="assertive" aria-atomic="true" data-bs-autohide="false">
<div class="d-flex">
<div class="toast-body" id="pdata">
<!-- nothing -->
</div>
<button type="button" class="btn-close btn-close-white me-3 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-A3rJD856KowSb7dwlZdYEkO39Gagi7vIsF0jrRAoQmDKKtQBHUuLZ9AsSv4jD4Xa" crossorigin="anonymous"></script>
<script>
let elm = document.getElementById('text-area');
function showToast(pdata){
let elem = document.getElementById('toast');
let where = document.getElementById('pdata');
let ico = `<i class="fa-solid fa-circle-info me-2"></i>`
where.innerHTML = ico + pdata;
elem.classList.toggle('show');
}
function clear_text(){
if(elm.value==""){
showToast("No data to clear");
}else{
elm.value = "";
showToast("Input data cleared");
}
}
function showNotes(){
let notesObj = [];
let nots = localStorage.getItem("notes");
if(nots==null)
return;
notesObj = JSON.parse(nots);
let html = "";
notesObj.forEach( function(element, index) {
html+=`<div class="card mb-4">
<div class="card-header text-center">
<dev class="row justify-content-between align-items-center">
<div class="col-auto">
<p class="mb-0 small">
${element[1]}
</p>
</div>
<div class="col-auto">
<strong>Note #${index+1}</strong>
</div>
<div class="col-auto btn-group" role="group">
<button onclick="edt(${index})" type="button" class="btn border btn-outline-success">
<i class="fa-regular fa-pen-to-square"></i>
</button>
<button onclick="deleteNotes(${index})" type="button" class="btn border btn-outline-danger">
<i class="fa-solid fa-trash"></i>
</button>
</div>
</dev>
</div>
<div class="card-body">
<p>${element[0]}</p>
</div>
</div>`
});
let diss = document.getElementById('diss');
if(notesObj.length==0){
diss.innerHTML = `
<p> Notes Will display here </p>
`
}else{
diss.innerHTML = html;
}
}
function addNote(){
if(elm.value==""){
showToast("Note field is empty");
return;
}
let current = new Date();
let cDate = current.getDate() + '-' + (current.getMonth() + 1) + '-'+ current.getFullYear();
let cTime = current.getHours() + ":" + current.getMinutes();
let dateTime = `${cDate} (${cTime})`;
let notesObj = [];
let nots = localStorage.getItem("notes");
if(nots!=null)
notesObj = JSON.parse(nots);
let t = [elm.value,dateTime];
notesObj.push(t);
localStorage.setItem("notes", JSON.stringify(notesObj));
elm.value = "";
showNotes();
}
showNotes();
function deleteNotes(i){
let notesObj = [];
let nots = localStorage.getItem("notes");
if(nots!=null)
notesObj = JSON.parse(nots);
notesObj.splice(i, 1);
localStorage.setItem("notes", JSON.stringify(notesObj));
showNotes();
}
function edt(i){
if(elm.value!=""){
showToast("First clear the input field");
return;
}
let notesObj = [];
let nots = localStorage.getItem("notes");
if(nots!=null)
notesObj = JSON.parse(nots);
elm.value = notesObj[i][0];
deleteNotes(i);
}
</script>
</body>
</html>