about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBrian Hetro <whee@smaertness.net>2023-05-26 20:24:29 -0400
committerBrian Hetro <whee@smaertness.net>2023-05-26 20:24:29 -0400
commit7c1bca4be8974e3e1ff694fec06747aa53fdf337 (patch)
treee74d5dbb458d9ec736fbc43264932c5496b17e30
parent5be2b27ed6a6b347342e11a46b74e104aac36cd4 (diff)
downloadrust-7c1bca4be8974e3e1ff694fec06747aa53fdf337.tar.gz
rust-7c1bca4be8974e3e1ff694fec06747aa53fdf337.zip
Handle back/forward when using URL parameters for filter states
-rw-r--r--util/gh-pages/script.js18
1 files changed, 15 insertions, 3 deletions
diff --git a/util/gh-pages/script.js b/util/gh-pages/script.js
index 3aaf455e12f..868b63a27df 100644
--- a/util/gh-pages/script.js
+++ b/util/gh-pages/script.js
@@ -163,7 +163,7 @@
                 const urlParameters = $location.search();
 
                 // Define a helper function that assigns URL parameters to a provided scope variable
-                const handleParameter = (parameter, scopeVariable) => {
+                const handleParameter = (parameter, scopeVariable, defaultValues) => {
                     if (urlParameters[parameter]) {
                         const items = urlParameters[parameter].split(',');
                         for (const key in scopeVariable) {
@@ -171,11 +171,17 @@
                                 scopeVariable[key] = items.includes(key);
                             }
                         }
+                    } else if (defaultValues) {
+                        for (const key in defaultValues) {
+                            if (scopeVariable.hasOwnProperty(key)) {
+                                scopeVariable[key] = defaultValues[key];
+                            }
+                        }
                     }
                 };
 
-                handleParameter('levels', $scope.levels);
-                handleParameter('groups', $scope.groups);
+                handleParameter('levels', $scope.levels, LEVEL_FILTERS_DEFAULT);
+                handleParameter('groups', $scope.groups, GROUPS_FILTER_DEFAULT);
 
                 // Handle 'versions' parameter separately because it needs additional processing
                 if (urlParameters.versions) {
@@ -277,6 +283,12 @@
                 }
             });
 
+            $scope.$watch(function () {
+                return $location.search();
+            }, function (newParameters) {
+                loadFromURLParameters();
+            });
+
             $scope.selectTheme = function (theme) {
                 setTheme(theme, true);
             }