1
- function note_layout_creater ( title , text )
1
+
2
+ main_container = document . querySelector ( '.note_container' ) ;
3
+
4
+ function save_to_local ( checker , title , data )
2
5
{
6
+ if ( checker )
7
+ {
3
8
4
- note_card = document . createElement ( 'div' )
5
- note_card . className = "note" ;
6
- let html ;
9
+ let dict = { } ;
10
+ dict [ title ] = data ;
11
+
12
+ let stored_notes = JSON . parse ( localStorage . getItem ( 'notes' ) ) ;
13
+
14
+ if ( stored_notes != null )
15
+ {
16
+ stored_notes . push ( dict ) ;
17
+ localStorage . setItem ( 'notes' , JSON . stringify ( stored_notes ) )
18
+ }
19
+ else
20
+ {
21
+ let notes_array = [ ]
22
+ notes_array . push ( dict )
23
+ localStorage . setItem ( 'notes' , JSON . stringify ( notes_array ) )
24
+ }
25
+ }
26
+ }
27
+ function error_message_shower ( title , data )
28
+ {
29
+ if ( title )
30
+ {
31
+ terror = document . getElementById ( "title_error" ) ;
32
+ terror . innerHTML = title ;
33
+ terror . setAttribute ( "style" , "color: red; font-size: 12px;" ) ;
34
+ t_el = document . getElementById ( 'note_title' ) . setAttribute ( 'style' , 'border: 1px solid red;' ) ;
35
+ }
36
+
37
+ if ( data )
38
+ {
39
+
40
+ derror = document . getElementById ( "data_error" ) ;
41
+
42
+ derror . innerHTML = data ;
43
+ derror . setAttribute ( "style" , "color: red; font-size: 12px;" ) ;
44
+ d_el = document . getElementById ( 'note_data' ) . setAttribute ( 'style' , 'border: 1px solid red;' )
45
+ }
46
+
47
+
48
+
7
49
8
- console . log ( note_card ) ;
9
- return note_card
10
50
}
11
- main_container = document . querySelector ( '.note_container' ) ;
51
+ function data_validator ( ) //main function
52
+ {
53
+
54
+ title_el = document . getElementById ( "note_title" ) . value ;
55
+ data_el = document . getElementById ( "note_data" ) . value ;
56
+ storenote = document . getElementById ( "storenote" ) . checked ;
57
+ document . getElementById ( "note_title" )
58
+
59
+
60
+ if ( title_el == "" )
61
+ {
62
+ error_message_shower ( "Note Title Can't Empty" , false )
63
+ }
64
+ if ( data_el == "" )
65
+ {
66
+ error_message_shower ( false , "Note Data Can't be Empty" ) ;
67
+ }
68
+ else
69
+ { add_note ( title_el , data_el ) ;
70
+ save_to_local ( storenote , title_el , data_el ) ;
71
+ }
12
72
13
- function add_note ( )
73
+ }
74
+ function add_note ( title_el , data_el )
14
75
{
15
- notes_count = document . querySelectorAll ( '.note' ) . length ;
16
- text = document . getElementById ( 'exampleFormControlTextarea1' ) . value ;
17
- note_card = note_layout_creater ( notes_count , text ) ;
18
- note_title = document . getElementById ( 'note_title' ) . value ;
76
+ notes_count = document . querySelectorAll ( '.note' ) . length ; // returns total created notes
77
+
19
78
20
- note_card . id = `${ notes_count + 1 } ` ;
79
+ note_card = document . createElement ( 'div' )
80
+ note_card . className = "note" ;
81
+ note_card . id = `${ notes_count + 1 } ` ; //for giving unique id to every note
21
82
22
83
main_container = document . getElementById ( 'nt' ) ;
23
84
main_container . appendChild ( note_card ) ;
24
85
html = `
25
- <div class="card text-white bg-dark mx-1 mb-3 id="${ notes_count + 1 } " style=" max-width: 18rem;">
26
- <div class="card-header row container-fluid justify-content-between" style="margin: 0px !important">Note: ${ notes_count + 1 } <i" onclick="notedelete(${ notes_count + 1 } )"style="padding: 3px 0 0 0; cursor:pointer;" class="fa fa-trash" aria-hidden="true"></i></div>
27
- <div class="card-body">
28
- <h5 class="card-title">${ note_title } </h5>
29
- <p class="card-text">${ text . slice ( 0 , 15 ) } ...</p>
86
+ <div class="card text-white bg-dark mx-1 mb-3" id="${ notes_count + 1 } " style=" max-width: 18rem;">
87
+ <div class="card-header row container-fluid justify-content-between" style="margin: 0px !important">
88
+ Note: ${ notes_count + 1 } <i" onclick="notedelete(${ notes_count + 1 } ,'${ title_el } ')"style="padding: 3px 0 0 0; cursor:pointer;" class="fa fa-trash" aria-hidden="true"></i>
89
+
90
+ </div>
91
+ <div class="card-body">
92
+ <h5 class="card-title">${ title_el } </h5>
93
+ <p class="card-text">${ data_el . slice ( 0 , 25 ) } ...</p>
94
+ </div>
30
95
</div>` ;
31
- document . getElementById ( `${ notes_count + 1 } ` ) . innerHTML = html ;
32
96
97
+ document . getElementById ( `${ notes_count + 1 } ` ) . innerHTML = html ; //adding the html for the proper view
98
+
33
99
}
34
- function notedelete ( id )
100
+ function notedelete ( id , title )
35
101
{
102
+
36
103
el = document . getElementById ( id ) ;
37
- el . remove ( )
38
- console . log ( "hello" )
39
- }
104
+ note_title = el . children [ 0 ] . children [ 1 ] . children [ 0 ] . innerHTML ;
105
+ el . remove ( ) ;
106
+ let notes_array = JSON . parse ( localStorage . getItem ( 'notes' ) ) ;
107
+ temp = notes_array ;
108
+ temp . forEach ( function key_popper ( ab , ind ) {
109
+ for ( var key in ab )
110
+ {
111
+ if ( key == title )
112
+ {
113
+ notes_array . splice ( ind , 1 ) ;
114
+
115
+ }
116
+ break ;
117
+ }
118
+ return false
119
+
120
+ } ) ;
121
+ localStorage . setItem ( 'notes' , JSON . stringify ( notes_array ) ) ;
122
+ }
123
+ // saved_notes_display()
124
+ // {
125
+ // let noteselm = localStorage.getItem('notes');
126
+ // if(notes==null)
127
+ // {
128
+ // notesObj=[];
129
+ // }
130
+ // else
131
+ // {
132
+ // notesObj = JSON.parse(notes);
133
+ // }
134
+ // }
135
+
136
+ //////////////////////////////////////text transition/////////////////////////////////////////
137
+
138
+ var textWrapper = document . querySelector ( '.ml3' ) ;
139
+ textWrapper . innerHTML = textWrapper . textContent . replace ( / \S / g, "<span class='letter'>$&</span>" ) ;
140
+
141
+ anime . timeline ( { loop : true } )
142
+ . add ( {
143
+ targets : '.ml3 .letter' ,
144
+ opacity : [ 0 , 1 ] ,
145
+ easing : "easeInOutQuad" ,
146
+ duration : 2250 ,
147
+ delay : ( el , i ) => 150 * ( i + 1 )
148
+ } ) . add ( {
149
+ targets : '.ml3' ,
150
+ opacity : 0 ,
151
+ duration : 1000 ,
152
+ easing : "easeOutExpo" ,
153
+ delay : 1000
154
+ } ) ;
0 commit comments