-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
132 lines (109 loc) · 3.85 KB
/
script.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
let themeButton = document.querySelector("#theme");
themeButton.addEventListener("click", function changeTheme() {
document.body.classList.toggle("dark-theme");
if (document.body.classList.contains("dark-theme")) {
themeButton.innerHTML = "Light mode?";
} else {
themeButton.innerHTML = "Dark mode?";
}
});
function currentDate() {
let dateDisplay = document.querySelector("#date");
let now = new Date();
let daysofWeek = [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
];
let day = daysofWeek[now.getDay()];
let hour = now.getHours();
let minute = now.getMinutes();
let date = now.getDate();
let month = now.getMonth() + 1;
let year = now.getFullYear();
if (hour > 12) {
hour = hour - 12;
dateDisplay.innerHTML = `${day}, ${hour}:${minute} PM
<br />
${date}/${month}/${year}`;
} else if ((hour = 12)) {
dateDisplay.innerHTML = `${day}, 12:${minute} PM
<br />
${date}/${month}/${year}`;
} else {
dateDisplay.innerHTML = `${day}, ${hour}:${minute} AM
<br />
${date}/${month}/${year}`;
}
}
function formActions(event) {
event.preventDefault();
let formInput = document.querySelector("#new-task-input");
let taskList = document.querySelector("#tasks");
let task = formInput.value;
if (task.length < 1) {
alert("Please write something");
return;
}
let task_el = document.createElement("div");
task_el.classList.add("task");
let task_content_el = document.createElement("div");
task_content_el.classList.add("content");
let task_input_el = document.createElement("input");
task_input_el.classList.add("text");
task_input_el.type = "text";
task_input_el.value = task;
task_input_el.maxLength = "70";
task_input_el.setAttribute("readonly", "readonly");
let task_actions_el = document.createElement("div");
task_actions_el.classList.add("actions");
let task_done_el = document.createElement("button");
task_done_el.classList.add("done");
task_done_el.innerHTML = `<i class="fa-regular fa-square"></i>`;
let task_edit_el = document.createElement("button");
task_edit_el.classList.add("edit");
task_edit_el.innerHTML = `<i class="fa-solid fa-pencil"></i>`;
let task_delete_el = document.createElement("button");
task_delete_el.classList.add("delete");
task_delete_el.innerHTML = `<i class="fa-solid fa-circle-xmark"></i>`;
task_el.appendChild(task_done_el);
taskList.appendChild(task_el);
task_el.appendChild(task_content_el);
task_content_el.appendChild(task_input_el);
task_el.appendChild(task_actions_el);
task_actions_el.appendChild(task_edit_el);
task_actions_el.appendChild(task_delete_el);
formInput.value = "";
task_edit_el.addEventListener("click", function editButton() {
if (task_edit_el.innerHTML == `<i class="fa-solid fa-pencil"></i>`) {
task_edit_el.innerHTML = `<i class="fa-solid fa-sd-card"></i>`;
task_input_el.removeAttribute("readonly");
task_input_el.focus();
} else {
task_input_el.setAttribute("readonly", "readonly");
task_edit_el.innerHTML = `<i class="fa-solid fa-pencil"></i>`;
}
});
task_done_el.addEventListener("click", function doneButton() {
if (task_done_el.innerHTML == `<i class="fa-regular fa-square"></i>`) {
task_done_el.innerHTML = `<i class="fa-regular fa-square-check"></i>`;
task_input_el.classList.add("strike-through");
} else {
task_done_el.innerHTML = `<i class="fa-regular fa-square"></i>`;
task_input_el.classList.remove("strike-through");
}
});
task_delete_el.addEventListener("click", function deleteButton() {
taskList.removeChild(task_el);
});
}
function gettingHTML() {
let form = document.querySelector("#new-task-form");
form.addEventListener("submit", formActions);
}
window.addEventListener("load", gettingHTML);
currentDate();