From 3df0cfa6417622aa55fcf1ac927470eee1fd47e0 Mon Sep 17 00:00:00 2001 From: vrana Date: Tue, 11 Sep 2012 15:15:35 -0700 Subject: [PATCH] Autoscroll sidebar Summary: If the ToC in sidebar is long then the active file can be under the fold when we highlight it. This also saves some CPU cycles because it highlights only after scrolling of the main window and not in the elements. Test Plan: Scrolled on a long diff. Scrolled the ToC. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D3473 --- .../application/core/behavior-active-nav.js | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/webroot/rsrc/js/application/core/behavior-active-nav.js b/webroot/rsrc/js/application/core/behavior-active-nav.js index 43fcc3328f..a753e15184 100644 --- a/webroot/rsrc/js/application/core/behavior-active-nav.js +++ b/webroot/rsrc/js/application/core/behavior-active-nav.js @@ -28,8 +28,11 @@ JX.behavior('phabricator-active-nav', function(config) { link, 'phabricator-active-nav-focus', selected); + if (selected && link.scrollIntoView) { + link.scrollIntoView(false); + } } - } + }; /** @@ -72,15 +75,24 @@ JX.behavior('phabricator-active-nav', function(config) { // If we get above the first marker, select it. selectnav(active && JX.Stratcom.getData(active).anchor); - } + }; var pending = null; var onviewportchange = function(e) { pending && clearTimeout(pending); pending = setTimeout(updateposition, 100); - } + }; - JX.Stratcom.listen('scroll', null, onviewportchange); + var onscroll = function(e) { + if (e.getNode('tag:body')) { + // If we are inside then it means we just scrolled some