Skip to content

Commit

Permalink
Merge pull request #4328 from bbc/t1969-logo-click-scroll-bug
Browse files Browse the repository at this point in the history
Ensure scroll posotion resets to top when logo clicked
  • Loading branch information
twrichards authored Sep 23, 2024
2 parents 5ce0cd9 + cd6ebb5 commit 763ccda
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
7 changes: 5 additions & 2 deletions kahuna/public/js/search/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import './results';
import '../preview/image';
import '../lib/data-structure/list-factory';
import '../lib/data-structure/ordered-set-factory';
import '../services/scroll-position';
import '../components/gr-top-bar/gr-top-bar';
import '../components/gr-info-panel/gr-info-panel';
import '../components/gr-collections-panel/gr-collections-panel';
Expand All @@ -35,6 +36,7 @@ export var search = angular.module('kahuna.search', [
'kahuna.search.query',
'kahuna.search.results',
'kahuna.preview.image',
'kahuna.services.scroll-position',
'data-structure.list-factory',
'data-structure.ordered-set-factory',
'gr.topBar',
Expand Down Expand Up @@ -85,9 +87,9 @@ search.config(['$stateProvider', '$urlMatcherFactoryProvider',
},
controllerAs: 'ctrl',
controller: [
'$scope', '$window', '$stateParams', 'panels', 'shortcutKeys', 'keyboardShortcut',
'$scope', '$window', '$stateParams', 'scrollPosition', 'panels', 'shortcutKeys', 'keyboardShortcut',
'panelService', 'cropSettings', 'mediaApi', 'storage', '$state',
function($scope, $window, $stateParams, panels, shortcutKeys, keyboardShortcut,
function($scope, $window, $stateParams, scrollPosition, panels, shortcutKeys, keyboardShortcut,
panelService, cropSettings, mediaApi, storage, $state) {

const ctrl = this;
Expand Down Expand Up @@ -115,6 +117,7 @@ search.config(['$stateProvider', '$urlMatcherFactoryProvider',
detail: {showPaid: defaultNonFreeFilter.isNonFree},
bubbles: true
}));
scrollPosition.resetToTop();
});
};

Expand Down
17 changes: 15 additions & 2 deletions kahuna/public/js/services/scroll-position.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,22 @@ scrollPosService.factory('scrollPosition',
// The original context where the position was saved
let originalContext;

// Enable reset to top on next save
let forceReset = false;

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;
if (forceReset) {
forceReset = false;
positionTop = 0;
} else {
positionTop = document.body.scrollTop || document.documentElement.scrollTop;
}
}

function resume(currentContext) {
Expand All @@ -41,11 +49,16 @@ scrollPosService.factory('scrollPosition',
originalContext = undefined;
}

function resetToTop() {
forceReset = true;
}

return {
save,
resume,
getSaved,
clear
clear,
resetToTop
};
}]);

Expand Down

0 comments on commit 763ccda

Please sign in to comment.