Skip to content

Commit

Permalink
Merge pull request ansible#7179 from mabashian/6442-scroll-top
Browse files Browse the repository at this point in the history
Scroll the user to the top of the page after a non-search state transition
  • Loading branch information
mabashian authored Jul 21, 2017
2 parents 2460ade + 54eaa6e commit 825dfc9
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion awx/ui/client/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,30 @@ var awApp = angular.module('awApp', [
activateTab();
});

$rootScope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState) {
$rootScope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams) {

if(toState === fromState) {
// check to see if something other than a search param has changed
let toParamsWithoutSearchKeys = {};
let fromParamsWithoutSearchKeys = {};
for (let key in toParams) {
if (toParams.hasOwnProperty(key) && !/_search/.test(key)) {
toParamsWithoutSearchKeys[key] = toParams[key];
}
}
for (let key in fromParams) {
if (fromParams.hasOwnProperty(key) && !/_search/.test(key)) {
fromParamsWithoutSearchKeys[key] = fromParams[key];
}
}

if(!_.isEqual(toParamsWithoutSearchKeys, fromParamsWithoutSearchKeys)) {
document.body.scrollTop = document.documentElement.scrollTop = 0;
}
}
else {
document.body.scrollTop = document.documentElement.scrollTop = 0;
}

if (fromState.name === 'license' && toParams.hasOwnProperty('licenseMissing')) {
$rootScope.licenseMissing = toParams.licenseMissing;
Expand Down

0 comments on commit 825dfc9

Please sign in to comment.