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 | |
| 139 | if (location.href.indexOf("/reference/") != -1) { |
| 140 | var cookiePath = "reference_"; |
| 141 | } else if (location.href.indexOf("/guide/") != -1) { |
| 142 | var cookiePath = "guide_"; |
| 143 | } |
The Android Open Source Project | fdd3a10 | 2009-03-11 12:11:54 -0700 | [diff] [blame] | 144 | |
| 145 | if (!isMobile) { |
Scott Main | 3f7d1df | 2009-11-02 15:31:04 -0800 | [diff] [blame] | 146 | $("#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] | 147 | $(".side-nav-resizable").resizable({handles: "e", resize: function(e, ui) { resizeWidth(); } }); |
Dirk Dougherty | 4405a23 | 2009-07-07 17:43:27 -0700 | [diff] [blame] | 148 | var cookieWidth = readCookie(cookiePath+'width'); |
| 149 | var cookieHeight = readCookie(cookiePath+'height'); |
The Android Open Source Project | fdd3a10 | 2009-03-11 12:11:54 -0700 | [diff] [blame] | 150 | if (cookieWidth) { |
| 151 | restoreWidth(cookieWidth); |
| 152 | } else if ($(".side-nav-resizable").length) { |
| 153 | resizeWidth(); |
| 154 | } |
| 155 | if (cookieHeight) { |
| 156 | restoreHeight(cookieHeight); |
| 157 | } else { |
| 158 | resizeHeight(); |
| 159 | } |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | if (devdocNav.length) { // only dev guide and sdk |
| 163 | highlightNav(location.href); |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | function highlightNav(fullPageName) { |
| 168 | var lastSlashPos = fullPageName.lastIndexOf("/"); |
| 169 | var firstSlashPos = (fullPageName.indexOf("/guide/") != -1) ? |
| 170 | fullPageName.indexOf("/guide/") : |
| 171 | fullPageName.indexOf("/sdk/"); // first slash after /guide or /sdk |
| 172 | if (lastSlashPos == (fullPageName.length - 1)) { // if the url ends in slash (add 'index.html') |
| 173 | fullPageName = fullPageName + "index.html"; |
| 174 | } |
| 175 | var htmlPos = fullPageName.lastIndexOf(".html", fullPageName.length); |
| 176 | var pathPageName = fullPageName.slice(firstSlashPos, htmlPos + 5); |
| 177 | var link = $("#devdoc-nav a[href$='"+ pathPageName+"']"); |
Scott Main | 0d8872e | 2009-10-23 13:04:31 -0700 | [diff] [blame] | 178 | if ((link.length == 0) && (fullPageName.indexOf("/guide/") != -1)) { |
| 179 | // 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] | 180 | lastBackstep = pathPageName.lastIndexOf("/"); |
| 181 | while (link.length == 0) { |
| 182 | backstepDirectory = pathPageName.lastIndexOf("/", lastBackstep); |
| 183 | link = $("#devdoc-nav a[href$='"+ pathPageName.slice(0, backstepDirectory + 1)+"index.html']"); |
| 184 | lastBackstep = pathPageName.lastIndexOf("/", lastBackstep - 1); |
| 185 | if (lastBackstep == 0) break; |
| 186 | } |
| 187 | } |
| 188 | link.parent().addClass('selected'); |
| 189 | if (link.parent().parent().is(':hidden')) { |
| 190 | toggle(link.parent().parent().parent(), false); |
| 191 | } else if (link.parent().parent().hasClass('toggle-list')) { |
| 192 | toggle(link.parent().parent(), false); |
| 193 | } |
| 194 | } |
| 195 | |
Scott Main | 3f7d1df | 2009-11-02 15:31:04 -0800 | [diff] [blame] | 196 | /* Resize the height of the nav panels in the reference, |
| 197 | * and save the new size to a cookie */ |
| 198 | function resizePackagesHeight() { |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 199 | var windowHeight = ($(window).height() - HEADER_HEIGHT); |
Scott Main | 3f7d1df | 2009-11-02 15:31:04 -0800 | [diff] [blame] | 200 | 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] | 201 | resizePackagesNav.css({maxHeight:swapperHeight + "px"}); |
| 202 | classesNav.css({height:swapperHeight - parseInt(resizePackagesNav.css("height")) + "px"}); |
Scott Main | 3f7d1df | 2009-11-02 15:31:04 -0800 | [diff] [blame] | 203 | |
| 204 | $("#swapper").css({height:swapperHeight + "px"}); |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 205 | $("#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] | 206 | |
Dirk Dougherty | c13d045 | 2009-07-08 14:39:31 -0700 | [diff] [blame] | 207 | var basePath = getBaseUri(location.pathname); |
| 208 | var section = basePath.substring(1,basePath.indexOf("/",1)); |
Dirk Dougherty | 4405a23 | 2009-07-07 17:43:27 -0700 | [diff] [blame] | 209 | writeCookie("height", resizePackagesNav.css("height"), section, null); |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 210 | } |
| 211 | |
Scott Main | 3f7d1df | 2009-11-02 15:31:04 -0800 | [diff] [blame] | 212 | /* Resize the height of the side-nav and doc-content divs, |
| 213 | * which creates the frame effect */ |
| 214 | function resizeHeight() { |
| 215 | // Get the window height and always resize the doc-content and side-nav divs |
| 216 | var windowHeight = ($(window).height() - HEADER_HEIGHT); |
| 217 | content.css({height:windowHeight + "px"}); |
| 218 | sidenav.css({height:windowHeight + "px"}); |
| 219 | |
| 220 | var href = location.href; |
| 221 | // If in the reference docs, also resize the "swapper", "classes-nav", and "nav-tree" divs |
| 222 | if (href.indexOf("/reference/") != -1) { |
| 223 | var swapperHeight = windowHeight - 13; |
| 224 | $("#swapper").css({height:swapperHeight + "px"}); |
| 225 | $("#classes-nav").css({height:swapperHeight - parseInt(resizePackagesNav.css("height")) + "px"}); |
| 226 | $("#nav-tree").css({height:swapperHeight + "px"}); |
| 227 | |
| 228 | // If in the dev guide docs, also resize the "devdoc-nav" div |
| 229 | } else if (href.indexOf("/guide/") != -1) { |
| 230 | $("#devdoc-nav").css({height:sidenav.css("height")}); |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | /* Resize the width of the "side-nav" and the left margin of the "doc-content" div, |
| 235 | * which creates the resizable side bar */ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 236 | function resizeWidth() { |
| 237 | var windowWidth = $(window).width() + "px"; |
| 238 | if (sidenav.length) { |
| 239 | var sidenavWidth = sidenav.css("width"); |
| 240 | } else { |
| 241 | var sidenavWidth = 0; |
| 242 | } |
Scott Main | 3f7d1df | 2009-11-02 15:31:04 -0800 | [diff] [blame] | 243 | content.css({marginLeft:parseInt(sidenavWidth) + 6 + "px"}); //account for 6px-wide handle-bar |
| 244 | |
| 245 | if (isIE6) { |
| 246 | content.css({width:parseInt(windowWidth) - parseInt(sidenavWidth) - 6 + "px"}); // necessary in order to for scrollbars to be visible |
| 247 | } |
| 248 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 249 | resizePackagesNav.css({width:sidenavWidth}); |
| 250 | classesNav.css({width:sidenavWidth}); |
| 251 | $("#packages-nav").css({width:sidenavWidth}); |
Scott Main | 3f7d1df | 2009-11-02 15:31:04 -0800 | [diff] [blame] | 252 | |
Dirk Dougherty | c13d045 | 2009-07-08 14:39:31 -0700 | [diff] [blame] | 253 | var basePath = getBaseUri(location.pathname); |
| 254 | var section = basePath.substring(1,basePath.indexOf("/",1)); |
Dirk Dougherty | 4405a23 | 2009-07-07 17:43:27 -0700 | [diff] [blame] | 255 | writeCookie("width", sidenavWidth, section, null); |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 256 | } |
| 257 | |
Scott Main | 3f7d1df | 2009-11-02 15:31:04 -0800 | [diff] [blame] | 258 | /* For IE6 only, |
| 259 | * because it can't properly perform auto width for "doc-content" div, |
| 260 | * avoiding this for all browsers provides better performance */ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 261 | function resizeAll() { |
Scott Main | 3f7d1df | 2009-11-02 15:31:04 -0800 | [diff] [blame] | 262 | resizeHeight(); |
| 263 | resizeWidth(); |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 264 | } |
| 265 | |
Dirk Dougherty | 4405a23 | 2009-07-07 17:43:27 -0700 | [diff] [blame] | 266 | function getBaseUri(uri) { |
Dirk Dougherty | efdcda4 | 2009-07-15 16:41:48 -0700 | [diff] [blame] | 267 | var intlUrl = (uri.substring(0,6) == "/intl/"); |
Dirk Dougherty | 4405a23 | 2009-07-07 17:43:27 -0700 | [diff] [blame] | 268 | if (intlUrl) { |
| 269 | base = uri.substring(uri.indexOf('intl/')+5,uri.length); |
| 270 | base = base.substring(base.indexOf('/')+1, base.length); |
| 271 | //alert("intl, returning base url: /" + base); |
| 272 | return ("/" + base); |
| 273 | } else { |
| 274 | //alert("not intl, returning uri as found."); |
| 275 | return uri; |
| 276 | } |
| 277 | } |
| 278 | |
Dirk Dougherty | efdcda4 | 2009-07-15 16:41:48 -0700 | [diff] [blame] | 279 | function requestAppendHL(uri) { |
| 280 | //append "?hl=<lang> to an outgoing request (such as to blog) |
| 281 | var lang = getLangPref(); |
| 282 | if (lang) { |
| 283 | var q = 'hl=' + lang; |
| 284 | uri += '?' + q; |
| 285 | window.location = uri; |
| 286 | return false; |
| 287 | } else { |
| 288 | return true; |
| 289 | } |
| 290 | } |
| 291 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 292 | function loadLast(cookiePath) { |
| 293 | var location = window.location.href; |
| 294 | if (location.indexOf("/"+cookiePath+"/") != -1) { |
| 295 | return true; |
| 296 | } |
Dirk Dougherty | 4405a23 | 2009-07-07 17:43:27 -0700 | [diff] [blame] | 297 | var lastPage = readCookie(cookiePath + "_lastpage"); |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 298 | if (lastPage) { |
| 299 | window.location = lastPage; |
| 300 | return false; |
| 301 | } |
| 302 | return true; |
| 303 | } |
| 304 | |
| 305 | $(window).unload(function(){ |
Dirk Dougherty | 4405a23 | 2009-07-07 17:43:27 -0700 | [diff] [blame] | 306 | var path = getBaseUri(location.pathname); |
| 307 | if (path.indexOf("/reference/") != -1) { |
| 308 | writeCookie("lastpage", path, "reference", null); |
| 309 | } else if (path.indexOf("/guide/") != -1) { |
| 310 | writeCookie("lastpage", path, "guide", null); |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 311 | } |
| 312 | }); |
| 313 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 314 | function toggle(obj, slide) { |
| 315 | var ul = $("ul", obj); |
| 316 | var li = ul.parent(); |
| 317 | if (li.hasClass("closed")) { |
| 318 | if (slide) { |
| 319 | ul.slideDown("fast"); |
| 320 | } else { |
| 321 | ul.show(); |
| 322 | } |
| 323 | li.removeClass("closed"); |
| 324 | li.addClass("open"); |
| 325 | $(".toggle-img", li).attr("title", "hide pages"); |
| 326 | } else { |
| 327 | ul.slideUp("fast"); |
| 328 | li.removeClass("open"); |
| 329 | li.addClass("closed"); |
| 330 | $(".toggle-img", li).attr("title", "show pages"); |
| 331 | } |
| 332 | } |
| 333 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 334 | function buildToggleLists() { |
| 335 | $(".toggle-list").each( |
| 336 | function(i) { |
| 337 | $("div", this).append("<a class='toggle-img' href='#' title='show pages' onClick='toggle(this.parentNode.parentNode, true); return false;'></a>"); |
| 338 | $(this).addClass("closed"); |
| 339 | }); |
| 340 | } |
| 341 | |
| 342 | function getNavPref() { |
Dirk Dougherty | 4405a23 | 2009-07-07 17:43:27 -0700 | [diff] [blame] | 343 | var v = readCookie('reference_nav'); |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 344 | if (v != NAV_PREF_TREE) { |
| 345 | v = NAV_PREF_PANELS; |
| 346 | } |
| 347 | return v; |
| 348 | } |
| 349 | |
| 350 | function chooseDefaultNav() { |
| 351 | nav_pref = getNavPref(); |
| 352 | if (nav_pref == NAV_PREF_TREE) { |
| 353 | $("#nav-panels").toggle(); |
| 354 | $("#panel-link").toggle(); |
| 355 | $("#nav-tree").toggle(); |
| 356 | $("#tree-link").toggle(); |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | function swapNav() { |
| 361 | if (nav_pref == NAV_PREF_TREE) { |
| 362 | nav_pref = NAV_PREF_PANELS; |
| 363 | } else { |
| 364 | nav_pref = NAV_PREF_TREE; |
Dirk Dougherty | 3b1ee37 | 2009-07-29 12:25:44 -0700 | [diff] [blame] | 365 | init_default_navtree(toRoot); |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 366 | } |
| 367 | var date = new Date(); |
| 368 | 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] | 369 | writeCookie("nav", nav_pref, "reference", date.toGMTString()); |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 370 | |
| 371 | $("#nav-panels").toggle(); |
| 372 | $("#panel-link").toggle(); |
| 373 | $("#nav-tree").toggle(); |
| 374 | $("#tree-link").toggle(); |
| 375 | |
| 376 | if ($("#nav-tree").is(':visible')) scrollIntoView("nav-tree"); |
| 377 | else { |
| 378 | scrollIntoView("packages-nav"); |
| 379 | scrollIntoView("classes-nav"); |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | function scrollIntoView(nav) { |
| 384 | var navObj = $("#"+nav); |
| 385 | if (navObj.is(':visible')) { |
| 386 | var selected = $(".selected", navObj); |
| 387 | if (selected.length == 0) return; |
| 388 | if (selected.is("div")) selected = selected.parent(); |
| 389 | |
| 390 | var scrolling = document.getElementById(nav); |
| 391 | var navHeight = navObj.height(); |
| 392 | var offsetTop = selected.position().top; |
| 393 | if (selected.parent().parent().is(".toggle-list")) offsetTop += selected.parent().parent().position().top; |
| 394 | if(offsetTop > navHeight - 92) { |
| 395 | scrolling.scrollTop = offsetTop - navHeight + 92; |
| 396 | } |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | function toggleAllInherited(linkObj, expand) { |
| 401 | var a = $(linkObj); |
| 402 | var table = $(a.parent().parent().parent()); |
| 403 | var expandos = $(".jd-expando-trigger", table); |
| 404 | if ( (expand == null && a.text() == "[Expand]") || expand ) { |
| 405 | expandos.each(function(i) { |
| 406 | toggleInherited(this, true); |
| 407 | }); |
| 408 | a.text("[Collapse]"); |
| 409 | } else if ( (expand == null && a.text() == "[Collapse]") || (expand == false) ) { |
| 410 | expandos.each(function(i) { |
| 411 | toggleInherited(this, false); |
| 412 | }); |
| 413 | a.text("[Expand]"); |
| 414 | } |
| 415 | return false; |
| 416 | } |
| 417 | |
| 418 | function toggleAllSummaryInherited(linkObj) { |
| 419 | var a = $(linkObj); |
| 420 | var content = $(a.parent().parent().parent()); |
| 421 | var toggles = $(".toggle-all", content); |
| 422 | if (a.text() == "[Expand All]") { |
| 423 | toggles.each(function(i) { |
| 424 | toggleAllInherited(this, true); |
| 425 | }); |
| 426 | a.text("[Collapse All]"); |
| 427 | } else { |
| 428 | toggles.each(function(i) { |
| 429 | toggleAllInherited(this, false); |
| 430 | }); |
| 431 | a.text("[Expand All]"); |
| 432 | } |
| 433 | return false; |
| 434 | } |
Dirk Dougherty | 4405a23 | 2009-07-07 17:43:27 -0700 | [diff] [blame] | 435 | |
| 436 | |
| 437 | function changeTabLang(lang) { |
| 438 | var nodes = $("#header-tabs").find("."+lang); |
| 439 | for (i=0; i < nodes.length; i++) { // for each node in this language |
| 440 | var node = $(nodes[i]); |
| 441 | node.siblings().css("display","none"); // hide all siblings |
| 442 | if (node.not(":empty").length != 0) { //if this languages node has a translation, show it |
| 443 | node.css("display","inline"); |
| 444 | } else { //otherwise, show English instead |
| 445 | node.css("display","none"); |
| 446 | node.siblings().filter(".en").css("display","inline"); |
| 447 | } |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | function changeNavLang(lang) { |
| 452 | var nodes = $("#side-nav").find("."+lang); |
| 453 | for (i=0; i < nodes.length; i++) { // for each node in this language |
| 454 | var node = $(nodes[i]); |
| 455 | node.siblings().css("display","none"); // hide all siblings |
| 456 | if (node.not(":empty").length != 0) { // if this languages node has a translation, show it |
| 457 | node.css("display","inline"); |
| 458 | } else { // otherwise, show English instead |
| 459 | node.css("display","none"); |
| 460 | node.siblings().filter(".en").css("display","inline"); |
| 461 | } |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | function changeDocLang(lang) { |
| 466 | changeTabLang(lang); |
| 467 | changeNavLang(lang); |
| 468 | } |
| 469 | |
| 470 | function changeLangPref(lang, refresh) { |
| 471 | var date = new Date(); |
| 472 | expires = date.toGMTString(date.setTime(date.getTime()+(10*365*24*60*60*1000))); // keep this for 50 years |
| 473 | //alert("expires: " + expires) |
| 474 | writeCookie("pref_lang", lang, null, expires); |
| 475 | //changeDocLang(lang); |
| 476 | if (refresh) { |
| 477 | l = getBaseUri(location.pathname); |
| 478 | window.location = l; |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | function loadLangPref() { |
| 483 | var lang = readCookie("pref_lang"); |
| 484 | if (lang != 0) { |
| 485 | $("#language").find("option[value='"+lang+"']").attr("selected",true); |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | function getLangPref() { |
Dirk Dougherty | efdcda4 | 2009-07-15 16:41:48 -0700 | [diff] [blame] | 490 | var lang = $("#language").find(":selected").attr("value"); |
| 491 | if (!lang) { |
| 492 | lang = readCookie("pref_lang"); |
| 493 | } |
| 494 | return (lang != 0) ? lang : 'en'; |
Dirk Dougherty | 4405a23 | 2009-07-07 17:43:27 -0700 | [diff] [blame] | 495 | } |
Scott Main | 462cc37 | 2009-10-23 16:19:37 -0700 | [diff] [blame] | 496 | |
| 497 | |
| 498 | function toggleContent(obj) { |
| 499 | var button = $(obj); |
| 500 | var div = $(obj.parentNode); |
| 501 | var toggleMe = $(".toggle-content-toggleme",div); |
| 502 | if (button.hasClass("show")) { |
| 503 | toggleMe.slideDown(); |
| 504 | button.removeClass("show").addClass("hide"); |
| 505 | } else { |
| 506 | toggleMe.slideUp(); |
| 507 | button.removeClass("hide").addClass("show"); |
| 508 | } |
| 509 | $("span", button).toggle(); |
| 510 | } |