-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
78 lines (66 loc) · 2.4 KB
/
app.js
File metadata and controls
78 lines (66 loc) · 2.4 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
const clockDisplay = document.querySelector("#clockDisplay");
const addInput = document.getElementById("addInput");
const addBtn = document.querySelector("#addBtn");
const todoListContainer = document.querySelector("#todoListContainer");
// clock functionality
function updateClock(){
const date = new Date();
let hours = date.getHours();
hours = hours % 12 || 12;
hours = hours.toString().padStart(2,0);
const minutes = date.getMinutes().toString().padStart(2,0);
clockDisplay.textContent = `${hours}:${minutes}`;
}
// update Clock every sec
updateClock();
setInterval(updateClock, 1000);
let listCount = 1;
// load from storage
if(localStorage.length > 0){
for(i=0; i < localStorage.length; i++){
setupDisplay(localStorage[localStorage.key(i)]);
}
}
//input
addBtn.addEventListener("click", (e) =>{
e.preventDefault();
const input = addInput.value;
if(input.length <= 40 && input.length >= 1 && listCount <= 8){
localStorage.setItem(input, input);
setupDisplay(input);
}
})
// using close button
document.addEventListener("click", (e) => {
if(e.target.classList[1] == "close" || e.target.classList[1] == "check"){
e.target.parentElement.remove();
localStorage.removeItem(e.target.parentElement.firstChild.textContent.toString());
}
})
// Task display setup
function setupDisplay(input){
const taskContainerDiv = document.createElement("div");
taskContainerDiv.classList.add("taskContainer");
const taskDiv = document.createElement("div");
taskDiv.textContent = input;
taskDiv.classList.add("task");
const checkBtn = document.createElement("img");
checkBtn.src = "./check.svg";
checkBtn.classList.add("btn");
checkBtn.classList.add("check");
const closeBtn = document.createElement("img");
closeBtn.src = "./close.svg";
closeBtn.classList.add("btn");
closeBtn.classList.add("close");
const editBtn = document.createElement("img");
editBtn.src = "./edit.svg";
editBtn.classList.add("btn");
editBtn.classList.add("edit");
taskContainerDiv.appendChild(taskDiv);
taskContainerDiv.appendChild(checkBtn);
taskContainerDiv.appendChild(closeBtn);
taskContainerDiv.appendChild(editBtn);
todoListContainer.appendChild(taskContainerDiv);
addInput.value = "";
listCount ++;
}