-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathto-do.js
85 lines (74 loc) · 2.78 KB
/
to-do.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
console.log("Welcome to my To-Do List App");
const container = document.querySelector(".todo-body");
const list = document.querySelector(".list");
const body = document.body;
const newTask = document.querySelector(".new-task");
const icon = container.querySelectorAll("i");
let clickCount = 0;
let bodyBackgroundColor = window.getComputedStyle(
document.body
).backgroundColor;
const initializeTask = () => {
clickCount++;
newTask.innerHTML = `<input type="text" class="task-info" placeholder="enter your task"><button class="submit" type="submit">Enter</button>`;
const submitBtn = document.querySelector(".submit");
submitBtn.addEventListener("click", () => {
const taskInfo = document.querySelector(".task-info");
const element = document.createElement("li");
element.innerHTML = `<li class="list-item"><div><i class="fa-regular fa-circle fa-xl check"></i>
<p class="content">${taskInfo.value}</p>
</div><i class="fa-solid fa-xmark cross" onclick="deleteItem(event)"></i>
</li><hr>`;
list.appendChild(element);
newTask.innerHTML =
'<i class="fa-solid fa-plus fa-xl" onclick="initializeTask()"></i><p>New Task</p>';
});
};
list.addEventListener("click", (event) => {
const check = event.target.closest(".check");
if (check) {
const content = check.nextElementSibling;
check.className = check.classList.contains("fa-circle")
? "fa-regular fa-circle-check fa-xl check"
: "fa-regular fa-circle fa-xl check";
content.classList.toggle("checked");
const parent = check.parentNode;
const elementParent = parent.parentNode;
const hrElement = elementParent.querySelector(".cross");
const hrLine = elementParent.nextElementSibling;
setTimeout(() => {
elementParent.remove();
hrElement.remove();
hrLine.remove();
}, 100);
}
});
const mode = document.querySelector(".dark-mode");
mode.addEventListener("click", () => {
mode.className = mode.classList.contains("fa-moon")
? "fa-regular fa-sun fa-xl dark-mode"
: "fa-regular fa-moon fa-xl dark-mode";
bodyBackgroundColor === "rgb(255, 255, 255)" ? darkMode() : whiteMode();
});
const darkMode = () => {
console.log("Dark mode");
bodyBackgroundColor = "#162029";
body.style.backgroundColor = bodyBackgroundColor;
document.body.style.color = "#fff";
container.style.backgroundColor = "#333e4a";
};
const whiteMode = () => {
console.log("White mode");
bodyBackgroundColor = "rgb(255, 255, 255)";
body.style.backgroundColor = bodyBackgroundColor;
document.body.style.color = "#000";
container.style.backgroundColor = "#f2f2f2";
};
const deleteItem = (event) => {
const del = event.target.closest(".cross");
console.log(del);
const parent = del.parentNode;
const hrElement = parent.nextElementSibling;
parent.remove();
hrElement.remove();
};