-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
42 lines (40 loc) · 1.56 KB
/
script.js
File metadata and controls
42 lines (40 loc) · 1.56 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
let tasks = 0;
document.getElementById("newTaskForm").addEventListener("submit", function (e) {
e.preventDefault();
const data = new FormData(this);
const task = data.get("input");
if (task) {
tasks++;
const taskItem = document.getElementById("taskItemElement").cloneNode(true);
taskItem.id = "";
taskItem.querySelector(".unfinishedTaskContent").innerText = task;
taskItem.querySelector(".finishedTaskContent").innerText = task;
taskItem.querySelector(".taskItem.checkbox").addEventListener("click", function () {
if (this.checked) {
tasks--;
taskItem.querySelector(".finishedTaskContent").style.display = "revert";
taskItem.querySelector(".unfinishedTaskContent").style.display = "none";
} else {
tasks++;
taskItem.querySelector(".finishedTaskContent").style.display = "none";
taskItem.querySelector(".unfinishedTaskContent").style.display = "revert";
}
});
document.getElementById("tasksZone").appendChild(taskItem);
}
document.getElementById("newTaskForm").querySelector("input[name='input']").value = "";
});
setInterval(function () {
if (tasks <= 0) {
tasks = 0;
document.getElementById("noTask").style.display = "flex";
} else {
document.getElementById("noTask").style.display = "none";
}
});
window.addEventListener("beforeunload", function (e) {
if (tasks > 0) {
e.preventDefault();
e.returnValue();
}
})