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
This commit is contained in:
Scott Main
2013-08-15 12:22:28 -07:00
parent 3b90aff04c
commit 52dd206715

View File

@@ -183,7 +183,6 @@ $(document).ready(function() {
$("#nav-x li.google a").addClass("selected"); $("#nav-x li.google a").addClass("selected");
} else { } else {
$("#nav-x li.reference a").addClass("selected"); $("#nav-x li.reference a").addClass("selected");
changeApiLevel(); // turn things grey
} }
} else if ((rootDir == "tools") || (rootDir == "sdk")) { } else if ((rootDir == "tools") || (rootDir == "sdk")) {
$("#nav-x li.tools a").addClass("selected"); $("#nav-x li.tools a").addClass("selected");
@@ -825,14 +824,13 @@ function scrollIntoView(nav) {
// If no selected item found, exit // If no selected item found, exit
return; return;
} }
// get the selected item's offset from its container nav by measuring the item's offset
var selectedOffset = $selected.offset().top; // measure offset from top, relative to entire page // relative to the document then subtract the container nav's offset relative to the document
if (selectedOffset > $nav.height() * .8) { // multiply nav height by .8 so we move up any var selectedOffset = $selected.offset().top - $nav.offset().top;
// items more than 80% down the nav if (selectedOffset > $nav.height() * .8) { // multiply nav height by .8 so we move up the item
// scroll the item up by an amount 125px less than the window height (account for site header) // if it's more than 80% down the nav
// and then multiply nav height by .8 to match the 80% threshold used above // scroll the item up by an amount equal to 80% the container nav's height
api.scrollTo(0, selectedOffset - 125 - ($nav.height() * .8), false); 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 */ /* Initialize some droiddoc stuff, but only if we're in the reference */
if (location.pathname.indexOf("/reference")) { if (location.pathname.indexOf("/reference") == 0) {
if(!location.pathname.indexOf("/reference-gms/packages.html") if(!(location.pathname.indexOf("/reference-gms/packages.html") == 0)
&& !location.pathname.indexOf("/reference-gcm/packages.html") && !(location.pathname.indexOf("/reference-gcm/packages.html") == 0)
&& !location.pathname.indexOf("/reference/com/google") == 0) { && !(location.pathname.indexOf("/reference/com/google") == 0)) {
$(document).ready(function() { $(document).ready(function() {
// init available apis based on user pref // init available apis based on user pref
changeApiLevel(); changeApiLevel();