Skip to content

Commit 7c1bca4

Browse files
committed
Handle back/forward when using URL parameters for filter states
1 parent 5be2b27 commit 7c1bca4

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

util/gh-pages/script.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,19 +163,25 @@
163163
const urlParameters = $location.search();
164164

165165
// Define a helper function that assigns URL parameters to a provided scope variable
166-
const handleParameter = (parameter, scopeVariable) => {
166+
const handleParameter = (parameter, scopeVariable, defaultValues) => {
167167
if (urlParameters[parameter]) {
168168
const items = urlParameters[parameter].split(',');
169169
for (const key in scopeVariable) {
170170
if (scopeVariable.hasOwnProperty(key)) {
171171
scopeVariable[key] = items.includes(key);
172172
}
173173
}
174+
} else if (defaultValues) {
175+
for (const key in defaultValues) {
176+
if (scopeVariable.hasOwnProperty(key)) {
177+
scopeVariable[key] = defaultValues[key];
178+
}
179+
}
174180
}
175181
};
176182

177-
handleParameter('levels', $scope.levels);
178-
handleParameter('groups', $scope.groups);
183+
handleParameter('levels', $scope.levels, LEVEL_FILTERS_DEFAULT);
184+
handleParameter('groups', $scope.groups, GROUPS_FILTER_DEFAULT);
179185

180186
// Handle 'versions' parameter separately because it needs additional processing
181187
if (urlParameters.versions) {
@@ -277,6 +283,12 @@
277283
}
278284
});
279285

286+
$scope.$watch(function () {
287+
return $location.search();
288+
}, function (newParameters) {
289+
loadFromURLParameters();
290+
});
291+
280292
$scope.selectTheme = function (theme) {
281293
setTheme(theme, true);
282294
}

0 commit comments

Comments
 (0)