OSDN Git Service

remove the dummy sidenav from samples before populating the real list.
[android-x86/build.git] / tools / droiddoc / templates-sdk / assets / js / docs.js
index ba65e44..12221eb 100644 (file)
@@ -11,7 +11,7 @@ var mPagePath; // initialized in ready() function
 var basePath = getBaseUri(location.pathname);
 var SITE_ROOT = toRoot + basePath.substring(1,basePath.indexOf("/",1));
 var GOOGLE_DATA; // combined data for google service apis, used for search suggest
-  
+
 // Ensure that all ajax getScript() requests allow caching
 $.ajaxSetup({
   cache: true
@@ -59,10 +59,10 @@ $(document).ready(function() {
       toggleFullscreen(false);
     }
   });
-  
+
   // initialize the divs with custom scrollbars
   $('.scroll-pane').jScrollPane( {verticalGutter:0} );
-  
+
   // add HRs below all H2s (except for a few other h2 variants)
   $('h2').not('#qv h2').not('#tb h2').not('.sidebox h2').not('#devdoc-nav h2').not('h2.norule').css({marginBottom:0}).after('<hr/>');
 
@@ -78,7 +78,7 @@ $(document).ready(function() {
   });
 
   // Set up quicknav
-  var quicknav_open = false;  
+  var quicknav_open = false;
   $("#btn-quicknav").click(function() {
     if (quicknav_open) {
       $(this).removeClass('active');
@@ -90,20 +90,20 @@ $(document).ready(function() {
       expand();
     }
   })
-  
+
   var expand = function() {
    $('#header-wrap').addClass('quicknav');
    $('#quicknav').stop().show().animate({opacity:'1'});
   }
-  
+
   var collapse = function() {
     $('#quicknav').stop().animate({opacity:'0'}, 100, function() {
       $(this).hide();
       $('#header-wrap').removeClass('quicknav');
     });
   }
-  
-  
+
+
   //Set up search
   $("#search_autocomplete").focus(function() {
     $("#search-container").addClass('active');
@@ -127,7 +127,7 @@ $(document).ready(function() {
     }
   })
 
-    
+
   // prep nav expandos
   var pagePath = document.location.pathname;
   // account for intl docs by removing the intl/*/ path
@@ -188,6 +188,8 @@ $(document).ready(function() {
       $("#nav-x li.tools a").addClass("selected");
     } else if ($("body").hasClass("google")) {
       $("#nav-x li.google a").addClass("selected");
+    } else if ($("body").hasClass("samples")) {
+      $("#nav-x li.samples a").addClass("selected");
     }
 
   // highlight Distribute tab
@@ -209,7 +211,7 @@ $(document).ready(function() {
     // set up prev links
     var $prevLink = [];
     var $prevListItem = $selListItem.prev('li');
-    
+
     var crossBoundaries = ($("body.design").length > 0) || ($("body.guide").length > 0) ? true :
 false; // navigate across topic boundaries only in design docs
     if ($prevListItem.length) {
@@ -224,10 +226,10 @@ false; // navigate across topic boundaries only in design docs
       // jump to this section's index page (if it exists)
       var $parentListItem = $selListItem.parents('li');
       $prevLink = $selListItem.parents('li').find('a');
-      
+
       // except if cross boundaries aren't allowed, and we're at the top of a section already
       // (and there's another parent)
-      if (!crossBoundaries && $parentListItem.hasClass('nav-section') 
+      if (!crossBoundaries && $parentListItem.hasClass('nav-section')
                            && $selListItem.hasClass('nav-section')) {
         $prevLink = [];
       }
@@ -238,8 +240,8 @@ false; // navigate across topic boundaries only in design docs
     var startClass = false;
     var training = $(".next-class-link").length; // decides whether to provide "next class" link
     var isCrossingBoundary = false;
-    
-    if ($selListItem.hasClass('nav-section')) {
+
+    if ($selListItem.hasClass('nav-section') && $selListItem.children('div.empty').length == 0) {
       // we're on an index page, jump to the first topic
       $nextLink = $selListItem.find('ul:eq(0)').find('a:eq(0)');
 
@@ -251,7 +253,7 @@ false; // navigate across topic boundaries only in design docs
         // then set the landing page "start link" text to be the first doc title
         $('.topic-start-link').text($nextLink.text().toUpperCase());
       }
-      
+
       // If the selected page has a description, then it's a class or article homepage
       if ($selListItem.find('a[description]').length) {
         // this means we're on a class landing page
@@ -260,12 +262,17 @@ false; // navigate across topic boundaries only in design docs
     } else {
       // jump to the next topic in this section (if it exists)
       $nextLink = $selListItem.next('li').find('a:eq(0)');
-      if (!$nextLink.length) {
+      if ($nextLink.length == 0) {
         isCrossingBoundary = true;
         // no more topics in this section, jump to the first topic in the next section
         $nextLink = $selListItem.parents('li:eq(0)').next('li.nav-section').find('a:eq(0)');
         if (!$nextLink.length) {  // Go up another layer to look for next page (lesson > class > course)
           $nextLink = $selListItem.parents('li:eq(1)').next('li.nav-section').find('a:eq(0)');
+          if ($nextLink.length == 0) {
+            // if that doesn't work, we're at the end of the list, so disable NEXT link
+            $('.next-page-link').attr('href','').addClass("disabled")
+                                .click(function() { return false; });
+          }
         }
       }
     }
@@ -273,7 +280,7 @@ false; // navigate across topic boundaries only in design docs
     if (startClass) {
       $('.start-class-link').attr('href', $nextLink.attr('href')).removeClass("hide");
 
-      // if there's no training bar (below the start button), 
+      // if there's no training bar (below the start button),
       // then we need to add a bottom border to button
       if (!$("#tb").length) {
         $('.start-class-link').css({'border-bottom':'1px solid #DADADA'});
@@ -283,10 +290,11 @@ false; // navigate across topic boundaries only in design docs
       $('.next-page-link').attr('href','')
                           .removeClass("hide").addClass("disabled")
                           .click(function() { return false; });
-     
-      $('.next-class-link').attr('href',$nextLink.attr('href'))
-                          .removeClass("hide").append($nextLink.html());
-      $('.next-class-link').find('.new').empty();
+      if ($nextLink.length) {
+        $('.next-class-link').attr('href',$nextLink.attr('href'))
+                             .removeClass("hide").append($nextLink.html());
+        $('.next-class-link').find('.new').empty();
+      }
     } else {
       $('.next-page-link').attr('href', $nextLink.attr('href')).removeClass("hide");
     }
@@ -298,7 +306,7 @@ false; // navigate across topic boundaries only in design docs
       } else {
         $('.prev-page-link').attr('href', $prevLink.attr('href')).removeClass("hide");
       }
-    } 
+    }
 
     // If this is a training 'article', there should be no prev/next nav
     // ... if the grandparent is the "nav" ... and it has no child list items...
@@ -307,16 +315,16 @@ false; // navigate across topic boundaries only in design docs
       $('.next-page-link,.prev-page-link').attr('href','').addClass("disabled")
                           .click(function() { return false; });
     }
-    
+
   }
-  
-  
-  
+
+
+
   // Set up the course landing pages for Training with class names and descriptions
   if ($('body.trainingcourse').length) {
     var $classLinks = $selListItem.find('ul li a').not('#nav .nav-section .nav-section ul a');
     var $classDescriptions = $classLinks.attr('description');
-    
+
     var $olClasses  = $('<ol class="class-list"></ol>');
     var $liClass;
     var $imgIcon;
@@ -328,18 +336,20 @@ false; // navigate across topic boundaries only in design docs
       $liClass  = $('<li></li>');
       $h2Title  = $('<a class="title" href="'+$(this).attr('href')+'"><h2>' + $(this).html()+'</h2><span></span></a>');
       $pSummary = $('<p class="description">' + $(this).attr('description') + '</p>');
-      
+
       $olLessons  = $('<ol class="lesson-list"></ol>');
-      
+
       $lessons = $(this).closest('li').find('ul li a');
-      
+
       if ($lessons.length) {
-        $imgIcon = $('<img src="'+toRoot+'assets/images/resource-tutorial.png" alt=""/>');
+        $imgIcon = $('<img src="'+toRoot+'assets/images/resource-tutorial.png" '
+            + ' width="64" height="64" alt=""/>');
         $lessons.each(function(index) {
           $olLessons.append('<li><a href="'+$(this).attr('href')+'">' + $(this).html()+'</a></li>');
         });
       } else {
-        $imgIcon = $('<img src="'+toRoot+'assets/images/resource-article.png" alt=""/>');
+        $imgIcon = $('<img src="'+toRoot+'assets/images/resource-article.png" '
+            + ' width="64" height="64" alt=""/>');
         $pSummary.addClass('article');
       }
 
@@ -349,36 +359,10 @@ false; // navigate across topic boundaries only in design docs
     $('.jd-descr').append($olClasses);
   }
 
+  // Set up expand/collapse behavior
+  initExpandableNavItems("#nav");
 
 
-
-  // Set up expand/collapse behavior
-  $('#nav li.nav-section .nav-section-header').click(function() {
-    var section = $(this).closest('li.nav-section');
-    if (section.hasClass('expanded')) {
-    /* hide me */
-    //  if (section.hasClass('selected') || section.find('li').hasClass('selected')) {
-   //   /* but not if myself or my descendents are selected */
-   //     return;
-    //  }
-      section.children('ul').slideUp(250, function() {
-        section.closest('li').removeClass('expanded');
-        resizeNav();
-      });
-    } else {
-    /* show me */
-      // first hide all other siblings
-      var $others = $('li.nav-section.expanded', $(this).closest('ul'));
-      $others.removeClass('expanded').children('ul').slideUp(250);
-      
-      // now expand me
-      section.closest('li').addClass('expanded');
-      section.children('ul').slideDown(250, function() {
-        resizeNav();
-      });
-    }
-  });
-  
   $(".scroll-pane").scroll(function(event) {
       event.preventDefault();
       return false;
@@ -410,10 +394,10 @@ false; // navigate across topic boundaries only in design docs
       // from a scrollable div and so there's no need to make adjustments to our layout
       return;
     }
-    var scrollTop = $(window).scrollTop();    
+    var scrollTop = $(window).scrollTop();
     var headerHeight = $('#header').outerHeight();
     var subheaderHeight = $('#nav-x').outerHeight();
-    var searchResultHeight = $('#searchResults').is(":visible") ? 
+    var searchResultHeight = $('#searchResults').is(":visible") ?
                              $('#searchResults').outerHeight() : 0;
     var totalHeaderHeight = headerHeight + subheaderHeight + searchResultHeight;
     // we set the navbar fixed when the scroll position is beyond the height of the site header...
@@ -423,20 +407,20 @@ false; // navigate across topic boundaries only in design docs
     if ($("#doc-col").height() < $("#side-nav").height()) {
       navBarShouldBeFixed = false;
     }
-   
+
     var scrollLeft = $(window).scrollLeft();
     // When the sidenav is fixed and user scrolls horizontally, reposition the sidenav to match
     if (navBarIsFixed && (scrollLeft != prevScrollLeft)) {
       updateSideNavPosition();
       prevScrollLeft = scrollLeft;
     }
-    
-    // Don't continue if the header is sufficently far away 
+
+    // Don't continue if the header is sufficently far away
     // (to avoid intensive resizing that slows scrolling)
     if (navBarIsFixed && navBarShouldBeFixed) {
       return;
     }
-    
+
     if (navBarIsFixed != navBarShouldBeFixed) {
       if (navBarShouldBeFixed) {
         // make it fixed
@@ -447,7 +431,7 @@ false; // navigate across topic boundaries only in design docs
             .prependTo('#body-content');
         // add neato "back to top" button
         $('#devdoc-nav a.totop').css({'display':'block','width':$("#nav").innerWidth()+'px'});
-        
+
         // update the sidenaav position for side scrolling
         updateSideNavPosition();
       } else {
@@ -459,25 +443,18 @@ false; // navigate across topic boundaries only in design docs
         $('#devdoc-nav a.totop').hide();
       }
       navBarIsFixed = navBarShouldBeFixed;
-    } 
-    
+    }
+
     resizeNav(250); // pass true in order to delay the scrollbar re-initialization for performance
   });
 
-  
+
   var navBarLeftPos;
   if ($('#devdoc-nav').length) {
     setNavBarLeftPos();
   }
 
 
-  // Stop expand/collapse behavior when clicking on nav section links (since we're navigating away
-  // from the page)
-  $('.nav-section-header').find('a:eq(0)').click(function(evt) {
-    window.location.href = $(this).attr('href');
-    return false;
-  });
-
   // Set up play-on-hover <video> tags.
   $('video.play-on-hover').bind('click', function(){
     $(this).get(0).load(); // in case the video isn't seekable
@@ -527,16 +504,16 @@ false; // navigate across topic boundaries only in design docs
   var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
 
 
-  // Revise the sidenav widths to make room for the scrollbar 
+  // Revise the sidenav widths to make room for the scrollbar
   // which avoids the visible width from changing each time the bar appears
   var $sidenav = $("#side-nav");
   var sidenav_width = parseInt($sidenav.innerWidth());
-    
+
   $("#devdoc-nav  #nav").css("width", sidenav_width - 4 + "px"); // 4px is scrollbar width
 
 
   $(".scroll-pane").removeAttr("tabindex"); // get rid of tabindex added by jscroller
-  
+
   if ($(".scroll-pane").length > 1) {
     // Check if there's a user preference for the panel heights
     var cookieHeight = readCookie("reference_height");
@@ -544,7 +521,7 @@ false; // navigate across topic boundaries only in design docs
       restoreHeight(cookieHeight);
     }
   }
-  
+
   resizeNav();
 
   /* init the language selector based on user cookie for lang */
@@ -582,16 +559,60 @@ false; // navigate across topic boundaries only in design docs
 // END of the onload event
 
 
+function initExpandableNavItems(rootTag) {
+  $(rootTag + ' li.nav-section .nav-section-header').click(function() {
+    var section = $(this).closest('li.nav-section');
+    if (section.hasClass('expanded')) {
+    /* hide me and descendants */
+      section.find('ul').slideUp(250, function() {
+        // remove 'expanded' class from my section and any children
+        section.closest('li').removeClass('expanded');
+        $('li.nav-section', section).removeClass('expanded');
+        resizeNav();
+      });
+    } else {
+    /* show me */
+      // first hide all other siblings
+      var $others = $('li.nav-section.expanded', $(this).closest('ul')).not('.sticky');
+      $others.removeClass('expanded').children('ul').slideUp(250);
+
+      // now expand me
+      section.closest('li').addClass('expanded');
+      section.children('ul').slideDown(250, function() {
+        resizeNav();
+      });
+    }
+  });
+
+  // Stop expand/collapse behavior when clicking on nav section links
+  // (since we're navigating away from the page)
+  // This selector captures the first instance of <a>, but not those with "#" as the href.
+  $('.nav-section-header').find('a:eq(0)').not('a[href="#"]').click(function(evt) {
+    window.location.href = $(this).attr('href');
+    return false;
+  });
+}
+
+/** Highlight the current page in sidenav, expanding children as appropriate */
 function highlightSidenav() {
-  // select current page in sidenav and header, and set up prev/next links if they exist
-  var $selNavLink = $('#nav').find('a[href="' + mPagePath + '"]');
+  // if something is already highlighted, undo it. This is for dynamic navigation (Samples index)
+  if ($("ul#nav li.selected").length) {
+    unHighlightSidenav();
+  }
+  // look for URL in sidenav, including the hash
+  var $selNavLink = $('#nav').find('a[href="' + mPagePath + location.hash + '"]');
+
+  // If the selNavLink is still empty, look for it without the hash
+  if ($selNavLink.length == 0) {
+    $selNavLink = $('#nav').find('a[href="' + mPagePath + '"]');
+  }
+
   var $selListItem;
   if ($selNavLink.length) {
-
     // Find this page's <li> in sidenav and set selected
     $selListItem = $selNavLink.closest('li');
     $selListItem.addClass('selected');
-    
+
     // Traverse up the tree and expand all parent nav-sections
     $selNavLink.parents('li.nav-section').each(function() {
       $(this).addClass('expanded');
@@ -600,6 +621,10 @@ function highlightSidenav() {
   }
 }
 
+function unHighlightSidenav() {
+  $("ul#nav li.selected").removeClass("selected");
+  $('ul#nav li.nav-section.expanded').removeClass('expanded').children('ul').hide();
+}
 
 function toggleFullscreen(enable) {
   var delay = 20;
@@ -637,13 +662,6 @@ function updateSideNavPosition() {
   $('#devdoc-nav').css({left: -newLeft});
   $('#devdoc-nav .totop').css({left: -(newLeft - parseInt($('#side-nav').css('margin-left')))});
 }
-  
-
-
-
-
-
-
 
 // TODO: use $(document).ready instead
 function addLoadEvent(newfun) {
@@ -668,10 +686,10 @@ if ((agent.indexOf("mobile") != -1) ||      // android, iphone, ipod
 }
 
 
-addLoadEvent( function() {
+$(document).ready(function() {
   $("pre:not(.no-pretty-print)").addClass("prettyprint");
   prettyPrint();
-} );
+});
 
 
 
@@ -682,7 +700,7 @@ function resizeNav(delay) {
   var $nav = $("#devdoc-nav");
   var $window = $(window);
   var navHeight;
-  
+
   // Get the height of entire window and the total header height.
   // Then figure out based on scroll position whether the header is visible
   var windowHeight = $window.height();
@@ -690,12 +708,12 @@ function resizeNav(delay) {
   var headerHeight = $('#header').outerHeight();
   var subheaderHeight = $('#nav-x').outerHeight();
   var headerVisible = (scrollTop < (headerHeight + subheaderHeight));
-  
-  // get the height of space between nav and top of window. 
+
+  // get the height of space between nav and top of window.
   // Could be either margin or top position, depending on whether the nav is fixed.
-  var topMargin = (parseInt($nav.css('margin-top')) || parseInt($nav.css('top'))) + 1; 
+  var topMargin = (parseInt($nav.css('margin-top')) || parseInt($nav.css('top'))) + 1;
   // add 1 for the #side-nav bottom margin
-  
+
   // Depending on whether the header is visible, set the side nav's height.
   if (headerVisible) {
     // The sidenav height grows as the header goes off screen
@@ -704,44 +722,44 @@ function resizeNav(delay) {
     // Once header is off screen, the nav height is almost full window height
     navHeight = windowHeight - topMargin;
   }
-  
-  
-  
+
+
+
   $scrollPanes = $(".scroll-pane");
   if ($scrollPanes.length > 1) {
     // subtract the height of the api level widget and nav swapper from the available nav height
     navHeight -= ($('#api-nav-header').outerHeight(true) + $('#nav-swap').outerHeight(true));
-    
+
     $("#swapper").css({height:navHeight + "px"});
     if ($("#nav-tree").is(":visible")) {
       $("#nav-tree").css({height:navHeight});
     }
-    
-    var classesHeight = navHeight - parseInt($("#resize-packages-nav").css("height")) - 10 + "px"; 
+
+    var classesHeight = navHeight - parseInt($("#resize-packages-nav").css("height")) - 10 + "px";
     //subtract 10px to account for drag bar
-    
-    // if the window becomes small enough to make the class panel height 0, 
+
+    // if the window becomes small enough to make the class panel height 0,
     // then the package panel should begin to shrink
     if (parseInt(classesHeight) <= 0) {
       $("#resize-packages-nav").css({height:navHeight - 10}); //subtract 10px for drag bar
       $("#packages-nav").css({height:navHeight - 10});
     }
-    
+
     $("#classes-nav").css({'height':classesHeight, 'margin-top':'10px'});
     $("#classes-nav .jspContainer").css({height:classesHeight});
-    
-    
+
+
   } else {
     $nav.height(navHeight);
   }
-  
+
   if (delay) {
     updateFromResize = true;
     delayedReInitScrollbars(delay);
   } else {
     reInitScrollbars();
   }
-  
+
 }
 
 var updateScrollbars = false;
@@ -760,7 +778,7 @@ function delayedReInitScrollbars(delay) {
     updateFromResize = false;
     return;
   }
-  
+
   // We're scheduled for an update and the update request came from this method's setTimeout
   if (updateScrollbars && !updateFromResize) {
     reInitScrollbars();
@@ -778,7 +796,7 @@ function reInitScrollbars() {
     var api = $(this).data('jsp');
     if (!api) { setTimeout(reInitScrollbars,300); return;}
     api.reinitialise( {verticalGutter:0} );
-  });  
+  });
   $(".scroll-pane").removeAttr("tabindex"); // get rid of tabindex added by jscroller
 }
 
@@ -809,7 +827,7 @@ function restoreHeight(packageHeight) {
 
 
 
-/** Scroll the jScrollPane to make the currently selected item visible 
+/** Scroll the jScrollPane to make the currently selected item visible
     This is called when the page finished loading. */
 function scrollIntoView(nav) {
   var $nav = $("#"+nav);
@@ -818,13 +836,17 @@ 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;
+    }
+    // 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);
     }
   }
 }
@@ -873,7 +895,7 @@ function writeCookie(cookie, val, section, expiration) {
     date.setTime(date.getTime()+(10*365*24*60*60*1000)); // default expiration is one week
     expiration = date.toGMTString();
   }
-  var cookieValue = cookie_namespace + section + cookie + "=" + val 
+  var cookieValue = cookie_namespace + section + cookie + "=" + val
                     + "; expires=" + expiration+"; path=/";
   document.cookie = cookieValue;
 }
@@ -1012,7 +1034,7 @@ function swapNav() {
   $("#panel-link").toggle();
   $("#nav-tree").toggle();
   $("#tree-link").toggle();
-  
+
   resizeNav();
 
   // Gross nasty hack to make tree view show up upon first swap by setting height manually
@@ -1020,7 +1042,7 @@ function swapNav() {
       .css({'height':$("#nav-tree .jspContainer .jspPane").height() +'px'});
   // Another nasty hack to make the scrollbar appear now that we have height
   resizeNav();
-  
+
   if ($("#nav-tree").is(':visible')) {
     scrollIntoView("nav-tree");
   } else {
@@ -1075,7 +1097,7 @@ function changeNavLang(lang) {
 
 function changeLangPref(lang, submit) {
   var date = new Date();
-  expires = date.toGMTString(date.setTime(date.getTime()+(10*365*24*60*60*1000))); 
+  expires = date.toGMTString(date.setTime(date.getTime()+(10*365*24*60*60*1000)));
   // keep this for 50 years
   //alert("expires: " + expires)
   writeCookie("pref_lang", lang, null, expires);
@@ -1120,19 +1142,21 @@ function getLangPref() {
 /* Used to hide and reveal supplemental content, such as long code samples.
    See the companion CSS in android-developer-docs.css */
 function toggleContent(obj) {
-  var div = $(obj.parentNode.parentNode);
-  var toggleMe = $(".toggle-content-toggleme",div);
+  var div = $(obj).closest(".toggle-content");
+  var toggleMe = $(".toggle-content-toggleme:eq(0)",div);
   if (div.hasClass("closed")) { // if it's closed, open it
     toggleMe.slideDown();
-    $(".toggle-content-text", obj).toggle();
+    $(".toggle-content-text:eq(0)", obj).toggle();
     div.removeClass("closed").addClass("open");
-    $(".toggle-content-img", div).attr("title", "hide").attr("src", toRoot 
+    $(".toggle-content-img:eq(0)", div).attr("title", "hide").attr("src", toRoot
                   + "assets/images/triangle-opened.png");
   } else { // if it's open, close it
     toggleMe.slideUp('fast', function() {  // Wait until the animation is done before closing arrow
-      $(".toggle-content-text", obj).toggle();
+      $(".toggle-content-text:eq(0)", obj).toggle();
       div.removeClass("open").addClass("closed");
-      $(".toggle-content-img", div).attr("title", "show").attr("src", toRoot 
+      div.find(".toggle-content").removeClass("open").addClass("closed")
+              .find(".toggle-content-toggleme").hide();
+      $(".toggle-content-img", div).attr("title", "show").attr("src", toRoot
                   + "assets/images/triangle-closed.png");
     });
   }
@@ -1160,7 +1184,7 @@ function hideExpandable(ids) {
 
 
 
-/*    
+/*
  *  Slideshow 1.0
  *  Used on /index.html and /develop/index.html for carousel
  *
@@ -1201,7 +1225,7 @@ function hideExpandable(ids) {
 
  (function($) {
  $.fn.dacSlideshow = function(o) {
-     
+
      //Options - see above
      o = $.extend({
          btnPrev:   null,
@@ -1216,8 +1240,8 @@ function hideExpandable(ids) {
          pagination: true
 
      }, o || {});
-     
-     //Set up a carousel for each 
+
+     //Set up a carousel for each
      return this.each(function() {
 
          var running = false;
@@ -1226,7 +1250,7 @@ function hideExpandable(ids) {
          var div = $(this);
          var ul = $("ul", div);
          var tLi = $("li", ul);
-         var tl = tLi.size(); 
+         var tl = tLi.size();
          var timer = null;
 
          var li = $("li", ul);
@@ -1245,7 +1269,7 @@ function hideExpandable(ids) {
          ul.css(sizeCss, ulSize+"px").css(animCss, -(curr*liSize));
 
          div.css(sizeCss, divSize+"px");
-         
+
          //Pagination
          if (o.pagination) {
              var pagination = $("<div class='pagination'></div>");
@@ -1263,7 +1287,7 @@ function hideExpandable(ids) {
                 div.append(pagination);
              }
          }
-         
+
          //Previous button
          if(o.btnPrev)
              $(o.btnPrev).click(function(e) {
@@ -1288,18 +1312,18 @@ function hideExpandable(ids) {
                      pauseRotateTimer();
                  }
              });
-         
+
          //Auto rotation
          if(o.auto) startRotateTimer();
-             
+
          function startRotateTimer() {
              clearInterval(timer);
              timer = setInterval(function() {
                   if (curr == tl-1) {
                     go(0);
                   } else {
-                    go(curr+o.scroll);  
-                  } 
+                    go(curr+o.scroll);
+                  }
               }, o.autoTime);
              $(o.btnPause).removeClass('paused');
          }
@@ -1337,11 +1361,11 @@ function hideExpandable(ids) {
                     []
                   ).addClass("disabled");
 
-                 
+
                  var nav_items = $('li', pagination);
                  nav_items.removeClass('active');
                  nav_items.eq(to).addClass('active');
-                 
+
 
              }
              if(o.auto) startRotateTimer();
@@ -1363,7 +1387,7 @@ function hideExpandable(ids) {
  })(jQuery);
 
 
-/*  
+/*
  *  dacSlideshow 1.0
  *  Used on develop/index.html for side-sliding tabs
  *
@@ -1402,7 +1426,7 @@ function hideExpandable(ids) {
  */
  (function($) {
  $.fn.dacTabbedList = function(o) {
-     
+
      //Options - see above
      o = $.extend({
          speed : 250,
@@ -1410,8 +1434,8 @@ function hideExpandable(ids) {
          nav_id: null,
          frame_id: null
      }, o || {});
-     
-     //Set up a carousel for each 
+
+     //Set up a carousel for each
      return this.each(function() {
 
          var curr = 0;
@@ -1419,17 +1443,17 @@ function hideExpandable(ids) {
          var animCss = "margin-left";
          var sizeCss = "width";
          var div = $(this);
-         
+
          var nav = $(o.nav_id, div);
          var nav_li = $("li", nav);
-         var nav_size = nav_li.size(); 
+         var nav_size = nav_li.size();
          var frame = div.find(o.frame_id);
          var content_width = $(frame).find('ul').width();
          //Buttons
          $(nav_li).click(function(e) {
            go($(nav_li).index($(this)));
          })
-         
+
          //Go to an item
          function go(to) {
              if(!running) {
@@ -1442,10 +1466,10 @@ function hideExpandable(ids) {
                      }
                  );
 
-                 
+
                  nav_li.removeClass('active');
                  nav_li.eq(to).addClass('active');
-                 
+
 
              }
              return false;
@@ -1652,7 +1676,7 @@ function sync_selection_table(toroot)
   * otherwise invokes search suggestions on key-up event.
   * @param e       The JS event
   * @param kd      True if the event is key-down
-  * @param toroot  A string for the site's root path 
+  * @param toroot  A string for the site's root path
   * @returns       True if the event should bubble up
   */
 function search_changed(e, kd, toroot)
@@ -1746,7 +1770,7 @@ function search_changed(e, kd, toroot)
         if ($($("li", $selectedUl)[gSelectedIndex]).hasClass("header")) {
           gSelectedIndex++;
         }
-        // set item selected       
+        // set item selected
         $('li:nth-child('+(gSelectedIndex+1)+')', $selectedUl).addClass('jd-selected');
         return false;
       }
@@ -1764,7 +1788,7 @@ function search_changed(e, kd, toroot)
         if ($($("li", $selectedUl)[gSelectedIndex]).hasClass("header")) {
           gSelectedIndex++;
         }
-        // set item selected       
+        // set item selected
         $('li:nth-child('+(gSelectedIndex+1)+')', $selectedUl).addClass('jd-selected');
         return false;
       }
@@ -1995,7 +2019,7 @@ function highlight_autocomplete_result_labels(query) {
 
 function search_focus_changed(obj, focused)
 {
-    if (!focused) {     
+    if (!focused) {
         if(obj.value == ""){
           $(".search .close").addClass("hide");
         }
@@ -2016,9 +2040,9 @@ function hideResults() {
   $("#searchResults").slideUp();
   $(".search .close").addClass("hide");
   location.hash = '';
-  
+
   $("#search_autocomplete").val("").blur();
-  
+
   // reset the ajax search callback to nothing, so results don't appear unless ENTER
   searchControl.setSearchStartingCallback(this, function(control, searcher, query) {});
 
@@ -2138,6 +2162,12 @@ google.setOnLoadCallback(function(){
 
 // when an event on the browser history occurs (back, forward, load) requery hash and do search
 $(window).hashchange( function(){
+  // Handle hash changes in the samples browser
+  if ($("body").hasClass("samples") && location.href.indexOf("/samples/index.html") != -1) {
+    showSamples();
+    highlightSidenav();
+    resizeNav();
+  }
   // Exit if the hash isn't a search query or there's an error in the query
   if ((location.hash.indexOf("q=") == -1) || (query == "undefined")) {
     // If the results pane is open, close it.
@@ -2176,10 +2206,10 @@ function addTabListeners() {
       setTimeout(function() {
         // remove any residual page numbers
         $('#searchResults .gsc-tabsArea .gsc-cursor-box.gs-bidi-start-align').remove();
-        // move the page numbers to the left position; make a clone, 
+        // move the page numbers to the left position; make a clone,
         // because the element is drawn to the DOM only once
-        // and because we're going to remove it (previous line), 
-        // we need it to be available to move again as the user navigates 
+        // and because we're going to remove it (previous line),
+        // we need it to be available to move again as the user navigates
         $('#searchResults .gsc-webResult .gsc-cursor-box.gs-bidi-start-align:visible')
                         .clone().appendTo('#searchResults .gsc-tabsArea');
         }, 200);
@@ -2224,10 +2254,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();
@@ -2241,22 +2271,22 @@ var minLevel = 1;
 var maxLevel = 1;
 
 /******* SIDENAV DIMENSIONS ************/
-  
+
   function initSidenavHeightResize() {
     // Change the drag bar size to nicely fit the scrollbar positions
     var $dragBar = $(".ui-resizable-s");
     $dragBar.css({'width': $dragBar.parent().width() - 5 + "px"});
-    
-    $( "#resize-packages-nav" ).resizable({ 
+
+    $( "#resize-packages-nav" ).resizable({
       containment: "#nav-panels",
       handles: "s",
       alsoResize: "#packages-nav",
       resize: function(event, ui) { resizeNav(); }, /* resize the nav while dragging */
       stop: function(event, ui) { saveNavPanels(); } /* once stopped, save the sizes to cookie  */
       });
-          
+
   }
-  
+
 function updateSidenavFixedWidth() {
   if (!navBarIsFixed) return;
   $('#devdoc-nav').css({
@@ -2264,7 +2294,7 @@ function updateSidenavFixedWidth() {
     'margin' : $('#side-nav').css('margin')
   });
   $('#devdoc-nav a.totop').css({'display':'block','width':$("#nav").innerWidth()+'px'});
-  
+
   initSidenavHeightResize();
 }
 
@@ -2275,7 +2305,7 @@ function updateSidenavFullscreenWidth() {
     'margin' : $('#side-nav').css('margin')
   });
   $('#devdoc-nav .totop').css({'left': 'inherit'});
-  
+
   initSidenavHeightResize();
 }
 
@@ -2359,7 +2389,7 @@ function toggleVisisbleApis(selectedLevel, context) {
     if (apiLevelNum > selectedLevelNum) {
       obj.addClass("absent").attr("title","Requires API Level \""
             + apiLevel + "\" or higher");
-    } 
+    }
     else obj.removeClass("absent").removeAttr("title");
   });
 }
@@ -2428,7 +2458,7 @@ function new_node(me, mom, text, link, children_data, api_level)
       node.expanded = false;
     }
   }
-  
+
 
   node.children_ul = null;
   node.get_children_ul = function() {
@@ -2456,7 +2486,7 @@ function expand_node(me, node)
       get_node(me, node);
       if ($(node.label_div).hasClass("absent")) {
         $(node.get_children_ul()).addClass("absent");
-      } 
+      }
       $(node.get_children_ul()).slideDown("fast");
     }
     node.plus_img.src = me.toroot + "assets/images/triangle-opened-small.png";
@@ -2532,7 +2562,7 @@ function init_default_navtree(toroot) {
           init_navtree("tree-list", toroot, NAVTREE_DATA);
       }
   });
-  
+
   // perform api level toggling because because the whole tree is new to the DOM
   var selectedLevel = $("#apiLevelSelector option:selected").val();
   toggleVisisbleApis(selectedLevel, "#side-nav");
@@ -2571,6 +2601,13 @@ function init_navtree(navtree_id, toroot, root_nodes)
   }
 }
 
+
+
+
+
+
+
+
 /* TODO: eliminate redundancy with non-google functions */
 function init_google_navtree(navtree_id, toroot, root_nodes)
 {
@@ -2599,8 +2636,8 @@ function new_google_node(me, mom, text, link, children_data, api_level)
   node.depth = mom.depth + 1;
   node.get_children_ul = function() {
       if (!node.children_ul) {
-        node.children_ul = document.createElement("ul"); 
-        node.children_ul.className = "tree-list-children"; 
+        node.children_ul = document.createElement("ul");
+        node.children_ul.className = "tree-list-children";
         node.li.appendChild(node.children_ul);
       }
       return node.children_ul;
@@ -2608,8 +2645,8 @@ function new_google_node(me, mom, text, link, children_data, api_level)
   node.li = document.createElement("li");
 
   mom.get_children_ul().appendChild(node.li);
-  
-  
+
+
   if(link) {
     child = document.createElement("a");
 
@@ -2622,7 +2659,7 @@ function new_google_node(me, mom, text, link, children_data, api_level)
   if (children_data != null) {
     node.li.className="nav-section";
     node.label_div = document.createElement("div");
-    node.label_div.className = "nav-section-header-ref";  
+    node.label_div.className = "nav-section-header-ref";
     node.li.appendChild(node.label_div);
     get_google_node(me, node);
     node.label_div.appendChild(child);
@@ -2656,6 +2693,77 @@ function get_google_node(me, mom)
           node_data[2], node_data[3]);
   }
 }
+
+
+
+
+
+
+/****** NEW version of script to build google and sample navs dynamically ******/
+// TODO: update Google reference docs to tolerate this new implementation
+
+var NODE_NAME = 0;
+var NODE_HREF = 1;
+var NODE_GROUP = 2;
+var NODE_TAGS = 3;
+var NODE_CHILDREN = 4;
+
+function init_google_navtree2(navtree_id, data)
+{
+  var $containerUl = $("#"+navtree_id);
+  for (var i in data) {
+    var node_data = data[i];
+    $containerUl.append(new_google_node2(node_data));
+  }
+
+  // Make all third-generation list items 'sticky' to prevent them from collapsing
+  $containerUl.find('li li li.nav-section').addClass('sticky');
+
+  initExpandableNavItems("#"+navtree_id);
+}
+
+function new_google_node2(node_data)
+{
+  var linkText = node_data[NODE_NAME];
+  if(linkText.match("^"+"com.google.android")=="com.google.android"){
+    linkText = linkText.substr(19, linkText.length);
+  }
+  var $li = $('<li>');
+  var $a;
+  if (node_data[NODE_HREF] != null) {
+    $a = $('<a href="' + toRoot + node_data[NODE_HREF] + '" title="' + linkText + '" >'
+        + linkText + '</a>');
+  } else {
+    $a = $('<a href="#" onclick="return false;" title="' + linkText + '" >'
+        + linkText + '/</a>');
+  }
+  var $childUl = $('<ul>');
+  if (node_data[NODE_CHILDREN] != null) {
+    $li.addClass("nav-section");
+    $a = $('<div class="nav-section-header">').append($a);
+    if (node_data[NODE_HREF] == null) $a.addClass('empty');
+
+    for (var i in node_data[NODE_CHILDREN]) {
+      var child_node_data = node_data[NODE_CHILDREN][i];
+      $childUl.append(new_google_node2(child_node_data));
+    }
+    $li.append($childUl);
+  }
+  $li.prepend($a);
+
+  return $li;
+}
+
+
+
+
+
+
+
+
+
+
+
 function showGoogleRefTree() {
   init_default_google_navtree(toRoot);
   init_default_gcm_navtree(toRoot);
@@ -2685,6 +2793,28 @@ function init_default_gcm_navtree(toroot) {
   });
 }
 
+function showSamplesRefTree() {
+  init_default_samples_navtree(toRoot);
+}
+
+function init_default_samples_navtree(toroot) {
+  // load json file for navtree data
+  $.getScript(toRoot + 'samples_navtree_data.js', function(data, textStatus, jqxhr) {
+      // when the file is loaded, initialize the tree
+      if(jqxhr.status === 200) {
+          // hack to remove the "about the samples" link then put it back in
+          // after we nuke the list to remove the dummy static list of samples
+          var $firstLi = $("#nav.samples-nav > li:first-child").clone();
+          $("#nav.samples-nav").empty();
+          $("#nav.samples-nav").append($firstLi);
+
+          init_google_navtree2("nav.samples-nav", SAMPLES_NAVTREE_DATA);
+          highlightSidenav();
+          resizeNav();
+      }
+  });
+}
+
 /* TOGGLE INHERITED MEMBERS */
 
 /* Toggle an inherited class (arrow toggle)
@@ -2778,3 +2908,62 @@ var control = mac ? e.metaKey && !e.ctrlKey : e.ctrlKey; // get ctrl key
     ensureAllInheritedExpanded();
   }
 });
+
+
+
+
+
+
+/* On-demand functions */
+
+/** Move sample code line numbers out of PRE block and into non-copyable column */
+function initCodeLineNumbers() {
+  var numbers = $("#codesample-block a.number");
+  if (numbers.length) {
+    $("#codesample-line-numbers").removeClass("hidden").append(numbers);
+  }
+
+  $(document).ready(function() {
+    // select entire line when clicked
+    $("span.code-line").click(function() {
+      if (!shifted) {
+        selectText(this);
+      }
+    });
+    // invoke line link on double click
+    $(".code-line").dblclick(function() {
+      document.location.hash = $(this).attr('id');
+    });
+    // highlight the line when hovering on the number
+    $("#codesample-line-numbers a.number").mouseover(function() {
+      var id = $(this).attr('href');
+      $(id).css('background','#e7e7e7');
+    });
+    $("#codesample-line-numbers a.number").mouseout(function() {
+      var id = $(this).attr('href');
+      $(id).css('background','none');
+    });
+  });
+}
+
+// create SHIFT key binder to avoid the selectText method when selecting multiple lines
+var shifted = false;
+$(document).bind('keyup keydown', function(e){shifted = e.shiftKey; return true;} );
+
+// courtesy of jasonedelman.com
+function selectText(element) {
+    var doc = document
+        , range, selection
+    ;
+    if (doc.body.createTextRange) { //ms
+        range = doc.body.createTextRange();
+        range.moveToElementText(element);
+        range.select();
+    } else if (window.getSelection) { //all others
+        selection = window.getSelection();
+        range = doc.createRange();
+        range.selectNodeContents(element);
+        selection.removeAllRanges();
+        selection.addRange(range);
+    }
+}