Skip to content

Commit cb56cd8

Browse files
committed
[day 6] Add checkboxes and buttons. This feels gross.
1 parent f1168d7 commit cb56cd8

File tree

3 files changed

+42
-21
lines changed

3 files changed

+42
-21
lines changed

projects/6-to-do-list/css/application.css

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ a {
4141
padding: 1rem;
4242
background: #F4F4F4;
4343
position: relative;
44+
display: flex;
4445
}
4546

4647
.todo__item + .todo__item {
@@ -53,20 +54,6 @@ a {
5354
color: rgba(0,0,0,0.5);
5455
}
5556

56-
.todo__item--complete::before {
57-
content: "";
58-
background-image: url("../img/check.svg");
59-
background-repeat: no-repeat;
60-
background-size: cover;
61-
width: 12px;
62-
height: 12px;
63-
display: inline-block;
64-
vertical-align: middle;
65-
position:relative;
66-
top:-.1em;
67-
left: -0.25em;
68-
}
69-
7057
.todo-input {
7158
border: 1px solid #F4F4F4;
7259
}
@@ -84,6 +71,30 @@ a {
8471
background: #46A3E4;
8572
}
8673

74+
.btn--icon {
75+
padding: 0;
76+
background: transparent;
77+
}
78+
79+
.todo__text {
80+
flex: auto;
81+
}
82+
83+
.icon {
84+
background-repeat: no-repeat;
85+
background-size: cover;
86+
width: 12px;
87+
height: 12px;
88+
display: inline-block;
89+
vertical-align: middle;
90+
position: relative;
91+
top: -.1em;
92+
}
93+
94+
.icon--remove {
95+
background-image: url("../img/close.svg");
96+
}
97+
8798
.page-footer {
8899
text-align: center;
89100
font-weight: 500;
Lines changed: 3 additions & 0 deletions
Loading

projects/6-to-do-list/js/to-do.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@ var list = document.getElementById('todo-items');
44
var itemInput = document.getElementById('todo-add-new');
55

66
var addToDo = function() {
7-
var text = itemInput.value;
8-
var item = document.createElement("li");
9-
var listLength = list.children.length;
10-
item.innerHTML = text;
7+
var text = itemInput.value;
8+
var item = document.createElement("li");
9+
var listLength = list.children.length;
10+
var itemCheck = '<input type="checkbox" id="too-doo-check_' + (listLength + 1) + '" />';
11+
var itemStatus = '<span class="todo__status">' + itemCheck + '</span>';
12+
var itemText = '<span class="todo__text px1">' + text + '</span>';
13+
var itemAction = '<span class="todo__remove"><button type="button" class="btn btn--icon"><i class="icon icon--remove"></i></button></span>';
14+
15+
item.innerHTML = itemStatus + itemText + itemAction;
1116
item.id = "too-doo_" + (listLength + 1);
1217
item.classList.add("todo__item");
1318
list.appendChild(item);
@@ -22,8 +27,10 @@ var addToDo = function() {
2227
};
2328

2429
var completeToDo = function(event) {
25-
var toDo = event.target;
26-
if (toDo && toDo.matches("li.todo__item")) {
30+
var check = event.target;
31+
var toDo = check.parentElement.parentElement;
32+
33+
if (toDo && toDo.matches("li")) {
2734
toDo.classList.toggle("todo__item--complete");
2835
var toDoItems = list.innerHTML;
2936
localStorage.setItem('toDoItems', toDoItems);
@@ -62,7 +69,7 @@ if(localStorage.getItem('toDoItems')) {
6269
}
6370

6471
var toDoHandlers = function() {
65-
list.addEventListener('click', completeToDo, false);
72+
list.addEventListener('change', completeToDo, false);
6673
};
6774

6875
window.onload = function(){

0 commit comments

Comments
 (0)