From 52dd206715e9d8e80a22c7106ec783324d51e747 Mon Sep 17 00:00:00 2001 From: Scott Main Date: Thu, 15 Aug 2013 12:22:28 -0700 Subject: [PATCH] fix two bugs in site script. 1. Fix URL path check for reference docs to initalize api level and sidenav. Previously, this condition was never true, so the sidenav would not be initialized under default conditions and the reference drag bar would not appear. 2. Fix the recent change to the 'scroll into view' script so that it works properly in a multi-pane sidenav (reference docs) by again making the offset measurement relative to the parent container (but much better than was done before). Change-Id: I2a31ed59d772346651c2432f0ed26530983c49ff --- .../droiddoc/templates-sdk/assets/js/docs.js | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/tools/droiddoc/templates-sdk/assets/js/docs.js b/tools/droiddoc/templates-sdk/assets/js/docs.js index fa7554b15d..c21929ea16 100644 --- a/tools/droiddoc/templates-sdk/assets/js/docs.js +++ b/tools/droiddoc/templates-sdk/assets/js/docs.js @@ -183,7 +183,6 @@ $(document).ready(function() { $("#nav-x li.google a").addClass("selected"); } else { $("#nav-x li.reference a").addClass("selected"); - changeApiLevel(); // turn things grey } } else if ((rootDir == "tools") || (rootDir == "sdk")) { $("#nav-x li.tools a").addClass("selected"); @@ -825,14 +824,13 @@ function scrollIntoView(nav) { // 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); - + // get the selected item's offset from its container nav by measuring the item's offset + // relative to the document then subtract the container nav's offset relative to the document + var selectedOffset = $selected.offset().top - $nav.offset().top; + if (selectedOffset > $nav.height() * .8) { // multiply nav height by .8 so we move up the item + // if it's more than 80% down the nav + // scroll the item up by an amount equal to 80% the container nav's height + api.scrollTo(0, selectedOffset - ($nav.height() * .8), false); } } } @@ -2232,10 +2230,10 @@ function escapeHTML(string) { /* ######################################################## */ /* Initialize some droiddoc stuff, but only if we're in the reference */ -if (location.pathname.indexOf("/reference")) { - if(!location.pathname.indexOf("/reference-gms/packages.html") - && !location.pathname.indexOf("/reference-gcm/packages.html") - && !location.pathname.indexOf("/reference/com/google") == 0) { +if (location.pathname.indexOf("/reference") == 0) { + if(!(location.pathname.indexOf("/reference-gms/packages.html") == 0) + && !(location.pathname.indexOf("/reference-gcm/packages.html") == 0) + && !(location.pathname.indexOf("/reference/com/google") == 0)) { $(document).ready(function() { // init available apis based on user pref changeApiLevel();