The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame^] | 1 | var resizePackagesNav; |
| 2 | var classesNav; |
| 3 | var devdocNav; |
| 4 | var sidenav; |
| 5 | var content; |
| 6 | var HEADER_HEIGHT = 103; |
| 7 | var cookie_style = 'android_dev_docs'; |
| 8 | |
| 9 | function addLoadEvent(newfun) { |
| 10 | var current = window.onload; |
| 11 | if (typeof window.onload != 'function') { |
| 12 | window.onload = newfun; |
| 13 | } else { |
| 14 | window.onload = function() { |
| 15 | current(); |
| 16 | newfun(); |
| 17 | } |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | addLoadEvent(prepare); |
| 22 | window.onresize = resizeAll; |
| 23 | |
| 24 | function restoreWidth(navWidth) { |
| 25 | var windowWidth = $(window).width() + "px"; |
| 26 | content.css({marginLeft:navWidth, width:parseInt(windowWidth) - parseInt(navWidth) + "px"}); |
| 27 | sidenav.css({width:navWidth}); |
| 28 | resizePackagesNav.css({width:navWidth}); |
| 29 | classesNav.css({width:navWidth}); |
| 30 | $("#packages-nav").css({width:navWidth}); |
| 31 | } |
| 32 | |
| 33 | function restoreHeight(packageHeight) { |
| 34 | var windowHeight = ($(window).height() - HEADER_HEIGHT); |
| 35 | sidenav.css({height:windowHeight + "px"}); |
| 36 | content.css({height:windowHeight + "px"}); |
| 37 | resizePackagesNav.css({maxHeight:windowHeight + "px", height:packageHeight}); |
| 38 | classesNav.css({height:windowHeight - parseInt(packageHeight) + "px"}); |
| 39 | $("#packages-nav").css({height:parseInt(packageHeight) - 6 + "px"}); //move 6px to give space for the resize handle |
| 40 | devdocNav.css({height:sidenav.css("height")}); |
| 41 | } |
| 42 | |
| 43 | function getCookie(cookie) { |
| 44 | var myCookie = cookie_style+"_"+cookie+"="; |
| 45 | if (document.cookie) { |
| 46 | var index = document.cookie.indexOf(myCookie); |
| 47 | if (index != -1) { |
| 48 | var valStart = index + myCookie.length; |
| 49 | var valEnd = document.cookie.indexOf(";", valStart); |
| 50 | var val = document.cookie.substring(valStart, valEnd); |
| 51 | return val; |
| 52 | } |
| 53 | } |
| 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | function writeCookie(cookie, val) { |
| 58 | if (location.href.indexOf("reference") != -1) { |
| 59 | document.cookie = cookie_style+'_'+cookie+'='+val+'; path=/gae/reference'; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | function prepare() { |
| 64 | $("#side-nav").css({position:"absolute",left:0}); |
| 65 | content = $("#doc-content"); |
| 66 | resizePackagesNav = $("#resize-packages-nav"); |
| 67 | classesNav = $("#classes-nav"); |
| 68 | sidenav = $("#side-nav"); |
| 69 | devdocNav = $("#devdoc-nav"); |
| 70 | |
| 71 | var cookieWidth = getCookie('width'); |
| 72 | var cookieHeight = getCookie('height'); |
| 73 | if (cookieWidth) { |
| 74 | restoreWidth(cookieWidth); |
| 75 | } else { |
| 76 | resizeWidth(); |
| 77 | } |
| 78 | if (cookieHeight) { |
| 79 | restoreHeight(cookieHeight); |
| 80 | } else { |
| 81 | resizeHeight(); |
| 82 | } |
| 83 | |
| 84 | if (devdocNav.length) { |
| 85 | highlightNav(location.href); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | function highlightNav(fullPageName) { |
| 90 | var lastSlashPos = fullPageName.lastIndexOf("/"); |
| 91 | var firstSlashPos = fullPageName.indexOf("/",8); // first slash after http:// |
| 92 | if (lastSlashPos == (fullPageName.length - 1)) { // if the url ends in slash (index.html) |
| 93 | fullPageName = fullPageName + "index.html"; |
| 94 | } |
| 95 | var htmlPos = fullPageName.lastIndexOf(".html", fullPageName.length); |
| 96 | var pageName = fullPageName.slice(firstSlashPos, htmlPos + 5); |
| 97 | var link = $("#devdoc-nav a[href$='"+pageName+"']"); |
| 98 | if (link.length == 0) { // if there's no match, maybe the nav url ends in a slash, also |
| 99 | link = $("#devdoc-nav a[href$='"+pageName.slice(0,pageName.indexOf("index.html"))+"']"); |
| 100 | } |
| 101 | link.parent().addClass('selected'); |
| 102 | } |
| 103 | |
| 104 | function resizeHeight() { |
| 105 | var windowHeight = ($(window).height() - HEADER_HEIGHT); |
| 106 | sidenav.css({height:windowHeight + "px"}); |
| 107 | content.css({height:windowHeight + "px"}); |
| 108 | resizePackagesNav.css({maxHeight:windowHeight + "px"}); |
| 109 | classesNav.css({height:windowHeight - parseInt(resizePackagesNav.css("height")) + "px"}); |
| 110 | $("#packages-nav").css({height:parseInt(resizePackagesNav.css("height")) - 6 + "px"}); //move 6px for handle |
| 111 | devdocNav.css({height:sidenav.css("height")}); |
| 112 | writeCookie("height", resizePackagesNav.css("height")); |
| 113 | } |
| 114 | |
| 115 | function resizeWidth() { |
| 116 | var windowWidth = $(window).width() + "px"; |
| 117 | if (sidenav.length) { |
| 118 | var sidenavWidth = sidenav.css("width"); |
| 119 | } else { |
| 120 | var sidenavWidth = 0; |
| 121 | } |
| 122 | content.css({marginLeft:sidenavWidth, width:parseInt(windowWidth) - parseInt(sidenavWidth) + "px"}); |
| 123 | resizePackagesNav.css({width:sidenavWidth}); |
| 124 | classesNav.css({width:sidenavWidth}); |
| 125 | $("#packages-nav").css({width:sidenavWidth}); |
| 126 | writeCookie("width", sidenavWidth); |
| 127 | } |
| 128 | |
| 129 | function resizeAll() { |
| 130 | resizeHeight(); |
| 131 | resizeWidth(); |
| 132 | } |
| 133 | |
| 134 | //added to onload when the bottom-left panel is empty |
| 135 | function maxPackageHeight() { |
| 136 | var windowHeight = resizePackagesNav.css("maxHeight"); |
| 137 | resizePackagesNav.css({height:windowHeight}); |
| 138 | $("#packages-nav").css({height:windowHeight}); |
| 139 | } |
| 140 | |
| 141 | $(document).ready(function(){ |
| 142 | $("#resize-packages-nav").resizable({handles: "s", resize: function(e, ui) { resizeHeight(); } }); |
| 143 | $(".side-nav-resizable").resizable({handles: "e", resize: function(e, ui) { resizeWidth(); } }); |
| 144 | }); |