From 69cbde795b5c4bb7b23720d2fd9642eb07055929 Mon Sep 17 00:00:00 2001 From: AndyKilmory Date: Tue, 13 Aug 2024 15:51:50 +0100 Subject: [PATCH] fix issues leading to scrollTo not working with interimFilters. Resolve issue with unwanted $scope.$destroy events and also ambiguity over nonFree parameter in context. --- kahuna/public/js/search/results.js | 5 ++++- kahuna/public/js/services/scroll-position.js | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/kahuna/public/js/search/results.js b/kahuna/public/js/search/results.js index 898b0deb6e..3fcbbca8ab 100644 --- a/kahuna/public/js/search/results.js +++ b/kahuna/public/js/search/results.js @@ -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; diff --git a/kahuna/public/js/services/scroll-position.js b/kahuna/public/js/services/scroll-position.js index 6e35a67ef5..977360d705 100644 --- a/kahuna/public/js/services/scroll-position.js +++ b/kahuna/public/js/services/scroll-position.js @@ -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); }