diff --git a/tools/droiddoc/templates-sdk/assets/js/docs.js b/tools/droiddoc/templates-sdk/assets/js/docs.js index 87cbcd3544..1659cc673b 100644 --- a/tools/droiddoc/templates-sdk/assets/js/docs.js +++ b/tools/droiddoc/templates-sdk/assets/js/docs.js @@ -587,12 +587,22 @@ function initExpandableNavItems(rootTag) { }); } +/** 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
  • in sidenav and set selected $selListItem = $selNavLink.closest('li'); $selListItem.addClass('selected'); @@ -605,6 +615,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; @@ -2142,6 +2156,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. @@ -2676,10 +2696,15 @@ function get_google_node(me, mom) /****** 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); - var linkText; for (var i in data) { var node_data = data[i]; $containerUl.append(new_google_node2(node_data)); @@ -2690,25 +2715,25 @@ function init_google_navtree2(navtree_id, data) function new_google_node2(node_data) { - var linkText = node_data[0]; + var linkText = node_data[NODE_NAME]; if(linkText.match("^"+"com.google.android")=="com.google.android"){ linkText = linkText.substr(19, linkText.length); } var $li = $('
  • '); var $a; - if (node_data[1] != null) { - $a = $('' + linkText + ''); + if (node_data[NODE_HREF] != null) { + $a = $('' + linkText + ''); } else { $a = $('' + linkText + '/'); } var $childUl = $('