-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
todo list #4
base: master
Are you sure you want to change the base?
todo list #4
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
|
||
document | ||
.querySelector("ul") | ||
.addEventListener("click", e =>{ | ||
if(e.target.tagName === 'LI'){ | ||
if(e.metaKey){ | ||
e.target.remove(); | ||
} | ||
else{ | ||
e.target.style = 'text-decoration : line-through'; | ||
} | ||
} | ||
}); | ||
|
||
for(let butt of document.querySelectorAll("button")){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Language! |
||
butt.addEventListener("click", e =>{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since each button is an individual controller for a distinct action, we should add event listeners to them individually, not in a loop. |
||
for(let item of document.querySelectorAll("li")){ | ||
if(e.target.name === "mark_all"){ | ||
item.style = 'text-decoration : line-through'; | ||
} | ||
else if(e.target.name === "delete_all" && item.style.textDecoration === 'line-through'){ | ||
item.remove(); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
|
||
document.getElementById("write_item") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not listen to form's |
||
.addEventListener("input", e =>{ | ||
if(e.target.value !== "" && e.target.value !== "Write up your todo here"){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default value you see is called "placeholder". It's not literally a value. |
||
document.getElementById("add").disabled = false; | ||
} | ||
else{ | ||
document.getElementById("add").disabled = true; | ||
} | ||
}); | ||
|
||
document.getElementById("add") | ||
.addEventListener("click", e =>{ | ||
e.preventDefault(); | ||
const item = document.createElement("li"); | ||
const node = document.createTextNode(document.getElementById("write_item").value); | ||
item.append(node); | ||
document.querySelector("ul").prepend(item); | ||
document.getElementById("write_item").value = "Write up your todo here"; | ||
document.getElementById("write_item").style.width = ''; | ||
document.getElementById("add").disabled = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use a form's |
||
}); | ||
|
||
document.getElementById("write_item") | ||
.addEventListener("focus", e =>{ | ||
e.target.style.width = '500px'; | ||
}); | ||
|
||
document.getElementById("write_item") | ||
.addEventListener("blur", e =>{ | ||
if(e.target.value === "" || e.target.value === "Write up your todo here"){ | ||
e.target.style.width = ''; | ||
} | ||
}); | ||
|
||
document | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why reimplement the |
||
.addEventListener("keydown", e =>{ | ||
let list_li = document.querySelectorAll("li"); | ||
if(e.keyCode === 9 && list_li.length > 0){ //tab | ||
e.preventDefault(); | ||
let index = -1; | ||
for(let i = 0; i < list_li.length; i++){ | ||
if(document.activeElement === list_li[i]){ | ||
index = i; | ||
} | ||
} | ||
if(index === -1 || index === list_li.length-1){ | ||
list_li[0].focus(); | ||
} | ||
else{ | ||
list_li[index+1].focus(); | ||
} | ||
console.log(index); | ||
} | ||
}); | ||
|
||
document | ||
.querySelector("ul") | ||
.addEventListener("focus", e =>{ | ||
if(e.target.tagName === 'LI'){ | ||
if(e.target.textDecoration === 'line-through'){ | ||
e.target.textDecoration = 'underline line-through'; | ||
} | ||
else{ | ||
e.target.textDecoration = 'underline'; | ||
} | ||
e.target.style.listStyleType = 'circle'; | ||
} | ||
}); | ||
|
||
document | ||
.querySelector("ul") | ||
.addEventListener("blur", e =>{ | ||
if(e.target.tagName === 'LI'){ | ||
if(e.target.textDecoration === 'underline line-through'){ | ||
e.target.textDecoration = 'line-through'; | ||
} | ||
else{ | ||
e.target.textDecoration = ''; | ||
} | ||
e.target.style.listStyleType = 'disc'; | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,11 +14,19 @@ <h1>ExCo.</h1> | |
</header> | ||
<main> | ||
<h2>My Todos List</h2> | ||
<form> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But why not use a section? :( |
||
<input type="text" name="write_item" id="write_item" value="Write up your todo here"> | ||
<input type="submit" class="add" id="add" value="Add" disabled> | ||
</form> | ||
<ul> | ||
<li>Have morning coffee</li> | ||
<li>Eat lunch</li> | ||
<li>Make awesome things happen</li> | ||
</ul> | ||
<span> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A span instead of a section? A SPAN?!?! 😭 |
||
<button type="button" name="mark_all">Mark all as done</button> | ||
<button type="button" name="delete_all">Delete all done</button> | ||
</span> | ||
</main> | ||
<footer> | ||
<small>© Copyright 2058, Example Corporation</small> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a bug 😢