-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
77 lines (68 loc) · 1.89 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
import { todolist, updateLocalStorage, addTodo, addSVG } from "./data.js";
const todolistEl = document.querySelector(".todos");
const inputField = document.getElementById("todoInput");
const inputBtn = document.getElementById("addTodo");
inputBtn.addEventListener("click", function () {
if (inputField.value.length < 3) {
alert("Need more than 3 characters");
return;
}
addTodo(inputField.value);
renderPendingTodos(true);
inputField.value = "";
updateLocalStorage();
});
function renderPendingTodos(animate) {
todolistEl.innerHTML = "";
todolist.forEach((todo, i) => {
if (i === todolist.length - 1 && animate) {
createTodoHtml(todo, true);
} else {
createTodoHtml(todo);
}
});
}
function createTodoHtml(todoOb, animate) {
const todo = createElement("div", {
class: "todo",
id: `${todoOb.id}`,
});
const textBox = createElement("div", {
class: "textbox",
});
const todoText = createElement(
"p",
{
class: todoOb.name,
},
{
textAlign: "center",
},
todoOb.name
);
textBox.append(todoText);
todo.append(textBox);
todolistEl.prepend(todo);
addSVG(false, todo, "images/checkbox.svg", "checkbox", animate, todoOb);
addSVG(true, textBox, "images/underlines.svg", "lines", animate);
updateLocalStorage();
}
const createElement = (type, attributes, styles, textContent) => {
const el = document.createElement(type);
Object.assign(el.style, styles);
for (const [key, value] of Object.entries(attributes)) {
el.setAttribute(key, value);
}
el.textContent = textContent;
return el;
};
function render() {
addSVG(
false,
document.querySelector(".hero"),
"images/todos4.svg",
"heroText"
);
renderPendingTodos();
}
render();