-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtodo.js
109 lines (87 loc) · 2.63 KB
/
todo.js
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
const btn=document.querySelector(".card-body .list-group");
const clic=document.querySelector(".btn.btn-danger");
clic.addEventListener("click",run);
loads();
function run_1(e){
const li= document.createElement("li");
const text=e;
if(text==""){
// alrt("danger");
}
else{
li.textContent=text;
const a=document.createElement("a")
const i=document.createElement("i");
i.classList="fa fa-remove";
a.append(i);
a.href="#";
a.classList="delete-item";
li.append(a);
li.classList="list-group-item d-flex justify-content-between";
btn.append(li);
document.querySelector("#todo").value="";
// addTodoToStorage(text);
// alrt("success");
}
}
function run(e){
const li= document.createElement("li");
const text=document.querySelector("#todo").value.trim();
if(text==""){
alrt("danger");
}
else{
li.textContent=text;
const a=document.createElement("a")
const i=document.createElement("i");
i.classList="fa fa-remove";
a.append(i);
a.href="#";
a.classList="delete-item";
li.append(a);
li.classList="list-group-item d-flex justify-content-between";
btn.append(li);
document.querySelector("#todo").value="";
addTodoToStorage(text);
alrt("success");
}
e.preventDefault();
}
function alrt(cls){
const div=document.createElement("div");
div.classList= `alert alert-${cls}`;
div.innerHTML=" <strong>Oh snap!</strong> Change a few things up and try submitting again.";
const cardbdy=document.querySelector(".card-body");
cardbdy.append(div);
setTimeout(function(){
div.remove();
},1000);
}
function addTodoToStorage(newTodo){
let todos=getTodosFromStorage();
todos.push(newTodo);
localStorage.setItem("todos",JSON.stringify(todos));
}
function getTodosFromStorage(){//Storagedan Todoları Alma
let todos;
if(localStorage.getItem("todos")===null){
todos=[];
}
else{
todos=JSON.parse(localStorage.getItem("todos"));
}
return todos;
}
function loads(){
getTodosFromStorage().forEach(function(e){
// console.log(e)
run_1(e);
});
}
const cardbady_2=document.querySelector(".list-group .list-group-item .delete-item");
cardbady_2.addEventListener("click",runs);
function runs(e){
if(e.target.classList="delete-item"){
e.target.remove();
}
}