Visitar URL original
Day 10 my solution · wesbos/JavaScript30@2fc59fe · GitHub
Skip to content

Commit 2fc59fe

Browse files
committed
Day 10 my solution
1 parent d9eb87c commit 2fc59fe

1 file changed

Lines changed: 44 additions & 1 deletion

File tree

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

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,59 @@
104104
</div>
105105

106106
<script>
107-
console.log('helo');
107+
108+
//day 03?
108109
//get all the divs with class "item"
110+
const checkboxes = document.querySelectorAll('.inbox input[type="checkbox"]');
111+
112+
let lastChecked;
113+
let atEdge = false;
114+
let filling = false;
115+
let shiftClick = false;
116+
117+
function handleCheck(e) {
118+
if(lastChecked && shiftClick) {
119+
for( i = 0; i < checkboxes.length; i++ ) {
120+
atEdge = (checkboxes[i] == lastChecked || checkboxes[i] == e.currentTarget);
121+
filling = atEdge ? !filling : filling;
122+
if ( !atEdge ) {
123+
checkboxes[i].checked = filling;
124+
}
125+
}
126+
}
127+
atEdge = false;
128+
filling = false;
129+
lastChecked = e.currentTarget;
130+
}
109131

110132
//add a click event listener on each item
133+
checkboxes.forEach(checkbox => checkbox.addEventListener('click', handleCheck));
134+
135+
//figure out how to index the items
111136

112137
//Get the index of the last clicked item
113138

114139
//Get the index of the current clicked item
115140

116141
//Check all boxes in between last clicked and current click index if shift key down + click
142+
143+
144+
//Day 01 listening for keyboard events
145+
//Figure out how to tell if it's a shift+click
146+
function keydown(e) {
147+
if(e.keyCode == "16") {
148+
shiftClick = true;
149+
}
150+
}
151+
152+
function keyup(e) {
153+
if(e.keyCode == "16") {
154+
shiftClick = false;
155+
}
156+
}
157+
158+
window.addEventListener('keydown', keydown);
159+
window.addEventListener('keyup', keyup);
117160
</script>
118161
</body>
119162
</html>

0 commit comments

Comments
 (0)