1
1
/////////////////// getting the note container/////////////////
2
2
main_container = document . querySelector ( ".note_container" ) ;
3
+
4
+ ////////////////making storenote as a default and unchangeble option/////////////////
3
5
document . getElementById ( "storenote" ) . checked = true ;
4
6
document . getElementById ( "storenote" ) . disabled = true ;
5
7
///////////////////////fetching the value on startup////////////////
6
8
fetchnote_value = localStorage . getItem ( "fetchnote" ) ;
7
9
8
10
if ( fetchnote_value == "true" ) {
9
11
document . getElementById ( "fetchnote" ) . checked = true ;
12
+
10
13
saved_notes_display ( ) ;
11
14
} else {
12
15
document . getElementById ( "fetchnote" ) . checked = false ;
@@ -36,26 +39,59 @@ function save_to_local(checker, title, data) {
36
39
}
37
40
}
38
41
}
39
- function error_message_shower ( title = 0 , data = 0 ) {
42
+ function error_message_shower ( title = "" , data = "" ) {
40
43
////////////error message shower
41
- if ( title ) {
42
- terror = document . getElementById ( "title_error" ) ;
44
+ terror = document . getElementById ( "title_error" ) ;
45
+ derror = document . getElementById ( "data_error" ) ;
46
+ if ( title != "" && data != "" ) {
47
+
43
48
terror . innerHTML = title ;
44
49
terror . setAttribute ( "style" , "color: red; font-size: 12px;" ) ;
45
50
t_el = document
46
51
. getElementById ( "note_title" )
47
52
. setAttribute ( "style" , "border: 1px solid red;" ) ;
53
+ derror . innerHTML = data ;
54
+ derror . setAttribute ( "style" , "color: red; font-size: 12px;" ) ;
55
+ d_el = document
56
+ . getElementById ( "note_data" )
57
+ . setAttribute ( "style" , "border: 1px solid red;" ) ;
48
58
}
49
-
50
- if ( data ) {
51
- derror = document . getElementById ( "data_error" ) ;
52
-
59
+ else if ( title != "" && data == "" )
60
+ {
61
+ derror . innerHTML = data ;
62
+ d_el = document
63
+ . getElementById ( "note_data" )
64
+ . setAttribute ( "style" , "border: 1px solid green;" ) ;
65
+ terror . innerHTML = title ;
66
+ terror . setAttribute ( "style" , "color: red; font-size: 12px;" ) ;
67
+ t_el = document
68
+ . getElementById ( "note_title" )
69
+ . setAttribute ( "style" , "border: 1px solid red;" ) ;
70
+ }
71
+ else if ( title == "" && data != "" ) {
72
+
73
+ terror . innerHTML = ""
74
+ t_el = document
75
+ . getElementById ( "note_title" )
76
+ . setAttribute ( "style" , "border: 1px solid green;" ) ;
53
77
derror . innerHTML = data ;
54
78
derror . setAttribute ( "style" , "color: red; font-size: 12px;" ) ;
55
79
d_el = document
56
80
. getElementById ( "note_data" )
57
81
. setAttribute ( "style" , "border: 1px solid red;" ) ;
58
82
}
83
+ else if ( title == "" && data == "" ) {
84
+
85
+ terror . innerHTML = ""
86
+ t_el = document
87
+ . getElementById ( "note_title" )
88
+ . setAttribute ( "style" , "border: 1px solid green;" ) ;
89
+
90
+ derror . innerHTML = ""
91
+ d_el = document
92
+ . getElementById ( "note_data" )
93
+ . setAttribute ( "style" , "border: 1px solid green;" ) ;
94
+ }
59
95
}
60
96
//main function which check for the value and wil raise error if founc empty
61
97
function data_validator ( ) {
@@ -64,21 +100,30 @@ function data_validator() {
64
100
storenote = document . getElementById ( "storenote" ) . checked ;
65
101
document . getElementById ( "note_title" ) ;
66
102
67
- if ( title_el == "" ) {
68
- error_message_shower ( "Note Title Can't Empty" , false ) ;
103
+ if ( title_el == "" && data_el == "" ) {
104
+
105
+ error_message_shower ( "Note Title Can't Empty" , "Note Data Can't be Empty" ) ;
69
106
}
70
- if ( data_el == "" ) {
71
- error_message_shower ( false , "Note Data Can't be Empty" ) ;
72
- } else {
107
+ else if ( title_el == "" && data_el != "" ) {
108
+ error_message_shower ( "Note Title Can't Empty" , "" ) ;
109
+ }
110
+ else if ( title_el != "" && data_el == "" ) {
111
+
112
+ error_message_shower ( "" , "Note Data Can't be Empty" ) ;
113
+ }
114
+ else {
73
115
if ( unique_notes_verifier ( ) )
74
- { add_note ( title_el , data_el ) ;
75
- save_to_local ( storenote , title_el , data_el ) ; }
116
+ {
117
+ add_note ( title_el , data_el ) ;
118
+ save_to_local ( storenote , title_el , data_el ) ;
119
+ alert_shower ( "success" , "Note Added Succesfully" ) ;
120
+ }
76
121
}
77
122
}
78
123
//////////////add note fuction ////////////////////////
79
124
function add_note ( title_el , data_el ) {
80
125
notes_count = document . querySelectorAll ( ".note" ) . length ; // returns total created notes
81
-
126
+
82
127
note_card = document . createElement ( "div" ) ;
83
128
note_card . className = "note" ;
84
129
note_card . id = `${ notes_count + 1 } ` ; //for giving unique id to every note
@@ -104,12 +149,14 @@ function add_note(title_el, data_el) {
104
149
</div>` ;
105
150
106
151
document . getElementById ( `${ notes_count + 1 } ` ) . innerHTML = html ; //adding the html for the proper view
107
- alert_shower ( "success" , "Note Added Succesfully" ) ;
152
+
108
153
}
154
+
155
+
109
156
//////////////////////the delete function. This will remove note from dom and also from localstorage if the note is previously saved in local storage ////////////////////
110
- function notedelete ( id , title ) {
157
+ function notedelete ( id , title , msg = "" ) {
111
158
el = document . getElementById ( id ) ;
112
- // note_title = el.children[0].children[1].children[0].innerHTML;
159
+
113
160
el . remove ( ) ;
114
161
let notes_array = JSON . parse ( localStorage . getItem ( "notes" ) ) ;
115
162
temp = notes_array ;
@@ -123,8 +170,15 @@ function notedelete(id, title) {
123
170
return false ;
124
171
} ) ;
125
172
localStorage . setItem ( "notes" , JSON . stringify ( notes_array ) ) ;
173
+ if ( msg != "" )
174
+ {
175
+ alert_shower ( "success" , msg ) ;
176
+ }
177
+ else
126
178
alert_shower ( "success" , "No deleted Succesfully" ) ;
127
179
}
180
+
181
+
128
182
///////////////////////saved notes display//////////////////////////
129
183
function saved_notes_display ( ) {
130
184
let noteselm = JSON . parse ( localStorage . getItem ( "notes" ) ) ;
@@ -135,32 +189,37 @@ function saved_notes_display() {
135
189
all_note_in_dom . forEach ( function ( note , ind ) {
136
190
all_dom_notes_title . push ( note . innerHTML ) ;
137
191
} ) ;
138
-
192
+
193
+ if ( all_notes_in_dom . length > 0 )
194
+ {
195
+ alert_shower ( "success" , "Notes Already Added" ) ;
196
+ return ;
197
+
198
+ }
139
199
if ( ! noteselm . length ) {
200
+
140
201
alert_shower ( "danger" , "No Notes Found" ) ;
141
202
} else {
142
203
notesObj = noteselm ;
143
204
144
205
notesObj . forEach ( function note_data_extractor ( note , ind ) {
145
206
for ( var title in note ) {
146
- let chk = 0 ;
207
+
147
208
if ( ! all_dom_notes_title . length ) {
148
209
data = note [ title ] ;
149
210
add_note ( title , data ) ;
150
211
}
151
212
}
152
213
} ) ;
153
214
}
154
- if ( all_dom_notes_title . length )
155
- {
156
- alert_shower ( "success" , "Notes Already Added" ) ;
157
- }
215
+ alert_shower ( "success" , "Note Added Succesfully" ) ;
158
216
}
217
+ /////////////////////verify if it is in local storage///////////////////
159
218
function unique_notes_verifier ( ) {
160
219
161
220
input = document . getElementById ( "note_title" ) . value ;
162
221
163
- /////////////////////verify if it is in dom///////////////////
222
+
164
223
let noteselm = JSON . parse ( localStorage . getItem ( "notes" ) ) ;
165
224
try
166
225
{
@@ -199,10 +258,12 @@ function unique_notes_verifier() {
199
258
200
259
}
201
260
//////////////////this will clear your local storage////////////////////
261
+
202
262
function localStorage_clear ( ) {
203
263
localStorage . clear ( ) ;
204
264
alert_shower ( "danger" , "Local Storage Cleared" ) ;
205
265
}
266
+
206
267
///////////////////bootstrap alert shower/////////////////////////////
207
268
function alert_shower ( type , msg ) {
208
269
el = document . getElementById ( "alert" ) ;
@@ -218,13 +279,19 @@ function alert_shower(type, msg) {
218
279
seconds = 1 ;
219
280
220
281
let interval_id = setInterval ( function ( ) {
221
- if ( seconds == 5 ) {
282
+
283
+ if ( seconds == 8 )
284
+ {
222
285
el . style . display = "none" ;
223
286
clearInterval ( interval_id ) ;
224
- } else {
287
+ }
288
+ else
289
+ {
290
+
225
291
seconds += 1 ;
292
+
226
293
}
227
- } , 1000 ) ;
294
+ } , 1000 ) ;
228
295
}
229
296
////////////////////////////////search function///////////////////////////////
230
297
@@ -235,7 +302,6 @@ function note_search(e) {
235
302
for ( i = 0 ; i < cards . length ; i ++ ) {
236
303
if ( cards [ i ] . innerHTML . toLowerCase ( ) . indexOf ( input ) > - 1 ) {
237
304
cards [ i ] . parentNode . parentNode . style . display = "" ;
238
- console . log ( cards [ i ] . parentNode . parentNode ) ;
239
305
} else {
240
306
cards [ i ] . parentNode . parentNode . style . display = "none" ;
241
307
}
@@ -252,33 +318,11 @@ function edit_note(id)
252
318
253
319
title . value = note . children [ 0 ] . innerText ;
254
320
data . value = note . children [ 1 ] . innerText ;
255
-
256
- addbtn = document . getElementById ( "addbtn" ) ;
257
-
258
- savebtn = document . createElement ( 'button' ) ;
259
- savebtn . innerHTML = "Save Note"
260
- savebtn . setAttribute ( 'id' , "savebtn" )
261
- savebtn . setAttribute ( 'class' , "btn btn-dark" )
262
- savebtn . setAttribute ( 'onclick' , "edit_save()" )
263
- addbtn . replaceWith ( savebtn ) ;
264
-
265
-
266
-
267
-
321
+ msg = "Note is in edit mode now. Don't left without saving this note otherwise it will be lost."
322
+ notedelete ( id , note . children [ 0 ] . innerText , msg ) ;
268
323
269
324
}
270
- function edit_save ( )
271
- {
272
- oldnote = document . getElementById ( id ) . children [ 0 ] ;
273
- title = document . getElementById ( "note_title" ) . value ;
274
-
275
- data = document . getElementById ( "note_data" ) . value ;
276
- let noteselm = JSON . parse ( localStorage . getItem ( "notes" ) ) ;
277
- console . log ( noteselm )
278
- savebtn . replaceWith ( addbtn )
279
325
280
-
281
- }
282
326
//////////////////////////////////////text transition using anime.js/////////////////////////////////////////
283
327
284
328
var textWrapper = document . querySelector ( ".ml3" ) ;
0 commit comments