forked from CGM_Public/pretix_original
optimized update() to only check the least number of checkboxes
This commit is contained in:
@@ -738,22 +738,20 @@ $(function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
var update = function () {
|
var update = function () {
|
||||||
var all_true = true;
|
var all_same;
|
||||||
var all_false = true;
|
var checkboxes = $checkboxes.toArray();
|
||||||
$toggle.closest("table").find("td:first-child input[type=checkbox]").each(function () {
|
var i = checkboxes.length;
|
||||||
if ($(this).prop("checked")) {
|
while (i--) {
|
||||||
all_false = false;
|
if (all_same === undefined) {
|
||||||
} else {
|
all_same = checkboxes[i].checked;
|
||||||
all_true = false;
|
continue;
|
||||||
|
}
|
||||||
|
if (all_same != checkboxes[i].checked) {
|
||||||
|
$toggle.prop("checked", false).prop("indeterminate", true);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
if (all_true) {
|
|
||||||
$toggle.prop("checked", true).prop("indeterminate", false);
|
|
||||||
} else if (all_false) {
|
|
||||||
$toggle.prop("checked", false).prop("indeterminate", false);
|
|
||||||
} else {
|
|
||||||
$toggle.prop("checked", false).prop("indeterminate", true);
|
|
||||||
}
|
}
|
||||||
|
$toggle.prop("checked", all_same).prop("indeterminate", false);
|
||||||
};
|
};
|
||||||
|
|
||||||
$(this).closest("table").find("td:first-child input[type=checkbox]").change(update);
|
$(this).closest("table").find("td:first-child input[type=checkbox]").change(update);
|
||||||
|
|||||||
Reference in New Issue
Block a user