var resizePackagesNav; var classesNav; var devdocNav; var sidenav; var content; var HEADER_HEIGHT = 117; var cookie_namespace = 'android_developer'; var NAV_PREF_TREE = "tree"; var NAV_PREF_PANELS = "panels"; var nav_pref; var toRoot; var isMobile = false; // true if mobile, so we can adjust some layout var isIE6 = false; // true if IE6 // TODO: use $(document).ready instead function addLoadEvent(newfun) { var current = window.onload; if (typeof window.onload != 'function') { window.onload = newfun; } else { window.onload = function() { current(); newfun(); } } } var agent = navigator['userAgent'].toLowerCase(); // If a mobile phone, set flag and do mobile setup if ((agent.indexOf("mobile") != -1) || // android, iphone, ipod (agent.indexOf("blackberry") != -1) || (agent.indexOf("webos") != -1) || (agent.indexOf("mini") != -1)) { // opera mini browsers isMobile = true; addLoadEvent(mobileSetup); // If not a mobile browser, set the onresize event for IE6, and others } else if (agent.indexOf("msie 6") != -1) { isIE6 = true; addLoadEvent(function() { window.onresize = resizeAll; }); } else { addLoadEvent(function() { window.onresize = resizeHeight; }); } function mobileSetup() { $("body").css({'overflow':'auto'}); $("html").css({'overflow':'auto'}); $("#body-content").css({'position':'relative', 'top':'0'}); $("#doc-content").css({'overflow':'visible', 'border-left':'3px solid #DDD'}); $("#side-nav").css({'padding':'0'}); $("#nav-tree").css({'overflow-y': 'auto'}); } /* loads the lists.js file to the page. Loading this in the head was slowing page load time */ addLoadEvent( function() { var lists = document.createElement("script"); lists.setAttribute("type","text/javascript"); lists.setAttribute("src", toRoot+"reference/lists.js"); document.getElementsByTagName("head")[0].appendChild(lists); } ); addLoadEvent( function() { $("pre:not(.no-pretty-print)").addClass("prettyprint"); prettyPrint(); } ); function setToRoot(root) { toRoot = root; // note: toRoot also used by carousel.js } function restoreWidth(navWidth) { var windowWidth = $(window).width() + "px"; content.css({marginLeft:parseInt(navWidth) + 6 + "px"}); //account for 6px-wide handle-bar if (isIE6) { content.css({width:parseInt(windowWidth) - parseInt(navWidth) - 6 + "px"}); // necessary in order for scrollbars to be visible } sidenav.css({width:navWidth}); resizePackagesNav.css({width:navWidth}); classesNav.css({width:navWidth}); $("#packages-nav").css({width:navWidth}); } function restoreHeight(packageHeight) { var windowHeight = ($(window).height() - HEADER_HEIGHT); var swapperHeight = windowHeight - 13; $("#swapper").css({height:swapperHeight + "px"}); sidenav.css({height:windowHeight + "px"}); content.css({height:windowHeight + "px"}); resizePackagesNav.css({maxHeight:swapperHeight + "px", height:packageHeight}); classesNav.css({height:swapperHeight - parseInt(packageHeight) + "px"}); $("#packages-nav").css({height:parseInt(packageHeight) - 6 + "px"}); //move 6px to give space for the resize handle devdocNav.css({height:sidenav.css("height")}); $("#nav-tree").css({height:swapperHeight + "px"}); } function readCookie(cookie) { var myCookie = cookie_namespace+"_"+cookie+"="; if (document.cookie) { var index = document.cookie.indexOf(myCookie); if (index != -1) { var valStart = index + myCookie.length; var valEnd = document.cookie.indexOf(";", valStart); if (valEnd == -1) { valEnd = document.cookie.length; } var val = document.cookie.substring(valStart, valEnd); return val; } } return 0; } function writeCookie(cookie, val, section, expiration) { if (val==undefined) return; section = section == null ? "_" : "_"+section+"_"; if (expiration == null) { var date = new Date(); date.setTime(date.getTime()+(10*365*24*60*60*1000)); // default expiration is one week expiration = date.toGMTString(); } document.cookie = cookie_namespace + section + cookie + "=" + val + "; expires=" + expiration+"; path=/"; } function init() { $("#side-nav").css({position:"absolute",left:0}); content = $("#doc-content"); resizePackagesNav = $("#resize-packages-nav"); classesNav = $("#classes-nav"); sidenav = $("#side-nav"); devdocNav = $("#devdoc-nav"); var cookiePath = ""; if (location.href.indexOf("/reference/") != -1) { cookiePath = "reference_"; } else if (location.href.indexOf("/guide/") != -1) { cookiePath = "guide_"; } else if (location.href.indexOf("/sdk/") != -1) { cookiePath = "sdk_"; } else if ((location.href.indexOf("/resources/") != -1) || (location.href.indexOf("/training/") != -1)) { cookiePath = "resources_"; } if (!isMobile) { $("#resize-packages-nav").resizable({handles: "s", resize: function(e, ui) { resizePackagesHeight(); } }); $("#side-nav").resizable({handles: "e", resize: function(e, ui) { resizeWidth(); } }); var cookieWidth = readCookie(cookiePath+'width'); var cookieHeight = readCookie(cookiePath+'height'); if (cookieWidth) { restoreWidth(cookieWidth); } else if ($("#side-nav").length) { resizeWidth(); } if (cookieHeight) { restoreHeight(cookieHeight); } else { resizeHeight(); } } if (devdocNav.length) { // only dev guide, resources, and sdk tryPopulateResourcesNav(); highlightNav(location.href); } } function tryPopulateResourcesNav() { var sampleList = $('#devdoc-nav-sample-list'); var articleList = $('#devdoc-nav-article-list'); var tutorialList = $('#devdoc-nav-tutorial-list'); var topicList = $('#devdoc-nav-topic-list'); if (!topicList.length || !ANDROID_TAGS || !ANDROID_RESOURCES) return; var topics = []; for (var topic in ANDROID_TAGS['topic']) { topics.push({name:topic,title:ANDROID_TAGS['topic'][topic]}); } topics.sort(function(x,y){ return (x.title < y.title) ? -1 : 1; }); for (var i = 0; i < topics.length; i++) { topicList.append( $('