1
1
/////////////////// getting the note container/////////////////
2
2
main_container = document . querySelector ( ".note_container" ) ;
3
-
3
+ var global_note_id = 0 ;
4
4
////////////////making storenote as a default and unchangeble option/////////////////
5
5
if ( document . getElementById ( "storenote" ) )
6
6
{
@@ -122,6 +122,7 @@ function data_validator() {
122
122
error_message_shower ( "" , "Note Data Can't be Empty" ) ;
123
123
}
124
124
else {
125
+
125
126
if ( unique_notes_verifier ( ) )
126
127
{
127
128
add_note ( title_el , data_el ) ;
@@ -132,6 +133,19 @@ function data_validator() {
132
133
}
133
134
//////////////add note fuction ////////////////////////
134
135
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
+
135
149
notes_count = document . querySelectorAll ( ".note" ) . length ; // returns total created notes
136
150
137
151
note_card = document . createElement ( "div" ) ;
@@ -159,15 +173,19 @@ function add_note(title_el, data_el) {
159
173
</div>` ;
160
174
161
175
document . getElementById ( `${ notes_count + 1 } ` ) . innerHTML = html ; //adding the html for the proper view
176
+ }
162
177
163
178
}
164
179
165
180
166
181
//////////////////////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
+ }
169
188
170
- el . remove ( ) ;
171
189
let notes_array = JSON . parse ( localStorage . getItem ( "notes" ) ) ;
172
190
temp = notes_array ;
173
191
temp . forEach ( function key_popper ( ab , ind ) {
@@ -231,41 +249,44 @@ function unique_notes_verifier() {
231
249
232
250
233
251
let noteselm = JSON . parse ( localStorage . getItem ( "notes" ) ) ;
234
- try
252
+ if ( noteselm )
235
253
{
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"
239
265
240
- if ( title . toLowerCase ( ) == input . toLowerCase ( ) )
241
- {
242
-
243
- error_message_shower ( "Title Already Exist" ) ;
244
- throw "Title Already Exist"
245
266
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
+ }
266
287
}
267
-
268
-
288
+ else
289
+ return true ;
269
290
}
270
291
//////////////////this will clear your local storage////////////////////
271
292
@@ -320,6 +341,8 @@ function note_search(e) {
320
341
321
342
function edit_note ( id )
322
343
{
344
+ global_note_id = id ;
345
+
323
346
ntitle = document . getElementById ( "note_title" ) ;
324
347
325
348
data = document . getElementById ( "note_data" ) ;
@@ -333,11 +356,10 @@ function edit_note(id)
333
356
notesObj . forEach ( function note_data_extractor ( note , ind ) {
334
357
for ( var title in note ) {
335
358
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" ;
341
363
}
342
364
}
343
365
} ) ;
@@ -351,7 +373,7 @@ function edit_note(id)
351
373
352
374
msg = "Note is in edit mode now. Don't left without saving this note otherwise it will be lost."
353
375
354
- notedelete ( id , note . children [ 0 ] . innerText , msg ) ;
376
+ notedelete ( 0 , note . children [ 0 ] . innerText , msg ) ;
355
377
356
378
}
357
379
0 commit comments