Skip to content

Commit 1d64937

Browse files
committed
attempt range clicker
1 parent 23fb2cd commit 1d64937

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,39 @@
104104
</div>
105105

106106
<script>
107+
var Api = (function () {
108+
var $ = (sel) => Array.from(document.querySelectorAll(sel));
109+
var boxlist = $('.item input');
110+
var indexes = {};
111+
var self;
112+
113+
function reverser(bool) {
114+
var [start, end] = [indexes.last, indexes.this].sort();
115+
var arr = boxlist.slice(start, end + 1);
116+
arr.forEach(el => el.checked = bool);
117+
}
118+
119+
function updateLast(evt, num) {
120+
indexes.last = evt.shiftKey ? indexes.this : num;
121+
indexes.this = num;
122+
reverser(evt.target.checked);
123+
}
124+
125+
function doBinding(arr) {
126+
arr.forEach((ele, idx) => {
127+
ele.addEventListener('click', (evt) => updateLast(evt, idx));
128+
});
129+
return self;
130+
}
131+
132+
self = {
133+
init: doBinding,
134+
boxlist, indexes,
135+
};
136+
137+
return self.init(boxlist);
138+
}());
139+
107140
</script>
108141
</body>
109142
</html>

0 commit comments

Comments
 (0)