From 54eaa6e8d1c8c82d152ab250561e012636c668d0 Mon Sep 17 00:00:00 2001 From: Michael Abashian Date: Wed, 19 Jul 2017 16:59:42 -0400 Subject: [PATCH] Scroll the user to the top of the page after a non-search state transition --- awx/ui/client/src/app.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/awx/ui/client/src/app.js b/awx/ui/client/src/app.js index e8ec635ca3..9bffb3db69 100644 --- a/awx/ui/client/src/app.js +++ b/awx/ui/client/src/app.js @@ -353,7 +353,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;