10
0
mirror of https://github.com/LCPQ/QUESTDB_website.git synced 2024-12-25 13:53:48 +01:00

Add nestedCheckboxes eventHandler

This commit is contained in:
Mickaël Véril 2020-01-04 18:07:19 +01:00
parent 74dce2168f
commit c72176d808

View File

@ -0,0 +1,24 @@
function nestedCheckbox_change(e) {
checkbox = e.target;
//Apply children
if (!checkbox.indeterminate) {
var ul = $(checkbox).parent("li").next("ul")
if (ul.length != 0) {
ul.children("li").children("input[type=checkbox]").prop("checked", checkbox.checked);
}
}
//Apply parent
var ul=$(checkbox).parent("li").parent("ul")
var checkbox=$(ul).prev("li").children("input[type=checkbox]")
checkboxes=ul.children("li").children("input[type=checkbox]")
var checkeds=Array.from(checkboxes).map(el=>el.checked)
var scheckeds=new Set(checkeds)
if (scheckeds.size>1) {
$(checkbox).prop("checked",false);
checkbox.prop("indeterminate",true);
}
else{
checkbox.indeterminate=false;
checkbox=scheckeds[0];
}
}