Skip to content

Commit c3dacde

Browse files
committed
minor code fixes and bugs fixes
1 parent d0816f7 commit c3dacde

File tree

4 files changed

+69
-47
lines changed

4 files changed

+69
-47
lines changed

all_note.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
</ul>
3333
<form class="form-inline my-2 my-lg-0">
34-
<input class="form-control mr-sm-2 note-search" type="search" placeholder="Search" onkeyup="note_search()" aria-label="Search">
34+
<input class="form-control mr-sm-2 note-search" type="search" placeholder="Enter Note Title" onkeyup="note_search()" aria-label="Search">
3535

3636
</form>
3737
</div>
@@ -89,16 +89,16 @@ <h5 class="modal-title" id="exampleModalLabel">Warning</h5>
8989

9090
<!-- Modal -->
9191
<div class="modal fade" id="viewmodal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
92-
<div class="modal-dialog">
92+
<div class="modal-dialog ">
9393
<div class="modal-content">
9494
<div class="modal-header">
9595
<h5 class="modal-title" id="modaltitle">Modal title</h5>
9696
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
9797
<span aria-hidden="true">&times;</span>
9898
</button>
9999
</div>
100-
<div class="modal-body">
101-
<p id="modalbody"></p>
100+
<div class="modal-body text-break" id="modalbody">
101+
<!-- <p class="text-wrap"></p> -->
102102
</div>
103103
<div class="modal-footer">
104104
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
</ul>
3333
<form class="form-inline my-2 my-lg-0">
34-
<input class="form-control mr-sm-2 note-search" type="search" placeholder="Search" onkeyup="note_search()" aria-label="Search">
34+
<input class="form-control mr-sm-2 note-search" type="search" placeholder="Enter Note Title" onkeyup="note_search()" aria-label="Search">
3535

3636
</form>
3737
</div>

js/script.js

Lines changed: 63 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/////////////////// getting the note container/////////////////
22
main_container = document.querySelector(".note_container");
3-
3+
var global_note_id = 0;
44
////////////////making storenote as a default and unchangeble option/////////////////
55
if(document.getElementById("storenote"))
66
{
@@ -122,6 +122,7 @@ function data_validator() {
122122
error_message_shower("", "Note Data Can't be Empty");
123123
}
124124
else {
125+
125126
if(unique_notes_verifier())
126127
{
127128
add_note(title_el, data_el);
@@ -132,6 +133,19 @@ function data_validator() {
132133
}
133134
//////////////add note fuction ////////////////////////
134135
function add_note(title_el, data_el) {
136+
137+
if(global_note_id!=0)
138+
{
139+
note_body = document.getElementById(global_note_id).children[0].children[1];
140+
note_body.children[0].innerHTML = title_el;
141+
note_body.children[1].innerHTML = data_el.slice(0,30)+"...";
142+
global_note_id = 0;
143+
144+
}
145+
else
146+
{
147+
148+
135149
notes_count = document.querySelectorAll(".note").length; // returns total created notes
136150

137151
note_card = document.createElement("div");
@@ -159,15 +173,19 @@ function add_note(title_el, data_el) {
159173
</div>`;
160174

161175
document.getElementById(`${notes_count + 1}`).innerHTML = html; //adding the html for the proper view
176+
}
162177

163178
}
164179

165180

166181
//////////////////////the delete function. This will remove note from dom and also from localstorage if the note is previously saved in local storage ////////////////////
167-
function notedelete(id, title,msg="") {
168-
el = document.getElementById(id);
182+
function notedelete(id=0, title,msg="") {
183+
if(id!=0)
184+
{
185+
el = document.getElementById(id);
186+
el.remove();
187+
}
169188

170-
el.remove();
171189
let notes_array = JSON.parse(localStorage.getItem("notes"));
172190
temp = notes_array;
173191
temp.forEach(function key_popper(ab, ind) {
@@ -231,41 +249,44 @@ function unique_notes_verifier() {
231249

232250

233251
let noteselm = JSON.parse(localStorage.getItem("notes"));
234-
try
252+
if(noteselm)
235253
{
236-
noteselm.forEach(function note_data_extractor(note, ind) {
237-
for (var title in note)
238-
{
254+
try
255+
{
256+
noteselm.forEach(function note_data_extractor(note, ind) {
257+
for (var title in note)
258+
{
259+
260+
if(title.toLowerCase()==input.toLowerCase())
261+
{
262+
263+
error_message_shower("Title Already Exist");
264+
throw "Title Already Exist"
239265

240-
if(title.toLowerCase()==input.toLowerCase())
241-
{
242-
243-
error_message_shower("Title Already Exist");
244-
throw "Title Already Exist"
245266

246-
247-
}
248-
}
249-
});
250-
terror = document.getElementById("title_error");
251-
252-
terror.innerHTML = "";
253-
terror.setAttribute("style", "color: red; font-size: 12px;");
254-
t_el = document
255-
.getElementById("note_title")
256-
.setAttribute("style", "border: 1px solid green;");
257-
document
258-
.getElementById("note_data")
259-
.setAttribute("style", "border: 1px solid green;");
260-
261-
return true;
262-
}
263-
catch(err)
264-
{
265-
return false;
267+
}
268+
}
269+
});
270+
terror = document.getElementById("title_error");
271+
272+
terror.innerHTML = "";
273+
terror.setAttribute("style", "color: red; font-size: 12px;");
274+
t_el = document
275+
.getElementById("note_title")
276+
.setAttribute("style", "border: 1px solid green;");
277+
document
278+
.getElementById("note_data")
279+
.setAttribute("style", "border: 1px solid green;");
280+
281+
return true;
282+
}
283+
catch(err)
284+
{
285+
return false;
286+
}
266287
}
267-
268-
288+
else
289+
return true;
269290
}
270291
//////////////////this will clear your local storage////////////////////
271292

@@ -320,6 +341,8 @@ function note_search(e) {
320341

321342
function edit_note(id)
322343
{
344+
global_note_id = id;
345+
323346
ntitle = document.getElementById("note_title");
324347

325348
data = document.getElementById("note_data");
@@ -333,11 +356,10 @@ function edit_note(id)
333356
notesObj.forEach(function note_data_extractor(note, ind) {
334357
for (var title in note) {
335358

336-
if (ntitle.value==title) {
337-
ndata = note[title];
338-
console.log(ndata)
339-
throw "found";
340-
359+
if (ntitle.value==title)
360+
{
361+
ndata = note[title];
362+
throw "found";
341363
}
342364
}
343365
});
@@ -351,7 +373,7 @@ function edit_note(id)
351373

352374
msg="Note is in edit mode now. Don't left without saving this note otherwise it will be lost."
353375

354-
notedelete(id,note.children[0].innerText,msg);
376+
notedelete(0,note.children[0].innerText,msg);
355377

356378
}
357379

js/view.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,5 @@ function saved_notes_display2() {
8181
}
8282
});
8383
}
84-
alert_shower("success", "Note Added Succesfully");
84+
8585
}

0 commit comments

Comments
 (0)