var cookie_namespace = 'android_developer'; var isMobile = false; // true if mobile, so we can adjust some layout var mPagePath; // initialized in ready() function var basePath = getBaseUri(location.pathname); var SITE_ROOT = toRoot + basePath.substring(1, basePath.indexOf("/", 1)); // Ensure that all ajax getScript() requests allow caching $.ajaxSetup({ cache: true }); /****** ON LOAD SET UP STUFF *********/ $(document).ready(function() { // prep nav expandos var pagePath = devsite ? location.href.replace(location.hash, '') : document.location.pathname; // account for intl docs by removing the intl/*/ path if (pagePath.indexOf("/intl/") == 0) { pagePath = pagePath.substr(pagePath.indexOf("/", 6)); // start after intl/ to get last / } if (pagePath.indexOf(SITE_ROOT) == 0) { if (pagePath == '' || pagePath.charAt(pagePath.length - 1) == '/') { pagePath += 'index.html'; } } // Need a copy of the pagePath before it gets changed in the next block; // it's needed to perform proper tab highlighting in offline docs (see rootDir below) var pagePathOriginal = pagePath; if (SITE_ROOT.match(/\.\.\//) || SITE_ROOT == '') { // If running locally, SITE_ROOT will be a relative path, so account for that by // finding the relative URL to this page. This will allow us to find links on the page // leading back to this page. var pathParts = pagePath.split('/'); var relativePagePathParts = []; var upDirs = (SITE_ROOT.match(/(\.\.\/)+/) || [''])[0].length / 3; for (var i = 0; i < upDirs; i++) { relativePagePathParts.push('..'); } for (var i = 0; i < upDirs; i++) { relativePagePathParts.push(pathParts[pathParts.length - (upDirs - i) - 1]); } relativePagePathParts.push(pathParts[pathParts.length - 1]); pagePath = relativePagePathParts.join('/'); } else { // Otherwise the page path is already an absolute URL } // set global variable so we can highlight the sidenav a bit later (such as for google reference) // and highlight the sidenav mPagePath = pagePath; highlightSidenav(); // set up prev/next links if they exist var $selNavLink = $('#nav').find('a[href="' + pagePath + '"]'); var $selListItem; if ($selNavLink.length) { $selListItem = $selNavLink.closest('li'); // 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) { if ($prevListItem.hasClass('nav-section') || crossBoundaries) { // jump to last topic of previous section $prevLink = $prevListItem.find('a:last'); } else if (!$selListItem.hasClass('nav-section')) { // jump to previous topic in this section $prevLink = $prevListItem.find('a:eq(0)'); } } else { // 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') && $selListItem.hasClass('nav-section')) { $prevLink = []; } } // set up next links var $nextLink = []; var startClass = false; var isCrossingBoundary = false; 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)'); // if there aren't any children, go to the next section (required for About pages) if ($nextLink.length == 0) { $nextLink = $selListItem.next('li').find('a'); } else if ($('.topic-start-link').length) { // as long as there's a child link and there is a "topic start link" (we're on a landing) // 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 startClass = true; } } else { // jump to the next topic in this section (if it exists) $nextLink = $selListItem.next('li').find('a:eq(0)'); 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').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; }); // and completely hide the one in the footer $('.content-footer .next-page-link').hide(); } } } } if (startClass) { $('.start-class-link').attr('href', $nextLink.attr('href')).removeClass("hide"); // 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'}); } } else if (isCrossingBoundary && !$('body.design').length) { // Design always crosses boundaries $('.content-footer.next-class').show(); $('.next-page-link').attr('href', '') .removeClass("hide").addClass("disabled") .click(function() { return false; }); // and completely hide the one in the footer $('.content-footer .next-page-link').hide(); $('.content-footer .prev-page-link').hide(); if ($nextLink.length) { $('.next-class-link').attr('href', $nextLink.attr('href')) .removeClass("hide"); $('.content-footer .next-class-link').append($nextLink.html()); $('.next-class-link').find('.new').empty(); } } else { $('.next-page-link').attr('href', $nextLink.attr('href')) .removeClass("hide"); // for the footer link, also add the previous and next page titles $('.content-footer .prev-page-link').append($prevLink.html()); $('.content-footer .next-page-link').append($nextLink.html()); } if (!startClass && $prevLink.length) { var prevHref = $prevLink.attr('href'); if (prevHref == SITE_ROOT + 'index.html') { // Don't show Previous when it leads to the homepage } else { $('.prev-page-link').attr('href', $prevLink.attr('href')).removeClass("hide"); } } } // 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'); // create an array for all the class descriptions var $classDescriptions = new Array($classLinks.length); var lang = getLangPref(); $classLinks.each(function(index) { var langDescr = $(this).attr(lang + "-description"); if (typeof langDescr !== 'undefined' && langDescr !== false) { // if there's a class description in the selected language, use that $classDescriptions[index] = langDescr; } else { // otherwise, use the default english description $classDescriptions[index] = $(this).attr("description"); } }); var $olClasses = $('
    '); var $liClass; var $h2Title; var $pSummary; var $olLessons; var $liLesson; $classLinks.each(function(index) { $liClass = $('
  1. '); $h2Title = $('

    ' + $(this).html() + '

    '); $pSummary = $('

    ' + $classDescriptions[index] + '

    '); $olLessons = $('
      '); $lessons = $(this).closest('li').find('ul li a'); if ($lessons.length) { $lessons.each(function(index) { $olLessons.append('
    1. ' + $(this).html() + '
    2. '); }); } else { $pSummary.addClass('article'); } $liClass.append($h2Title).append($pSummary).append($olLessons); $olClasses.append($liClass); }); $('#classes').append($olClasses); } // Set up expand/collapse behavior initExpandableNavItems("#nav"); // Set up play-on-hover