The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1 | var resizePackagesNav; |
| 2 | var classesNav; |
| 3 | var devdocNav; |
| 4 | var sidenav; |
| 5 | var content; |
| 6 | var HEADER_HEIGHT = 117; |
Dirk Dougherty | 4405a23 | 2009-07-07 17:43:27 -0700 | [diff] [blame] | 7 | var cookie_namespace = 'android_developer'; |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 8 | var NAV_PREF_TREE = "tree"; |
| 9 | var NAV_PREF_PANELS = "panels"; |
| 10 | var nav_pref; |
| 11 | var toRoot; |
The Android Open Source Project | fdd3a10 | 2009-03-11 12:11:54 -0700 | [diff] [blame] | 12 | var isMobile = false; // true if mobile, so we can adjust some layout |
Scott Main | 3f7d1df | 2009-11-02 15:31:04 -0800 | [diff] [blame] | 13 | var isIE6 = false; // true if IE6 |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 14 | |
Scott Main | f8af887 | 2009-12-02 20:59:40 -0800 | [diff] [blame] | 15 | // TODO: use $(document).ready instead |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 16 | function addLoadEvent(newfun) { |
| 17 | var current = window.onload; |
| 18 | if (typeof window.onload != 'function') { |
| 19 | window.onload = newfun; |
| 20 | } else { |
| 21 | window.onload = function() { |
| 22 | current(); |
| 23 | newfun(); |
| 24 | } |
| 25 | } |
| 26 | } |
| 27 | |
Scott Main | d8115ff | 2009-11-03 18:54:26 -0800 | [diff] [blame] | 28 | var agent = navigator['userAgent'].toLowerCase(); |
Scott Main | 3f7d1df | 2009-11-02 15:31:04 -0800 | [diff] [blame] | 29 | // If a mobile phone, set flag and do mobile setup |
Scott Main | d8115ff | 2009-11-03 18:54:26 -0800 | [diff] [blame] | 30 | if ((agent.indexOf("mobile") != -1) || // android, iphone, ipod |
| 31 | (agent.indexOf("blackberry") != -1) || |
| 32 | (agent.indexOf("webos") != -1) || |
| 33 | (agent.indexOf("mini") != -1)) { // opera mini browsers |
The Android Open Source Project | fdd3a10 | 2009-03-11 12:11:54 -0700 | [diff] [blame] | 34 | isMobile = true; |
| 35 | addLoadEvent(mobileSetup); |
Scott Main | 3f7d1df | 2009-11-02 15:31:04 -0800 | [diff] [blame] | 36 | // If not a mobile browser, set the onresize event for IE6, and others |
Scott Main | d8115ff | 2009-11-03 18:54:26 -0800 | [diff] [blame] | 37 | } else if (agent.indexOf("msie 6") != -1) { |
Scott Main | 3f7d1df | 2009-11-02 15:31:04 -0800 | [diff] [blame] | 38 | isIE6 = true; |
| 39 | addLoadEvent(function() { |
| 40 | window.onresize = resizeAll; |
| 41 | }); |
| 42 | } else { |
| 43 | addLoadEvent(function() { |
| 44 | window.onresize = resizeHeight; |
| 45 | }); |
The Android Open Source Project | fdd3a10 | 2009-03-11 12:11:54 -0700 | [diff] [blame] | 46 | } |
| 47 | |
The Android Open Source Project | fdd3a10 | 2009-03-11 12:11:54 -0700 | [diff] [blame] | 48 | function mobileSetup() { |
| 49 | $("body").css({'overflow':'auto'}); |
| 50 | $("html").css({'overflow':'auto'}); |
| 51 | $("#body-content").css({'position':'relative', 'top':'0'}); |
| 52 | $("#doc-content").css({'overflow':'visible', 'border-left':'3px solid #DDD'}); |
| 53 | $("#side-nav").css({'padding':'0'}); |
| 54 | $("#nav-tree").css({'overflow-y': 'auto'}); |
| 55 | } |
| 56 | |
Scott Main | 25fda19 | 2009-08-04 11:26:30 -0700 | [diff] [blame] | 57 | /* loads the lists.js file to the page. |
| 58 | Loading this in the head was slowing page load time */ |
| 59 | addLoadEvent( function() { |
| 60 | var lists = document.createElement("script"); |
| 61 | lists.setAttribute("type","text/javascript"); |
| 62 | lists.setAttribute("src", toRoot+"reference/lists.js"); |
Scott Main | 1da8238 | 2009-09-17 10:54:05 -0700 | [diff] [blame] | 63 | document.getElementsByTagName("head")[0].appendChild(lists); |
Scott Main | 25fda19 | 2009-08-04 11:26:30 -0700 | [diff] [blame] | 64 | } ); |
| 65 | |
Scott Main | f8af887 | 2009-12-02 20:59:40 -0800 | [diff] [blame] | 66 | addLoadEvent( function() { |
| 67 | $("pre").addClass("prettyprint"); |
| 68 | prettyPrint(); |
| 69 | } ); |
| 70 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 71 | function setToRoot(root) { |
| 72 | toRoot = root; |
| 73 | // note: toRoot also used by carousel.js |
| 74 | } |
| 75 | |
| 76 | function restoreWidth(navWidth) { |
| 77 | var windowWidth = $(window).width() + "px"; |
Scott Main | 3f7d1df | 2009-11-02 15:31:04 -0800 | [diff] [blame] | 78 | content.css({marginLeft:parseInt(navWidth) + 6 + "px"}); //account for 6px-wide handle-bar |
| 79 | |
| 80 | if (isIE6) { |
| 81 | content.css({width:parseInt(windowWidth) - parseInt(navWidth) - 6 + "px"}); // necessary in order for scrollbars to be visible |
| 82 | } |
| 83 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 84 | sidenav.css({width:navWidth}); |
| 85 | resizePackagesNav.css({width:navWidth}); |
| 86 | classesNav.css({width:navWidth}); |
| 87 | $("#packages-nav").css({width:navWidth}); |
| 88 | } |
| 89 | |
| 90 | function restoreHeight(packageHeight) { |
| 91 | var windowHeight = ($(window).height() - HEADER_HEIGHT); |
| 92 | var swapperHeight = windowHeight - 13; |
| 93 | $("#swapper").css({height:swapperHeight + "px"}); |
| 94 | sidenav.css({height:windowHeight + "px"}); |
| 95 | content.css({height:windowHeight + "px"}); |
| 96 | resizePackagesNav.css({maxHeight:swapperHeight + "px", height:packageHeight}); |
| 97 | classesNav.css({height:swapperHeight - parseInt(packageHeight) + "px"}); |
| 98 | $("#packages-nav").css({height:parseInt(packageHeight) - 6 + "px"}); //move 6px to give space for the resize handle |
| 99 | devdocNav.css({height:sidenav.css("height")}); |
| 100 | $("#nav-tree").css({height:swapperHeight + "px"}); |
| 101 | } |
| 102 | |
Dirk Dougherty | 4405a23 | 2009-07-07 17:43:27 -0700 | [diff] [blame] | 103 | function readCookie(cookie) { |
| 104 | var myCookie = cookie_namespace+"_"+cookie+"="; |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 105 | if (document.cookie) { |
| 106 | var index = document.cookie.indexOf(myCookie); |
| 107 | if (index != -1) { |
| 108 | var valStart = index + myCookie.length; |
| 109 | var valEnd = document.cookie.indexOf(";", valStart); |
| 110 | if (valEnd == -1) { |
| 111 | valEnd = document.cookie.length; |
| 112 | } |
| 113 | var val = document.cookie.substring(valStart, valEnd); |
| 114 | return val; |
| 115 | } |
| 116 | } |
| 117 | return 0; |
| 118 | } |
| 119 | |
Dirk Dougherty | 4405a23 | 2009-07-07 17:43:27 -0700 | [diff] [blame] | 120 | function writeCookie(cookie, val, section, expiration) { |
Scott Main | 9b5fdb9 | 2009-10-27 15:09:15 -0700 | [diff] [blame] | 121 | if (val==undefined) return; |
Dirk Dougherty | 4405a23 | 2009-07-07 17:43:27 -0700 | [diff] [blame] | 122 | section = section == null ? "_" : "_"+section+"_"; |
| 123 | if (expiration == null) { |
| 124 | var date = new Date(); |
| 125 | date.setTime(date.getTime()+(10*365*24*60*60*1000)); // default expiration is one week |
| 126 | expiration = date.toGMTString(); |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 127 | } |
Scott Main | 3f7d1df | 2009-11-02 15:31:04 -0800 | [diff] [blame] | 128 | document.cookie = cookie_namespace + section + cookie + "=" + val + "; expires=" + expiration+"; path=/"; |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | function init() { |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 132 | $("#side-nav").css({position:"absolute",left:0}); |
| 133 | content = $("#doc-content"); |
| 134 | resizePackagesNav = $("#resize-packages-nav"); |
| 135 | classesNav = $("#classes-nav"); |
| 136 | sidenav = $("#side-nav"); |
| 137 | devdocNav = $("#devdoc-nav"); |
| 138 | |
Scott Main | a39d3bb | 2010-01-06 14:18:02 -0800 | [diff] [blame] | 139 | var cookiePath = ""; |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 140 | if (location.href.indexOf("/reference/") != -1) { |
Scott Main | a39d3bb | 2010-01-06 14:18:02 -0800 | [diff] [blame] | 141 | cookiePath = "reference_"; |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 142 | } else if (location.href.indexOf("/guide/") != -1) { |
Scott Main | a39d3bb | 2010-01-06 14:18:02 -0800 | [diff] [blame] | 143 | cookiePath = "guide_"; |
Dirk Dougherty | 502c498 | 2009-12-02 18:01:16 -0800 | [diff] [blame] | 144 | } else if (location.href.indexOf("/resources/") != -1) { |
Scott Main | a39d3bb | 2010-01-06 14:18:02 -0800 | [diff] [blame] | 145 | cookiePath = "resources_"; |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 146 | } |
The Android Open Source Project | fdd3a10 | 2009-03-11 12:11:54 -0700 | [diff] [blame] | 147 | |
| 148 | if (!isMobile) { |
Scott Main | 3f7d1df | 2009-11-02 15:31:04 -0800 | [diff] [blame] | 149 | $("#resize-packages-nav").resizable({handles: "s", resize: function(e, ui) { resizePackagesHeight(); } }); |
The Android Open Source Project | fdd3a10 | 2009-03-11 12:11:54 -0700 | [diff] [blame] | 150 | $(".side-nav-resizable").resizable({handles: "e", resize: function(e, ui) { resizeWidth(); } }); |
Dirk Dougherty | 4405a23 | 2009-07-07 17:43:27 -0700 | [diff] [blame] | 151 | var cookieWidth = readCookie(cookiePath+'width'); |
| 152 | var cookieHeight = readCookie(cookiePath+'height'); |
The Android Open Source Project | fdd3a10 | 2009-03-11 12:11:54 -0700 | [diff] [blame] | 153 | if (cookieWidth) { |
| 154 | restoreWidth(cookieWidth); |
| 155 | } else if ($(".side-nav-resizable").length) { |
| 156 | resizeWidth(); |
| 157 | } |
| 158 | if (cookieHeight) { |
| 159 | restoreHeight(cookieHeight); |
| 160 | } else { |
| 161 | resizeHeight(); |
| 162 | } |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | if (devdocNav.length) { // only dev guide and sdk |
| 166 | highlightNav(location.href); |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | function highlightNav(fullPageName) { |
| 171 | var lastSlashPos = fullPageName.lastIndexOf("/"); |
Dirk Dougherty | 502c498 | 2009-12-02 18:01:16 -0800 | [diff] [blame] | 172 | var firstSlashPos; |
| 173 | if (fullPageName.indexOf("/guide/") != -1) { |
| 174 | firstSlashPos = fullPageName.indexOf("/guide/"); |
| 175 | } else if (fullPageName.indexOf("/sdk/") != -1) { |
| 176 | firstSlashPos = fullPageName.indexOf("/sdk/"); |
| 177 | } else { |
| 178 | firstSlashPos = fullPageName.indexOf("/resources/"); |
| 179 | } |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 180 | if (lastSlashPos == (fullPageName.length - 1)) { // if the url ends in slash (add 'index.html') |
| 181 | fullPageName = fullPageName + "index.html"; |
| 182 | } |
| 183 | var htmlPos = fullPageName.lastIndexOf(".html", fullPageName.length); |
| 184 | var pathPageName = fullPageName.slice(firstSlashPos, htmlPos + 5); |
| 185 | var link = $("#devdoc-nav a[href$='"+ pathPageName+"']"); |
Dirk Dougherty | f32c5ac | 2009-12-15 18:48:38 -0800 | [diff] [blame] | 186 | if ((link.length == 0) && ((fullPageName.indexOf("/guide/") != -1) || (fullPageName.indexOf("/resources/") != -1))) { |
Scott Main | 0d8872e | 2009-10-23 13:04:31 -0700 | [diff] [blame] | 187 | // if there's no match, then let's backstep through the directory until we find an index.html page that matches our ancestor directories (only for dev guide) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 188 | lastBackstep = pathPageName.lastIndexOf("/"); |
| 189 | while (link.length == 0) { |
| 190 | backstepDirectory = pathPageName.lastIndexOf("/", lastBackstep); |
| 191 | link = $("#devdoc-nav a[href$='"+ pathPageName.slice(0, backstepDirectory + 1)+"index.html']"); |
| 192 | lastBackstep = pathPageName.lastIndexOf("/", lastBackstep - 1); |
| 193 | if (lastBackstep == 0) break; |
| 194 | } |
| 195 | } |
| 196 | link.parent().addClass('selected'); |
| 197 | if (link.parent().parent().is(':hidden')) { |
| 198 | toggle(link.parent().parent().parent(), false); |
| 199 | } else if (link.parent().parent().hasClass('toggle-list')) { |
| 200 | toggle(link.parent().parent(), false); |
| 201 | } |
| 202 | } |
| 203 | |
Scott Main | 3f7d1df | 2009-11-02 15:31:04 -0800 | [diff] [blame] | 204 | /* Resize the height of the nav panels in the reference, |
| 205 | * and save the new size to a cookie */ |
| 206 | function resizePackagesHeight() { |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 207 | var windowHeight = ($(window).height() - HEADER_HEIGHT); |
Scott Main | 3f7d1df | 2009-11-02 15:31:04 -0800 | [diff] [blame] | 208 | var swapperHeight = windowHeight - 13; // move 13px for swapper link at the bottom |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 209 | resizePackagesNav.css({maxHeight:swapperHeight + "px"}); |
| 210 | classesNav.css({height:swapperHeight - parseInt(resizePackagesNav.css("height")) + "px"}); |
Scott Main | 3f7d1df | 2009-11-02 15:31:04 -0800 | [diff] [blame] | 211 | |
| 212 | $("#swapper").css({height:swapperHeight + "px"}); |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 213 | $("#packages-nav").css({height:parseInt(resizePackagesNav.css("height")) - 6 + "px"}); //move 6px for handle |
Scott Main | 3f7d1df | 2009-11-02 15:31:04 -0800 | [diff] [blame] | 214 | |
Dirk Dougherty | c13d045 | 2009-07-08 14:39:31 -0700 | [diff] [blame] | 215 | var basePath = getBaseUri(location.pathname); |
| 216 | var section = basePath.substring(1,basePath.indexOf("/",1)); |
Dirk Dougherty | 4405a23 | 2009-07-07 17:43:27 -0700 | [diff] [blame] | 217 | writeCookie("height", resizePackagesNav.css("height"), section, null); |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 218 | } |
| 219 | |
Scott Main | 3f7d1df | 2009-11-02 15:31:04 -0800 | [diff] [blame] | 220 | /* Resize the height of the side-nav and doc-content divs, |
| 221 | * which creates the frame effect */ |
| 222 | function resizeHeight() { |
Scott Main | 13b79b2 | 2010-01-12 13:37:00 -0800 | [diff] [blame^] | 223 | var docContent = $("#doc-content"); |
| 224 | |
Scott Main | 3f7d1df | 2009-11-02 15:31:04 -0800 | [diff] [blame] | 225 | // Get the window height and always resize the doc-content and side-nav divs |
| 226 | var windowHeight = ($(window).height() - HEADER_HEIGHT); |
Scott Main | 13b79b2 | 2010-01-12 13:37:00 -0800 | [diff] [blame^] | 227 | docContent.css({height:windowHeight + "px"}); |
| 228 | $("#side-nav").css({height:windowHeight + "px"}); |
Scott Main | 3f7d1df | 2009-11-02 15:31:04 -0800 | [diff] [blame] | 229 | |
| 230 | var href = location.href; |
| 231 | // If in the reference docs, also resize the "swapper", "classes-nav", and "nav-tree" divs |
| 232 | if (href.indexOf("/reference/") != -1) { |
| 233 | var swapperHeight = windowHeight - 13; |
| 234 | $("#swapper").css({height:swapperHeight + "px"}); |
| 235 | $("#classes-nav").css({height:swapperHeight - parseInt(resizePackagesNav.css("height")) + "px"}); |
| 236 | $("#nav-tree").css({height:swapperHeight + "px"}); |
| 237 | |
| 238 | // If in the dev guide docs, also resize the "devdoc-nav" div |
| 239 | } else if (href.indexOf("/guide/") != -1) { |
| 240 | $("#devdoc-nav").css({height:sidenav.css("height")}); |
Dirk Dougherty | 502c498 | 2009-12-02 18:01:16 -0800 | [diff] [blame] | 241 | } else if (href.indexOf("/resources/") != -1) { |
| 242 | $("#devdoc-nav").css({height:sidenav.css("height")}); |
Scott Main | 3f7d1df | 2009-11-02 15:31:04 -0800 | [diff] [blame] | 243 | } |
Scott Main | 13b79b2 | 2010-01-12 13:37:00 -0800 | [diff] [blame^] | 244 | |
| 245 | // Hide the "Go to top" link if there's no vertical scroll |
| 246 | if ( parseInt($("#jd-content").css("height")) <= parseInt(docContent.css("height")) ) { |
| 247 | $("a[href='#top']").css({'display':'none'}); |
| 248 | } else { |
| 249 | $("a[href='#top']").css({'display':'inline'}); |
| 250 | } |
Scott Main | 3f7d1df | 2009-11-02 15:31:04 -0800 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | /* Resize the width of the "side-nav" and the left margin of the "doc-content" div, |
| 254 | * which creates the resizable side bar */ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 255 | function resizeWidth() { |
| 256 | var windowWidth = $(window).width() + "px"; |
| 257 | if (sidenav.length) { |
| 258 | var sidenavWidth = sidenav.css("width"); |
| 259 | } else { |
| 260 | var sidenavWidth = 0; |
| 261 | } |
Scott Main | 3f7d1df | 2009-11-02 15:31:04 -0800 | [diff] [blame] | 262 | content.css({marginLeft:parseInt(sidenavWidth) + 6 + "px"}); //account for 6px-wide handle-bar |
| 263 | |
| 264 | if (isIE6) { |
| 265 | content.css({width:parseInt(windowWidth) - parseInt(sidenavWidth) - 6 + "px"}); // necessary in order to for scrollbars to be visible |
| 266 | } |
| 267 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 268 | resizePackagesNav.css({width:sidenavWidth}); |
| 269 | classesNav.css({width:sidenavWidth}); |
| 270 | $("#packages-nav").css({width:sidenavWidth}); |
Scott Main | 3f7d1df | 2009-11-02 15:31:04 -0800 | [diff] [blame] | 271 | |
Scott Main | b6da480 | 2010-01-06 14:18:02 -0800 | [diff] [blame] | 272 | if ($(".side-nav-resizable").length) { // Must check if the nav is resizable because IE6 calls resizeWidth() from resizeAll() for all pages |
| 273 | var basePath = getBaseUri(location.pathname); |
| 274 | var section = basePath.substring(1,basePath.indexOf("/",1)); |
| 275 | writeCookie("width", sidenavWidth, section, null); |
| 276 | } |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 277 | } |
| 278 | |
Scott Main | 3f7d1df | 2009-11-02 15:31:04 -0800 | [diff] [blame] | 279 | /* For IE6 only, |
| 280 | * because it can't properly perform auto width for "doc-content" div, |
| 281 | * avoiding this for all browsers provides better performance */ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 282 | function resizeAll() { |
Scott Main | 3f7d1df | 2009-11-02 15:31:04 -0800 | [diff] [blame] | 283 | resizeHeight(); |
Scott Main | b6da480 | 2010-01-06 14:18:02 -0800 | [diff] [blame] | 284 | resizeWidth(); |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 285 | } |
| 286 | |
Dirk Dougherty | 4405a23 | 2009-07-07 17:43:27 -0700 | [diff] [blame] | 287 | function getBaseUri(uri) { |
Dirk Dougherty | efdcda4 | 2009-07-15 16:41:48 -0700 | [diff] [blame] | 288 | var intlUrl = (uri.substring(0,6) == "/intl/"); |
Dirk Dougherty | 4405a23 | 2009-07-07 17:43:27 -0700 | [diff] [blame] | 289 | if (intlUrl) { |
| 290 | base = uri.substring(uri.indexOf('intl/')+5,uri.length); |
| 291 | base = base.substring(base.indexOf('/')+1, base.length); |
| 292 | //alert("intl, returning base url: /" + base); |
| 293 | return ("/" + base); |
| 294 | } else { |
| 295 | //alert("not intl, returning uri as found."); |
| 296 | return uri; |
| 297 | } |
| 298 | } |
| 299 | |
Dirk Dougherty | efdcda4 | 2009-07-15 16:41:48 -0700 | [diff] [blame] | 300 | function requestAppendHL(uri) { |
| 301 | //append "?hl=<lang> to an outgoing request (such as to blog) |
| 302 | var lang = getLangPref(); |
| 303 | if (lang) { |
| 304 | var q = 'hl=' + lang; |
| 305 | uri += '?' + q; |
| 306 | window.location = uri; |
| 307 | return false; |
| 308 | } else { |
| 309 | return true; |
| 310 | } |
| 311 | } |
| 312 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 313 | function loadLast(cookiePath) { |
| 314 | var location = window.location.href; |
| 315 | if (location.indexOf("/"+cookiePath+"/") != -1) { |
| 316 | return true; |
| 317 | } |
Dirk Dougherty | 4405a23 | 2009-07-07 17:43:27 -0700 | [diff] [blame] | 318 | var lastPage = readCookie(cookiePath + "_lastpage"); |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 319 | if (lastPage) { |
| 320 | window.location = lastPage; |
| 321 | return false; |
| 322 | } |
| 323 | return true; |
| 324 | } |
| 325 | |
| 326 | $(window).unload(function(){ |
Dirk Dougherty | 4405a23 | 2009-07-07 17:43:27 -0700 | [diff] [blame] | 327 | var path = getBaseUri(location.pathname); |
| 328 | if (path.indexOf("/reference/") != -1) { |
| 329 | writeCookie("lastpage", path, "reference", null); |
| 330 | } else if (path.indexOf("/guide/") != -1) { |
| 331 | writeCookie("lastpage", path, "guide", null); |
Dirk Dougherty | 502c498 | 2009-12-02 18:01:16 -0800 | [diff] [blame] | 332 | } else if (path.indexOf("/resources/") != -1) { |
| 333 | writeCookie("lastpage", path, "resources", null); |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 334 | } |
| 335 | }); |
| 336 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 337 | function toggle(obj, slide) { |
| 338 | var ul = $("ul", obj); |
| 339 | var li = ul.parent(); |
| 340 | if (li.hasClass("closed")) { |
| 341 | if (slide) { |
| 342 | ul.slideDown("fast"); |
| 343 | } else { |
| 344 | ul.show(); |
| 345 | } |
| 346 | li.removeClass("closed"); |
| 347 | li.addClass("open"); |
| 348 | $(".toggle-img", li).attr("title", "hide pages"); |
| 349 | } else { |
| 350 | ul.slideUp("fast"); |
| 351 | li.removeClass("open"); |
| 352 | li.addClass("closed"); |
| 353 | $(".toggle-img", li).attr("title", "show pages"); |
| 354 | } |
| 355 | } |
| 356 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 357 | function buildToggleLists() { |
| 358 | $(".toggle-list").each( |
| 359 | function(i) { |
| 360 | $("div", this).append("<a class='toggle-img' href='#' title='show pages' onClick='toggle(this.parentNode.parentNode, true); return false;'></a>"); |
| 361 | $(this).addClass("closed"); |
| 362 | }); |
| 363 | } |
| 364 | |
| 365 | function getNavPref() { |
Dirk Dougherty | 4405a23 | 2009-07-07 17:43:27 -0700 | [diff] [blame] | 366 | var v = readCookie('reference_nav'); |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 367 | if (v != NAV_PREF_TREE) { |
| 368 | v = NAV_PREF_PANELS; |
| 369 | } |
| 370 | return v; |
| 371 | } |
| 372 | |
| 373 | function chooseDefaultNav() { |
| 374 | nav_pref = getNavPref(); |
| 375 | if (nav_pref == NAV_PREF_TREE) { |
| 376 | $("#nav-panels").toggle(); |
| 377 | $("#panel-link").toggle(); |
| 378 | $("#nav-tree").toggle(); |
| 379 | $("#tree-link").toggle(); |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | function swapNav() { |
| 384 | if (nav_pref == NAV_PREF_TREE) { |
| 385 | nav_pref = NAV_PREF_PANELS; |
| 386 | } else { |
| 387 | nav_pref = NAV_PREF_TREE; |
Dirk Dougherty | 3b1ee37 | 2009-07-29 12:25:44 -0700 | [diff] [blame] | 388 | init_default_navtree(toRoot); |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 389 | } |
| 390 | var date = new Date(); |
| 391 | date.setTime(date.getTime()+(10*365*24*60*60*1000)); // keep this for 10 years |
Dirk Dougherty | 4405a23 | 2009-07-07 17:43:27 -0700 | [diff] [blame] | 392 | writeCookie("nav", nav_pref, "reference", date.toGMTString()); |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 393 | |
| 394 | $("#nav-panels").toggle(); |
| 395 | $("#panel-link").toggle(); |
| 396 | $("#nav-tree").toggle(); |
| 397 | $("#tree-link").toggle(); |
| 398 | |
| 399 | if ($("#nav-tree").is(':visible')) scrollIntoView("nav-tree"); |
| 400 | else { |
| 401 | scrollIntoView("packages-nav"); |
| 402 | scrollIntoView("classes-nav"); |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | function scrollIntoView(nav) { |
| 407 | var navObj = $("#"+nav); |
| 408 | if (navObj.is(':visible')) { |
| 409 | var selected = $(".selected", navObj); |
| 410 | if (selected.length == 0) return; |
| 411 | if (selected.is("div")) selected = selected.parent(); |
| 412 | |
| 413 | var scrolling = document.getElementById(nav); |
| 414 | var navHeight = navObj.height(); |
| 415 | var offsetTop = selected.position().top; |
| 416 | if (selected.parent().parent().is(".toggle-list")) offsetTop += selected.parent().parent().position().top; |
| 417 | if(offsetTop > navHeight - 92) { |
| 418 | scrolling.scrollTop = offsetTop - navHeight + 92; |
| 419 | } |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | function toggleAllInherited(linkObj, expand) { |
| 424 | var a = $(linkObj); |
| 425 | var table = $(a.parent().parent().parent()); |
| 426 | var expandos = $(".jd-expando-trigger", table); |
| 427 | if ( (expand == null && a.text() == "[Expand]") || expand ) { |
| 428 | expandos.each(function(i) { |
| 429 | toggleInherited(this, true); |
| 430 | }); |
| 431 | a.text("[Collapse]"); |
| 432 | } else if ( (expand == null && a.text() == "[Collapse]") || (expand == false) ) { |
| 433 | expandos.each(function(i) { |
| 434 | toggleInherited(this, false); |
| 435 | }); |
| 436 | a.text("[Expand]"); |
| 437 | } |
| 438 | return false; |
| 439 | } |
| 440 | |
| 441 | function toggleAllSummaryInherited(linkObj) { |
| 442 | var a = $(linkObj); |
| 443 | var content = $(a.parent().parent().parent()); |
| 444 | var toggles = $(".toggle-all", content); |
| 445 | if (a.text() == "[Expand All]") { |
| 446 | toggles.each(function(i) { |
| 447 | toggleAllInherited(this, true); |
| 448 | }); |
| 449 | a.text("[Collapse All]"); |
| 450 | } else { |
| 451 | toggles.each(function(i) { |
| 452 | toggleAllInherited(this, false); |
| 453 | }); |
| 454 | a.text("[Expand All]"); |
| 455 | } |
| 456 | return false; |
| 457 | } |
Dirk Dougherty | 4405a23 | 2009-07-07 17:43:27 -0700 | [diff] [blame] | 458 | |
| 459 | |
| 460 | function changeTabLang(lang) { |
| 461 | var nodes = $("#header-tabs").find("."+lang); |
| 462 | for (i=0; i < nodes.length; i++) { // for each node in this language |
| 463 | var node = $(nodes[i]); |
| 464 | node.siblings().css("display","none"); // hide all siblings |
| 465 | if (node.not(":empty").length != 0) { //if this languages node has a translation, show it |
| 466 | node.css("display","inline"); |
| 467 | } else { //otherwise, show English instead |
| 468 | node.css("display","none"); |
| 469 | node.siblings().filter(".en").css("display","inline"); |
| 470 | } |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | function changeNavLang(lang) { |
| 475 | var nodes = $("#side-nav").find("."+lang); |
| 476 | for (i=0; i < nodes.length; i++) { // for each node in this language |
| 477 | var node = $(nodes[i]); |
| 478 | node.siblings().css("display","none"); // hide all siblings |
| 479 | if (node.not(":empty").length != 0) { // if this languages node has a translation, show it |
| 480 | node.css("display","inline"); |
| 481 | } else { // otherwise, show English instead |
| 482 | node.css("display","none"); |
| 483 | node.siblings().filter(".en").css("display","inline"); |
| 484 | } |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | function changeDocLang(lang) { |
| 489 | changeTabLang(lang); |
| 490 | changeNavLang(lang); |
| 491 | } |
| 492 | |
| 493 | function changeLangPref(lang, refresh) { |
| 494 | var date = new Date(); |
| 495 | expires = date.toGMTString(date.setTime(date.getTime()+(10*365*24*60*60*1000))); // keep this for 50 years |
| 496 | //alert("expires: " + expires) |
| 497 | writeCookie("pref_lang", lang, null, expires); |
| 498 | //changeDocLang(lang); |
| 499 | if (refresh) { |
| 500 | l = getBaseUri(location.pathname); |
| 501 | window.location = l; |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | function loadLangPref() { |
| 506 | var lang = readCookie("pref_lang"); |
| 507 | if (lang != 0) { |
| 508 | $("#language").find("option[value='"+lang+"']").attr("selected",true); |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | function getLangPref() { |
Dirk Dougherty | efdcda4 | 2009-07-15 16:41:48 -0700 | [diff] [blame] | 513 | var lang = $("#language").find(":selected").attr("value"); |
| 514 | if (!lang) { |
| 515 | lang = readCookie("pref_lang"); |
| 516 | } |
| 517 | return (lang != 0) ? lang : 'en'; |
Dirk Dougherty | 4405a23 | 2009-07-07 17:43:27 -0700 | [diff] [blame] | 518 | } |
Scott Main | 462cc37 | 2009-10-23 16:19:37 -0700 | [diff] [blame] | 519 | |
| 520 | |
| 521 | function toggleContent(obj) { |
| 522 | var button = $(obj); |
| 523 | var div = $(obj.parentNode); |
| 524 | var toggleMe = $(".toggle-content-toggleme",div); |
| 525 | if (button.hasClass("show")) { |
| 526 | toggleMe.slideDown(); |
| 527 | button.removeClass("show").addClass("hide"); |
| 528 | } else { |
| 529 | toggleMe.slideUp(); |
| 530 | button.removeClass("hide").addClass("show"); |
| 531 | } |
| 532 | $("span", button).toggle(); |
| 533 | } |