Skip to content

Commit

Permalink
Merge pull request #4318 from bbc/t1835-scroll-bug
Browse files Browse the repository at this point in the history
Fix issues leading to scrollTo not working with interimFilters on.
  • Loading branch information
andrew-nowak authored Aug 15, 2024
2 parents 5bb2423 + 69cbde7 commit 14bef78
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion kahuna/public/js/search/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,10 @@ results.controller('SearchResultsCtrl', [
});

$scope.$on('$destroy', () => {
scrollPosition.save($stateParams);
// only save scroll position if we're destroying grid scope (avoids issue regarding ng-if triggering scope refresh)
if (0 < $scope.ctrl.images.length) {
scrollPosition.save($stateParams);
}
freeUpdatesListener();
freeImageDeleteListener();
scopeGone = true;
Expand Down
8 changes: 8 additions & 0 deletions kahuna/public/js/services/scroll-position.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,20 @@ scrollPosService.factory('scrollPosition',
let originalContext;

function save(currentContext) {
// deal with url ambiguity over nonFree parameter
if (!currentContext.nonFree) {
currentContext.nonFree = "false";
}
originalContext = currentContext;
// Accommodate Chrome & Firefox
positionTop = document.body.scrollTop || document.documentElement.scrollTop;
}

function resume(currentContext) {
// deal with url ambiguity over nonFree parameter
if (!currentContext.nonFree) {
currentContext.nonFree = "false";
}
if (angular.equals(currentContext, originalContext)) {
$window.scrollTo(0, positionTop);
}
Expand Down

0 comments on commit 14bef78

Please sign in to comment.