-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathDetailJs.js
More file actions
214 lines (158 loc) · 6.35 KB
/
DetailJs.js
File metadata and controls
214 lines (158 loc) · 6.35 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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
window.addEventListener("load" , function() {
const getLocalStorageData = getLocalStorage();
if (getLocalStorageData) {
for (let i = 0; i < getLocalStorageData.length; i++) {
showLocalStorage(getLocalStorageData[i]);
}
}
});
function insertTodo(event) {
if(event.key === 'Enter') {
setLocalStorage();
createdValue();
}
}
function createdButton (inner , className) {
const createbutton = document.createElement("button");
createbutton.innerHTML = inner;
createbutton.className = className;
return createbutton;
}
function createdInput (inner , type , className) {
const createdInput = document.createElement("input");
createdInput.inner = inner;
createdInput.type = type;
createdInput.className = className;
return createdInput;
}
function createdElement (element , inner , className) {
const createdElement = document.createElement(element);
createdElement.inner = inner;
createdElement.className = className;
return createdElement;
}
function findTopNode (event) {
const topNode = event.target.parentElement;
return topNode;
}
function createdValue() {
const input = document.querySelector('.todo-input');
const inputValue = input.value.trim();
if (inputValue === '') return;
const newLi = createdElement("li" , "newLi" , "newLi");
const createdCheckBox = createdInput("checkBox" , "checkBox" , "todoCheckBoxList");
newLi.append(createdCheckBox)
const newSpan = createdElement("span" , "newSpan" , "newSpan");
newSpan.append(inputValue);
newLi.append(newSpan)
const createdEdit = createdButton("Edit" , "editBtn");
createdEdit.addEventListener('click' , (event) => {clickEditBtn(event)});
const createdXBtn = createdButton("X" , "xBtn");
createdXBtn.addEventListener('click', (event) => {clickXBtn(event);});
const createdSave = createdButton("Save" , "saveBtn");
createdSave.style.display = "none";
createdSave.addEventListener('click', (event) => {clickSaveBtn(event);});
newLi.append(createdEdit , createdSave , createdXBtn);
const todoList = document.getElementById('todo-list')
todoList.append(newLi);
input.value = '';
return todoList;
}
function changeFilter () {
const checkValues = document.getElementById("todo-filter").value;
todoFilter(checkValues);
}
function todoFilter(checkValues) {
const todoList = document.querySelectorAll('#todo-list li');
const checkboxList = document.getElementsByClassName('todoCheckBoxList');
for(let i = 0; i < todoList.length; i++) {
const tdcheck = checkboxList[i];
if (checkValues === "all") {
todoList[i].style.display = "list-item";
}
else if (checkValues === "todo" && !tdcheck.checked) {
todoList[i].style.display = "list-item";
}
else if (checkValues === "done" && tdcheck.checked) {
todoList[i].style.display = "list-item";
}
else {
todoList[i].style.display = "none";
}
}
}
function clickXBtn(event) {
const topNode = findTopNode(event);
const getNumber = parseInt(topNode.querySelector("span").id, 10);
const getLocalStorageData = getLocalStorage();
const updateLocalStorageData = getLocalStorageData.filter(item => item.Number !== getNumber);
saveLocalStorage(updateLocalStorageData);
topNode.remove();
}
function clickEditBtn(event) {
const topNode = findTopNode(event);
const editInput = createdInput("editInput" , "text" , "editInput");
const editSpan = createdElement("span" , "editSpan" , "editSpan");
editSpan.append(editInput);
const findSaveBtn = topNode.querySelector(".saveBtn");
findSaveBtn.style.display = "inline";
const findEditBtn = topNode.querySelector(".editBtn");
findEditBtn.style.display = "none";
const findXBtn = topNode.querySelector(".xBtn");
findXBtn.style.display = "none";
const changeSpan = topNode.querySelector("span");
topNode.replaceChild(editSpan , changeSpan);
}
function clickSaveBtn (event) {
const topNode = findTopNode(event);
const saveEdit = topNode.querySelector(".editSpan");
const saveInput = saveEdit.querySelector(".editInput");
saveEdit.innerText = saveInput.value;
const findSaveBtn = topNode.querySelector(".saveBtn");
findSaveBtn.style.display = "none";
const findEditBtn = topNode.querySelector(".editBtn");
findEditBtn.style.display = "inline";
const findXBtn = topNode.querySelector(".xBtn");
findXBtn.style.display = "inline";
setLocalStorage();
}
function setLocalStorage () {
const saveDataArray = []
const todoList = document.querySelector('.todo-list');
for (let i = 0; i < todoList.children.length; i++) {
const getSpan = todoList.children[i].querySelector('span');
const saveDataObj = {
Text : getSpan.innerHTML,
Number : parseInt(i , 10)
};
getSpan.id = i;
saveDataArray.push(saveDataObj);
}
saveLocalStorage(saveDataArray);
}
function saveLocalStorage(data) {
localStorage.setItem("Save" , JSON.stringify(data));
}
function showLocalStorage (getLocalStorageData) {
const newLi = createdElement("li" , "newLi" , "newLi");
const createdCheckBox = createdInput("checkBox" , "checkBox" , "todoCheckBoxList");
newLi.append(createdCheckBox)
const newSpan = createdElement("span" , "newSpan" , "newSpan");
newSpan.append(getLocalStorageData.Text);
newSpan.id = parseInt(getLocalStorageData.Number);
newLi.append(newSpan);
const createdEdit = createdButton("Edit" , "editBtn");
createdEdit.addEventListener('click' , (event) => {clickEditBtn(event)});
const createdXBtn = createdButton("X" , "xBtn");
createdXBtn.addEventListener('click', (event) => {clickXBtn(event);});
const createdSave = createdButton("Save" , "saveBtn");
createdSave.style.display = "none";
createdSave.addEventListener('click', (event) => {clickSaveBtn(event);});
newLi.append(createdEdit , createdSave , createdXBtn);
const todoList = document.getElementById('todo-list')
todoList.append(newLi);
}
function getLocalStorage () {
const getLocalStorageData = JSON.parse(localStorage.getItem('Save'));
return getLocalStorageData;
}