From d5950821e2eab68ef3d42fa62a40ed102d86c261 Mon Sep 17 00:00:00 2001 From: Richard Schreiber Date: Fri, 19 Feb 2021 11:02:42 +0100 Subject: [PATCH] optimized update() to only check the least number of checkboxes --- src/pretix/static/pretixcontrol/js/ui/main.js | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/pretix/static/pretixcontrol/js/ui/main.js b/src/pretix/static/pretixcontrol/js/ui/main.js index 7c9069c77..93c36fe8a 100644 --- a/src/pretix/static/pretixcontrol/js/ui/main.js +++ b/src/pretix/static/pretixcontrol/js/ui/main.js @@ -738,22 +738,20 @@ $(function () { }); var update = function () { - var all_true = true; - var all_false = true; - $toggle.closest("table").find("td:first-child input[type=checkbox]").each(function () { - if ($(this).prop("checked")) { - all_false = false; - } else { - all_true = false; + var all_same; + var checkboxes = $checkboxes.toArray(); + var i = checkboxes.length; + while (i--) { + if (all_same === undefined) { + all_same = checkboxes[i].checked; + 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);