From bc72957e927d5cbe5ee2f4d326d75a8bd88c3b14 Mon Sep 17 00:00:00 2001 From: Scott Main Date: Tue, 30 Jul 2013 18:00:51 -0700 Subject: [PATCH] fix sidebar autoscroll when the selected doc is not visible. bug: 9676913 This was not working for third generation list items. Switching the position measurement to be relative to the entire page rather than the parent container fixes it. I then added 125px to account for the site header and set the threshold and placement of scrolled items to be at 80% the nav height. Change-Id: Idda1896d11069e56325ba830ed745dae9e0fc483 --- .../droiddoc/templates-sdk/assets/js/docs.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/tools/droiddoc/templates-sdk/assets/js/docs.js b/tools/droiddoc/templates-sdk/assets/js/docs.js index 2d72ed56a..8fd442c9e 100644 --- a/tools/droiddoc/templates-sdk/assets/js/docs.js +++ b/tools/droiddoc/templates-sdk/assets/js/docs.js @@ -819,13 +819,18 @@ function scrollIntoView(nav) { if ($nav.is(':visible')) { var $selected = $(".selected", $nav); - if ($selected.length == 0) return; - - var selectedOffset = $selected.position().top; - if (selectedOffset + 90 > $nav.height()) { // add 90 so that we scroll up even - // if the current item is close to the bottom - api.scrollTo(0, selectedOffset - ($nav.height() / 4), false); // scroll the item into view - // to be 1/4 of the way from the top + if ($selected.length == 0) { + // If no selected item found, exit + return; + } + + var selectedOffset = $selected.offset().top; // measure offset from top, relative to entire page + if (selectedOffset > $nav.height() * .8) { // multiply nav height by .8 so we move up any + // items more than 80% down the nav + // scroll the item up by an amount 125px less than the window height (account for site header) + // and then multiply nav height by .8 to match the 80% threshold used above + api.scrollTo(0, selectedOffset - 125 - ($nav.height() * .8), false); + } } }