-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
135 lines (127 loc) · 4.35 KB
/
index.html
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
<!-- ToDo page
ver. on JS without REACT
-->
<html>
<head>
<meta charset="UTF-8" />
<link type="text/css" href="index.css" rel="stylesheet" />
<title>Hello!</title>
</head>
<body>
<div class="flcc w100 h100">
<div class="vcenter">
<p>
New ToDo
<input autofocus type="text" style="margin: auto 10px" />
<button id="addButton">Add (+)</button>
</p>
<br /><br />
<p>
ToDo Things
<button id="storeButton" style="margin: auto 10px">Store It</button>
<button id="recallButton">Recall It</button>
</p>
<div id="toDoList">
<p>
<input type="checkbox" disabled /> -
<span style="color: lightgray">bla-bla-bla bla-bla-bla</span>
</p>
</div>
<button id="delButton">Del (x)</button>
</div>
</div>
<script>
var toDos = [];
// ADD (+) button
const addButton = document.getElementById("addButton");
//console.log(button);
addButton.addEventListener("click", (event) => {
const newToDo = document.querySelector("input").value;
toDos.push(newToDo);
const toDoList = document.getElementById("toDoList");
toDoList.innerHTML = toDos
.map(
(toDo, index) =>
`<p><input id="chk${index.toString()}" type="checkbox"> - <span id="sp${index.toString()}" style="text-decoration:none;">${toDo}</span></p>`
)
.join("");
document.querySelector("input").value = "";
document.querySelector("input").focus();
document.querySelector("input").select();
});
// DEL (-) button
const delButton = document.getElementById("delButton");
delButton.addEventListener("click", (event) => {
// console.log(event);
var freshToDos = [];
toDos.forEach((element, ind) => {
el = document.getElementById("chk" + ind);
// if (!el.checked) {freshToDos.push(element);console.log(ind,"-ok");} else {console.log(ind,"---del---");}
if (!el.checked) {
freshToDos.push(element);
}
});
toDoList.innerHTML = freshToDos
.map(
(toDo, index) =>
`<p><input id="chk${index.toString()}" type="checkbox"> - <span id="sp${index.toString()}" style="text-decoration:none;">${toDo}</span></p>`
)
.join("");
toDos = freshToDos;
document.querySelector("input").focus();
document.querySelector("input").select();
});
// CHECKBOXes
document.addEventListener("change", function () {
var chk = event.target;
if (chk.tagName === "INPUT" && chk.type === "checkbox") {
// console.log("%s %s", chk.id, chk.checked);
const idx = chk.id.substring(3);
const el = document.getElementById("sp" + idx);
if (chk.checked) {
el.setAttribute("style", "text-decoration:line-through;");
} else {
el.setAttribute("style", "");
}
}
});
// STORE button
const storeButton = document.getElementById("storeButton");
storeButton.addEventListener("click", (event) => {
const mtemp = [];
toDos.forEach((elm) => {
abc = elm.replaceAll(",", ";;");
mtemp.push(abc);
});
localStorage.setItem("toDos", mtemp);
var locStor = localStorage.getItem("toDos");
// console.log(locStor);
});
// RECALL button
const recallButton = document.getElementById("recallButton");
recallButton.addEventListener("click", (event) => {
mToDos = localStorage.getItem("toDos");
mToDos = mToDos.split(",");
mToDos.forEach(
(elm, idx, arr) => (arr[idx] = elm.replaceAll(";;", ","))
);
// console.log(mToDos);
toDos = mToDos;
toDoList.innerHTML = toDos
.map(
(toDo, index) =>
`<p><input id="chk${index.toString()}" type="checkbox"> - <span id="sp${index.toString()}" style="text-decoration:none;">${toDo}</span></p>`
)
.join("");
});
</script>
<!--
1 - checkbox follow crossline
2 - delete button
3 - save to local storage
todo:
4 - move crosslined down
5 - sort up/down
-->
</body>
</html>