Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure scroll posotion resets to top when logo clicked #4328

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading