Skip to content

Commit e9dde7f

Browse files
committed
doc and clarify
1 parent 700540f commit e9dde7f

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,26 +105,28 @@
105105

106106
<script>
107107
var Api = (function () {
108+
// polyfill for jQuery
108109
var $ = (sel) => Array.from(document.querySelectorAll(sel));
109110
var boxlist = $('.item input');
110-
var indexes = {};
111+
var indexes = {}; // memory for box clicks
111112
var self;
112113

113-
function reverser(bool) {
114-
var [start, end] = [indexes.last, indexes.this].sort();
114+
function setChecked(bool) {
115+
// ensure lower index comes first
116+
var [start, end] = [indexes.last, indexes.next].sort();
115117
var arr = boxlist.slice(start, end + 1);
116-
arr.forEach(el => el.checked = bool);
118+
arr.forEach((el) => el.checked = bool);
117119
}
118120

119-
function updateLast(evt, num) {
120-
indexes.last = evt.shiftKey ? indexes.this : num;
121-
indexes.this = num;
122-
reverser(evt.target.checked);
121+
function revIndexes(evt, num) {
122+
indexes.last = evt.shiftKey ? indexes.next : num;
123+
indexes.next = num;
124+
setChecked(evt.target.checked); // replicate this state
123125
}
124126

125127
function doBinding(arr) {
126128
arr.forEach((ele, idx) => {
127-
ele.addEventListener('click', (evt) => updateLast(evt, idx));
129+
ele.addEventListener('click', (evt) => revIndexes(evt, idx));
128130
});
129131
return self;
130132
}

0 commit comments

Comments
 (0)