-
Notifications
You must be signed in to change notification settings - Fork 384
Expand file tree
/
Copy pathapp.js
More file actions
220 lines (162 loc) · 4.3 KB
/
app.js
File metadata and controls
220 lines (162 loc) · 4.3 KB
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
function myFunction() {
var d = new Date();
console.log(d);
var weekday = new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thrusday";
weekday[5]="Friday";
weekday[6]="Saturday";
var month = new Array(11);
month[0] = "Jan";
month[1] = "Feb";
month[2] = "Mar";
month[3] = "April";
month[4] = "May";
month[5] = "June";
month[6] = "July";
month[7] = "Aug";
month[8] = "Sept";
month[9] = "Oct";
month[10] = "Nov";
month[11] = "Dec";
var mon = month[d.getMonth()];
var day = weekday[d.getDay()];
var date = d.getDate();
document.getElementById("date").innerHTML = day +", "+ mon + " "+date ;
}
myFunction();
function showTime(){
var date = new Date();
var h = date.getHours(); // 0 - 23
var m = date.getMinutes(); // 0 - 59
var session = "AM";
if(h == 0){
h = 12;
}
if(h > 12){
h = h - 12;
session = "PM";
}
h = (h < 10) ? "0" + h : h;
m = (m < 10) ? "0" + m : m;
var time = h + ":" + m + ":" + " " + session;
document.getElementById("MyClockDisplay").innerText = time;
document.getElementById("MyClockDisplay").textContent = time;
setTimeout(showTime, 1000);
}
showTime();
// showing data in todolist
const clear = document.querySelector(".clear");
const list= document.getElementById("list");
const input=document.getElementById('input');
const check = "fa-check-circle";
const uncheck = "fa-circle-thin";
const linethrough="lineThrough";
let LIST, id;
//get item
let data = localStorage.getItem("storeitem");
if(data)
{
LIST =JSON.parse(data);
id=LIST.length;
loadList(LIST);
}
else{
LIST=[];
id=0;
}
function loadList(array){
array.forEach(function(item){
add(item.name,item.id,item.done,item.trash);
});
}
//clear
clear.addEventListener("click",function(){
localStorage.clear();
location.reload();
})
function add(todo,id,done,trash){
if(trash){
return;
}
const don = done ? check:uncheck;
const line = done ? linethrough:"";
const item = `<li class="item">
<i class="fa ${don} co" job="complete" id="${id}"></i>
<p class="text ${line}">${todo}</p>
<i class="fa fa-trash-o de" job="delete" id="${id}"></i>
</li>`;
const position="beforeend";
list.insertAdjacentHTML(position, item);
}
document.addEventListener("keyup",function(even){
if(event.keyCode==13)
{
const todo = input.value;
if(todo=="")
{
alert('ERROR :Please Input a task')
}
if(todo)
{
add(todo, id, false,false);
LIST.push({
name:todo,
id:id,
done:false,
trash:false
});
localStorage.setItem("storeitem",JSON.stringify(LIST));
id++;
}
input.value="";
}
});
const btu= document.getElementById('foo');
btu.addEventListener("click",function(cgata){
const todo = input.value;
if(todo=="")
{
alert('ERROR :Please Input a task')
}
if(todo)
{
add(todo, id, false,false);
LIST.push({
name:todo,
id:id,
done:false,
trash:false
});
id++;
}
input.value="";
})
function completeto(element)
{
element.classList.toggle(check);
element.classList.toggle(uncheck);
element.parentNode.querySelector(".text").classList.toggle(linethrough);
LIST[element.id].done =LIST[element.id].done?false:true;
}
function removeto(element)
{
element.parentNode.parentNode.removeChild(element.parentNode);
LIST[element.id].trash=true;
}
list.addEventListener("click",function(event){
const element = event.target;
const elementjob = element.attributes.job.value;
if(elementjob=="complete")
{
completeto(element);
}
else if(elementjob=="delete")
{
removeto(element);
}
localStorage.setItem("storeitem",JSON.stringify(LIST));
});