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