-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
124 lines (90 loc) · 4.39 KB
/
index.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
window.addEventListener("load", () => {
const form = document.querySelector("#todo-form");
const input = document.querySelector("#todo-form-text");
const todosElements = document.querySelector("#todos-to-do");
const todosDoneElements = document.querySelector("#todos-done");
form.addEventListener("submit", (e) => {
e.preventDefault();
const inputNewValue = input.value;
if(inputNewValue == ""){
alert("Please fill 'What you wanna do?'");
return;
}
const todoElement = document.createElement("div");
todoElement.classList.add("todo");
const todoContentElement = document.createElement("div");
todoContentElement.classList.add("content");
const todoContentChange = document.createElement("i");
todoContentChange.classList.add("fas");
todoContentChange.classList.add("fa-check");
todoContentChange.classList.add("check");
const todoContentInput = document.createElement("input");
todoContentInput.classList.add("todo-text");
todoContentInput.type = "text";
todoContentInput.value = inputNewValue;
todoContentInput.setAttribute("readonly", "readonly");
const todoContentEdit = document.createElement("i");
todoContentEdit.classList.add("fas");
todoContentEdit.classList.add("fa-pencil");
todoContentEdit.classList.add("pencil");
const todoContentTrash = document.createElement("i");
todoContentTrash.classList.add("fas");
todoContentTrash.classList.add("fa-trash-can");
todoContentTrash.classList.add("trash");
const todoContentReply = document.createElement("i");
todoContentReply.classList.add("fas");
todoContentReply.classList.add("fa-reply");
todoContentReply.classList.add("reply");
const todoContentDisk = document.createElement("i");
todoContentDisk.classList.add("fas");
todoContentDisk.classList.add("fa-floppy-disk");
todoContentDisk.classList.add("disk");
todoContentElement.appendChild(todoContentChange);
todoContentElement.appendChild(todoContentInput);
todoContentElement.appendChild(todoContentEdit);
todoContentElement.appendChild(todoContentTrash);
todoElement.appendChild(todoContentElement);
todosElements.appendChild(todoElement);
input.value = "";
todoContentEdit.addEventListener("click", () => {
if (todoContentEdit.classList.contains("pencil")) {
todoContentInput.removeAttribute("readonly");
todoContentInput.focus();
todoContentEdit.classList.remove("fa-pencil");
todoContentEdit.classList.remove("pencil");
todoContentEdit.classList.add("fa-floppy-disk");
todoContentEdit.classList.add("disk");
} else {
todoContentInput.setAttribute("readonly", "readonly");
todoContentEdit.classList.remove("fa-floppy-disk");
todoContentEdit.classList.remove("disk");
todoContentEdit.classList.add("fa-pencil");
todoContentEdit.classList.add("pencil");
}
});
todoContentTrash.addEventListener("click", () => {
if(todoElement.parentElement.id == "todos-to-do"){
todosElements.removeChild(todoElement);
}else{
todosDoneElements.removeChild(todoElement);
}
});
todoContentChange.addEventListener("click", () => {
if (todoContentChange.classList.contains("check")) {
todosElements.removeChild(todoElement);
todoContentChange.classList.remove("fa-check");
todoContentChange.classList.remove("check");
todoContentChange.classList.add("fa-reply");
todoContentChange.classList.add("reply");
todosDoneElements.appendChild(todoElement);
} else {
todosDoneElements.removeChild(todoElement);
todoContentChange.classList.remove("fa-reply");
todoContentChange.classList.remove("reply");
todoContentChange.classList.add("fa-check");
todoContentChange.classList.add("check");
todosElements.appendChild(todoElement);
}
});
});
});