Skip to content

Commit 3534d6a

Browse files
committed
Double click checkbox column to set/unset all
Fixes #36
1 parent 748dd39 commit 3534d6a

File tree

2 files changed

+91
-12
lines changed

2 files changed

+91
-12
lines changed

InteractiveHtmlBom/ibom.css

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,6 @@ canvas:active {
181181
width: 25px;
182182
}
183183

184-
.bom .bom-checkbox {
185-
width: 30px;
186-
}
187-
188184
.bom .Description {
189185
width: 10%;
190186
}
@@ -209,7 +205,7 @@ canvas:active {
209205
border-width: 5px;
210206
border-style: solid;
211207
border-color: transparent transparent #221 transparent;
212-
transform-origin: 50% 85%;
208+
transform-origin: 50% 85%;
213209
transition: opacity 0.2s, transform 0.4s;
214210
}
215211

@@ -222,13 +218,47 @@ canvas:active {
222218
}
223219

224220
.bom th .sortmark.desc {
225-
transform:rotate(180deg);
221+
transform: rotate(180deg);
226222
}
227223

228224
.bom th:hover .sortmark.none {
229225
opacity: 0.5;
230226
}
231227

228+
.bom .bom-checkbox {
229+
width: 30px;
230+
position: relative;
231+
user-select: none;
232+
}
233+
234+
.bom .bom-checkbox:before {
235+
content: "";
236+
position: absolute;
237+
border-width: 15px;
238+
border-style: solid;
239+
border-color: #51829f transparent transparent transparent;
240+
visibility: hidden;
241+
top: -15px;
242+
}
243+
244+
.bom .bom-checkbox:after {
245+
content: "Double click to set/unset all";
246+
position: absolute;
247+
color: white;
248+
top: -35px;
249+
left: -26px;
250+
background: #51829f;
251+
padding: 5px 15px;
252+
border-radius: 8px;
253+
white-space: nowrap;
254+
visibility: hidden;
255+
}
256+
257+
.bom .bom-checkbox:hover:before, .bom .bom-checkbox:hover:after {
258+
visibility: visible;
259+
transition: visibility 0.2s linear 1s;
260+
}
261+
232262
.split {
233263
-webkit-box-sizing: border-box;
234264
-moz-box-sizing: border-box;

InteractiveHtmlBom/ibom.js

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,35 @@ function highlightFilter(s) {
189189
return r;
190190
}
191191

192+
function checkboxSetUnsetAllHandler(checkboxname) {
193+
return function() {
194+
var checkboxnum = 0;
195+
while (checkboxnum < checkboxes.length &&
196+
checkboxes[checkboxnum].toLowerCase() != checkboxname.toLowerCase()) {
197+
checkboxnum++;
198+
}
199+
if (checkboxnum >= checkboxes.length) {
200+
return;
201+
}
202+
var allset = true;
203+
var checkbox;
204+
var row;
205+
for (row of bombody.childNodes) {
206+
checkbox = row.childNodes[checkboxnum + 1].childNodes[0];
207+
if (!checkbox.checked || checkbox.indeterminate) {
208+
allset = false;
209+
break;
210+
}
211+
}
212+
for (row of bombody.childNodes) {
213+
checkbox = row.childNodes[checkboxnum + 1].childNodes[0];
214+
checkbox.checked = !allset;
215+
checkbox.indeterminate = false;
216+
checkbox.onchange();
217+
}
218+
}
219+
}
220+
192221
function createColumnHeader(name, cls, comparator) {
193222
var th = document.createElement("TH");
194223
th.innerHTML = name;
@@ -237,16 +266,33 @@ function createColumnHeader(name, cls, comparator) {
237266
return th;
238267
}
239268

269+
function fancyDblClickHandler(el, onsingle, ondouble) {
270+
return function() {
271+
if (el.getAttribute("data-dblclick") == null) {
272+
el.setAttribute("data-dblclick", 1);
273+
setTimeout(function() {
274+
if (el.getAttribute("data-dblclick") == 1) {
275+
onsingle();
276+
}
277+
el.removeAttribute("data-dblclick");
278+
}, 200);
279+
} else {
280+
el.removeAttribute("data-dblclick");
281+
ondouble();
282+
}
283+
}
284+
}
285+
240286
function populateBomHeader() {
241287
while (bomhead.firstChild) {
242288
bomhead.removeChild(bomhead.firstChild);
243289
}
244290
var tr = document.createElement("TR");
245-
var td = document.createElement("TH");
246-
td.classList.add("numCol");
247-
tr.appendChild(td);
291+
var th = document.createElement("TH");
292+
th.classList.add("numCol");
293+
tr.appendChild(th);
248294
checkboxes = bomCheckboxes.split(",").filter((e) => e);
249-
var checkboxClosure = function(checkbox) {
295+
var checkboxCompareClosure = function(checkbox) {
250296
return (a, b) => {
251297
var stateA = getCheckboxState(checkbox, a[3]);
252298
var stateB = getCheckboxState(checkbox, b[3]);
@@ -256,8 +302,11 @@ function populateBomHeader() {
256302
}
257303
}
258304
for (var checkbox of checkboxes) {
259-
tr.appendChild(createColumnHeader(
260-
checkbox, "bom-checkbox", checkboxClosure(checkbox)));
305+
th = createColumnHeader(
306+
checkbox, "bom-checkbox", checkboxCompareClosure(checkbox));
307+
th.onclick = fancyDblClickHandler(
308+
th, th.onclick.bind(th), checkboxSetUnsetAllHandler(checkbox));
309+
tr.appendChild(th);
261310
}
262311
tr.appendChild(createColumnHeader("References", "References", (a, b) => {
263312
var i = 0;

0 commit comments

Comments
 (0)