Improve efficiency of area map dropdown category selection
authorLaury GvR <laury@gaslightmedia.com>
Thu, 27 Dec 2018 15:37:00 +0000 (10:37 -0500)
committerLaury GvR <laury@gaslightmedia.com>
Thu, 27 Dec 2018 15:37:00 +0000 (10:37 -0500)
js/leaflet-area-map.js

index 32e1127..90c2a14 100644 (file)
@@ -47,14 +47,9 @@ var GlmMap = {
             jQuery("#cat-main-close-" + category_id).click(function(){
                 jQuery("#cat-main-" + category_id).slideUp(GlmMap._catDivSpeed).parent().toggleClass("open");
             });
-            jQuery("#cat-main-" + category_id + " .catLabel input[type='checkbox']").click(function() {
-                var anySubCatSelected = false;
-                jQuery("#cat-main-" + category_id + " .catLabel input[type='checkbox']").each(function() {
-                    if ($(this)[0].checked) {
-                        anySubCatSelected = true;
-                    }
-                });
-                jQuery("#cat-" + category_id).toggleClass("selected", anySubCatSelected);
+            // While any checkbox of a given category is selected, preserve 'selected' class on that category's tab
+            $("#cat-main-" + category_id + " .catLabel input[type='checkbox']").on("click", function() {
+                $("#cat-" + category_id).toggleClass("selected", $("#cat-main-" + category_id + " input:checkbox:checked").length > 0);
             });
         });
         jQuery("#memLocHdr").click(function (){