-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
103 lines (70 loc) · 3.19 KB
/
main.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
window.addEventListener('load', ()=>{
const form= document.querySelector("#task-form");
const input= document.querySelector("#task-input");
const list= document.querySelector("#tasks");
form.addEventListener('submit', (e)=>{
e.preventDefault();
const task = input.value;
if (!task) {
return;
}
const task_div = document.createElement("div");
task_div.classList.add("task");
list.appendChild(task_div);
const task_content_div = document.createElement("div");
task_content_div.classList.add("content");
task_div.appendChild(task_content_div);
const task_input= document.createElement("input");
task_input.classList.add("text");
task_input.type = "text";
task_input.value= task;
task_input.setAttribute("readonly", "readonly");
task_content_div.appendChild(task_input);
const task_actions_div= document.createElement("div");
task_actions_div.classList.add("actions");
task_div.appendChild(task_actions_div);
const task_edit_botton= document.createElement("button");
task_edit_botton.classList.add("Edit");
task_edit_botton.innerHTML = "Edit";
const task_delete_button= document.createElement("button");
task_delete_button.classList.add("Delete");
task_delete_button.innerHTML = "Delete";
const task_completed_button= document.createElement("button");
task_completed_button.classList.add("Completed");
task_completed_button.innerHTML = "Completed";
task_actions_div.appendChild(task_edit_botton);
task_actions_div.appendChild(task_completed_button);
task_actions_div.appendChild(task_delete_button);
task_edit_botton.addEventListener('click', ()=>{
if (task_edit_botton.innerText.toLowerCase() =="edit") {
task_input.removeAttribute("readonly");
task_input.focus();
task_edit_botton.innerText = "Save";
task_input.style.textDecoration="none"
}else{
task_input.setAttribute("readonly", "readonly");
task_edit_botton.innerText ="Edit";
}
});
task_delete_button.addEventListener('click', ()=>{
if (confirm("Are you sure you want to delete this task?")) {
list.removeChild(task_div);
}
})
task_completed_button.addEventListener('click', ()=>{
task_input.style.textDecoration="line-through";
task_input.setAttribute("readonly", "readonly");
})
input.value = "";
});
});
const progressbar = document.querySelector(".progress");
const changeProgress = (progress) => {
progressbar.style.width = `${progress}%`;
};
/* change progress after 1 second (only for showcase) */
setTimeout(() => changeProgress(22), 1000);
setTimeout(() => changeProgress(45), 2000);
setTimeout(() => changeProgress(85), 4600);
setTimeout(() => changeProgress(98), 5266);
setTimeout(() => changeProgress(100), 8000);