OSDN Git Service

fix sidebar autoscroll when the selected doc is not visible.
[android-x86/build.git] / tools / droiddoc / templates-sdk / assets / js / docs.js
index f61cf1e..8fd442c 100644 (file)
@@ -183,6 +183,7 @@ $(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");
@@ -818,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);
+
     }
   }
 }
@@ -898,52 +904,7 @@ function writeCookie(cookie, val, section, expiration) {
 
 
 
-
-
-
-
-
-
-/*
-
-REMEMBER THE PREVIOUS PAGE FOR EACH TAB
-
-function loadLast(cookiePath) {
-  var location = window.location.href;
-  if (location.indexOf("/"+cookiePath+"/") != -1) {
-    return true;
-  }
-  var lastPage = readCookie(cookiePath + "_lastpage");
-  if (lastPage) {
-    window.location = lastPage;
-    return false;
-  }
-  return true;
-}
-
-
-
-$(window).unload(function(){
-  var path = getBaseUri(location.pathname);
-  if (path.indexOf("/reference/") != -1) {
-    writeCookie("lastpage", path, "reference", null);
-  } else if (path.indexOf("/guide/") != -1) {
-    writeCookie("lastpage", path, "guide", null);
-  } else if ((path.indexOf("/resources/") != -1) || (path.indexOf("/training/") != -1)) {
-    writeCookie("lastpage", path, "resources", null);
-  }
-});
-
-*/
-
-
-
-
-
-
-
-
-
+/*      MISC LIBRARY FUNCTIONS     */
 
 
 
@@ -970,9 +931,6 @@ function toggle(obj, slide) {
 }
 
 
-
-
-
 function buildToggleLists() {
   $(".toggle-list").each(
     function(i) {
@@ -983,7 +941,19 @@ function buildToggleLists() {
 
 
 
-
+function hideNestedItems(list, toggle) {
+  $list = $(list);
+  // hide nested lists
+  if($list.hasClass('showing')) {
+    $("li ol", $list).hide('fast');
+    $list.removeClass('showing');
+  // show nested lists
+  } else {
+    $("li ol", $list).show('fast');
+    $list.addClass('showing');
+  }
+  $(".more,.less",$(toggle)).toggle();
+}