Skip to content

Commit 9c7b7b5

Browse files
committed
Finished 10
1 parent dfdcb52 commit 9c7b7b5

File tree

1 file changed

+52
-24
lines changed

1 file changed

+52
-24
lines changed

10 - Hold Shift and Check Checkboxes/index-START.html

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,52 @@
11
<!DOCTYPE html>
22
<html lang="en">
3+
34
<head>
45
<meta charset="UTF-8">
56
<title>Hold Shift to Check Multiple Checkboxes</title>
67
</head>
8+
79
<body>
810
<style>
9-
1011
html {
1112
font-family: sans-serif;
12-
background:#ffc600;
13+
background: #ffc600;
1314
}
1415

1516
.inbox {
16-
max-width:400px;
17-
margin:50px auto;
18-
background:white;
19-
border-radius:5px;
20-
box-shadow:10px 10px 0 rgba(0,0,0,0.1);
17+
max-width: 400px;
18+
margin: 50px auto;
19+
background: white;
20+
border-radius: 5px;
21+
box-shadow: 10px 10px 0 rgba(0, 0, 0, 0.1);
2122
}
2223

2324
.item {
24-
display:flex;
25-
align-items:center;
25+
display: flex;
26+
align-items: center;
2627
border-bottom: 1px solid #F1F1F1;
2728
}
2829

2930
.item:last-child {
30-
border-bottom:0;
31+
border-bottom: 0;
3132
}
3233

3334

34-
input:checked + p {
35-
background:#F9F9F9;
35+
input:checked+p {
36+
background: #F9F9F9;
3637
text-decoration: line-through;
3738
}
3839

3940
input[type="checkbox"] {
40-
margin:20px;
41+
margin: 20px;
4142
}
4243

4344
p {
44-
margin:0;
45-
padding:20px;
46-
transition:background 0.2s;
47-
flex:1;
48-
font-family:'helvetica neue';
45+
margin: 0;
46+
padding: 20px;
47+
transition: background 0.2s;
48+
flex: 1;
49+
font-family: 'helvetica neue';
4950
font-size: 20px;
5051
font-weight: 200;
5152
border-left: 1px solid #D1E2FF;
@@ -55,10 +56,8 @@
5556
text-align: center;
5657
font-size: 15px;
5758
}
58-
59-
6059
</style>
61-
<!--
60+
<!--
6261
The following is a common layout you would see in an email client.
6362
6463
When a user clicks a checkbox, holds Shift, and then clicks another checkbox a few rows down, all the checkboxes inbetween those two checkboxes should be checked.
@@ -103,7 +102,36 @@
103102
</div>
104103
</div>
105104

106-
<script>
107-
</script>
105+
<script>
106+
var items = document.querySelectorAll("input");
107+
var checkboxes = document.getElementsByTagName("input");
108+
console.log('checkboxes', checkboxes, checkboxes[3].checked);
109+
var lastChecked = null;
110+
for (var i = 0; i < checkboxes.length; i++) {
111+
checkboxes[i].onclick = doSomething;
112+
checkboxes[i].index = i;
113+
};
114+
function doSomething(e) {
115+
var index = this.index;
116+
if (e.shiftKey && this.checked) {
117+
console.log('ere')
118+
if (lastChecked !== null) {
119+
// if lastChecked less than index, iterate up
120+
console.log('ereasdfd')
121+
if (lastChecked < index) {
122+
for (var i = lastChecked + 1; i < index; i++) {
123+
checkboxes[i].checked = true;
124+
}
125+
} else {
126+
for (i = lastChecked - 1; i > index; i--) {
127+
checkboxes[i].checked = true;
128+
}
129+
}
130+
}
131+
}
132+
lastChecked = index;
133+
};
134+
</script>
108135
</body>
109-
</html>
136+
137+
</html>

0 commit comments

Comments
 (0)