-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
177 lines (152 loc) · 5.47 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>To-Do List</title>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css" integrity="sha384-DyZ88mC6Up2uqS4h/KRgHuoeGwBcD4Ng9SiP4dIRy0EXTlnuz47vAwmeGwVChigm" crossorigin="anonymous">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link
href="https://fonts.googleapis.com/css2?family=Licorice&family=Montserrat:wght@100&family=Permanent+Marker&family=Roboto:wght@300&family=Shadows+Into+Light&display=swap"
rel="stylesheet">
<style>
html{
font-size: 24px;
}
body {
font-family: 'Shadows Into Light', cursive;
}
.done > span{
text-decoration: line-through; /*done içindeki spanın altını çiz*/
}
.container {
background-color: rgb(234, 255, 221);
max-width: 900px;
margin: 5rem auto;
padding: 1rem;
box-shadow: blue 0px 0px 0px 2px inset, rgb(255, 255, 255) 10px -10px 0px -3px, rgb(31, 193, 27) 10px -10px, rgb(255, 255, 255) 20px -20px 0px -3px, rgb(255, 217, 19) 20px -20px, rgb(255, 255, 255) 30px -30px 0px -3px, rgb(255, 156, 85) 30px -30px, rgb(255, 255, 255) 40px -40px 0px -3px, rgb(255, 85, 85) 40px -40px;
}
@media(max-width: 940px){
.container{
margin: 1rem;
}
}
ul {
list-style: none;
padding: 0;
}
ul>li {
line-height: 2;
/*satır yüksekliği fontun 2 katı*/
display: flex;
align-items: center;
}
.delete{
margin-left: auto; /*çöpkutusunu sağa gönderdik*/
margin-right: .5rem; /*sağa tam dayanmasın diye*/
cursor: pointer;
display: none;/*çöpkutusu görünmeyecek*/
}
ul>li:hover .delete{/*çöpkutusu üzerine gelinen satır ile görülecek*/
display: inline;
}
ul>li:nth-child(even) {
background-color: rgb(235, 193, 235);
}
input[type="checkbox"] {
margin-right: .5rem;
}
input[type="text"] {
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
button {
background-color: #6fb472;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
}
</style>
</head>
<body>
<div class="container">
<h1>Todos</h1>
<form id="frmNew">
<input id="txtTask" type="text" autocomplete="off" required placeholder="Type something to do.."/>
<button>Add</button>
</form>
<ul id="todos"></ul>
</div>
<script>
var todos = [];
var ulTodos = document.getElementById("todos");
var frm = document.getElementById("frmNew");
var txt = document.getElementById("txtTask");
function listTodos() {
todos.sort((a, b) => a.isDone - b.isDone);
save();
ulTodos.innerHTML = "";
for (var todo of todos) {
var li = document.createElement("li");
if (todo.isDone) {
li.classList.add("done");
}
li.todo = todo;
var chk = document.createElement("input");
chk.onchange = statusChanged;
chk.checked = todo.isDone;
chk.type = "checkbox";
li.appendChild(chk);
var span = document.createElement("span");
span.textContent = todo.task;
li.append(span);
var btn = document.createElement("i");
btn.onclick = deleteClicked; /*çöpkutusuna basıldığında deleteClicked fonks.ya kullanılacak*/
btn.classList.add("fas");
btn.classList.add("fa-trash-alt");
btn.classList.add("delete");
li.appendChild(btn);
ulTodos.appendChild(li);
}
}
function deleteClicked(){
var todo = this.parentNode.todo;
//todos'dan sil
var index = todos.indexOf(todo);
todos.splice(index,1); /*index'ine sahip todo dan itibaren 1 adet sil*/
listTodos();
}
function statusChanged() {
this.parentNode.todo.isDone = this.checked;
listTodos();
}
function save() {
localStorage["data"] = JSON.stringify(todos);
}
function load() {
try {
todos = JSON.parse(localStorage["data"]);
} catch (error) {
todos = [{ task: "Do your homework", isDone: false }, { task: "Watch Netflix", isDone: true }];
}
}
frm.onsubmit = function (event) {
event.preventDefault();
var task = txt.value;
todos.unshift({ task: task, isDone: false });
listTodos();
txt.value = "";
};
load();
listTodos();
</script>
</body>
</html>