blob: d61ce7218165060eab57e3ffeda185a1a58290e7 [file] [log] [blame]
The Android Open Source Project88b60792009-03-03 19:28:42 -08001var resizePackagesNav;
2var classesNav;
3var devdocNav;
4var sidenav;
5var content;
6var HEADER_HEIGHT = 117;
Dirk Dougherty4405a232009-07-07 17:43:27 -07007var cookie_namespace = 'android_developer';
The Android Open Source Project88b60792009-03-03 19:28:42 -08008var NAV_PREF_TREE = "tree";
9var NAV_PREF_PANELS = "panels";
10var nav_pref;
11var toRoot;
The Android Open Source Projectfdd3a102009-03-11 12:11:54 -070012var isMobile = false; // true if mobile, so we can adjust some layout
Scott Main3f7d1df2009-11-02 15:31:04 -080013var isIE6 = false; // true if IE6
The Android Open Source Project88b60792009-03-03 19:28:42 -080014
Scott Mainf8af8872009-12-02 20:59:40 -080015// TODO: use $(document).ready instead
The Android Open Source Project88b60792009-03-03 19:28:42 -080016function 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 Maind8115ff2009-11-03 18:54:26 -080028var agent = navigator['userAgent'].toLowerCase();
Scott Main3f7d1df2009-11-02 15:31:04 -080029// If a mobile phone, set flag and do mobile setup
Roman Nurik78eff9f2010-03-01 18:35:13 -080030if ((agent.indexOf("mobile") != -1) || // android, iphone, ipod
Scott Maind8115ff2009-11-03 18:54:26 -080031 (agent.indexOf("blackberry") != -1) ||
32 (agent.indexOf("webos") != -1) ||
Roman Nurik78eff9f2010-03-01 18:35:13 -080033 (agent.indexOf("mini") != -1)) { // opera mini browsers
The Android Open Source Projectfdd3a102009-03-11 12:11:54 -070034 isMobile = true;
35 addLoadEvent(mobileSetup);
Scott Main3f7d1df2009-11-02 15:31:04 -080036// If not a mobile browser, set the onresize event for IE6, and others
Scott Maind8115ff2009-11-03 18:54:26 -080037} else if (agent.indexOf("msie 6") != -1) {
Scott Main3f7d1df2009-11-02 15:31:04 -080038 isIE6 = true;
39 addLoadEvent(function() {
40 window.onresize = resizeAll;
41 });
42} else {
43 addLoadEvent(function() {
44 window.onresize = resizeHeight;
45 });
The Android Open Source Projectfdd3a102009-03-11 12:11:54 -070046}
47
The Android Open Source Projectfdd3a102009-03-11 12:11:54 -070048function 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 Main25fda192009-08-04 11:26:30 -070057/* loads the lists.js file to the page.
58Loading this in the head was slowing page load time */
59addLoadEvent( function() {
60 var lists = document.createElement("script");
61 lists.setAttribute("type","text/javascript");
62 lists.setAttribute("src", toRoot+"reference/lists.js");
Scott Main1da82382009-09-17 10:54:05 -070063 document.getElementsByTagName("head")[0].appendChild(lists);
Scott Main25fda192009-08-04 11:26:30 -070064} );
65
Scott Mainf8af8872009-12-02 20:59:40 -080066addLoadEvent( function() {
Scott Main945ed362010-01-15 17:30:38 -080067 $("pre:not(.no-pretty-print)").addClass("prettyprint");
Scott Mainf8af8872009-12-02 20:59:40 -080068 prettyPrint();
69} );
70
The Android Open Source Project88b60792009-03-03 19:28:42 -080071function setToRoot(root) {
72 toRoot = root;
73 // note: toRoot also used by carousel.js
74}
75
76function restoreWidth(navWidth) {
77 var windowWidth = $(window).width() + "px";
Scott Main3f7d1df2009-11-02 15:31:04 -080078 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 Project88b60792009-03-03 19:28:42 -080084 sidenav.css({width:navWidth});
85 resizePackagesNav.css({width:navWidth});
86 classesNav.css({width:navWidth});
87 $("#packages-nav").css({width:navWidth});
88}
89
90function 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 Dougherty4405a232009-07-07 17:43:27 -0700103function readCookie(cookie) {
104 var myCookie = cookie_namespace+"_"+cookie+"=";
The Android Open Source Project88b60792009-03-03 19:28:42 -0800105 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 Dougherty4405a232009-07-07 17:43:27 -0700120function writeCookie(cookie, val, section, expiration) {
Scott Main9b5fdb92009-10-27 15:09:15 -0700121 if (val==undefined) return;
Dirk Dougherty4405a232009-07-07 17:43:27 -0700122 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 Project88b60792009-03-03 19:28:42 -0800127 }
Scott Main3f7d1df2009-11-02 15:31:04 -0800128 document.cookie = cookie_namespace + section + cookie + "=" + val + "; expires=" + expiration+"; path=/";
Roman Nurik78eff9f2010-03-01 18:35:13 -0800129}
The Android Open Source Project88b60792009-03-03 19:28:42 -0800130
131function init() {
The Android Open Source Project88b60792009-03-03 19:28:42 -0800132 $("#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 Maina39d3bb2010-01-06 14:18:02 -0800139 var cookiePath = "";
The Android Open Source Project88b60792009-03-03 19:28:42 -0800140 if (location.href.indexOf("/reference/") != -1) {
Scott Maina39d3bb2010-01-06 14:18:02 -0800141 cookiePath = "reference_";
The Android Open Source Project88b60792009-03-03 19:28:42 -0800142 } else if (location.href.indexOf("/guide/") != -1) {
Scott Maina39d3bb2010-01-06 14:18:02 -0800143 cookiePath = "guide_";
Dirk Dougherty502c4982009-12-02 18:01:16 -0800144 } else if (location.href.indexOf("/resources/") != -1) {
Scott Maina39d3bb2010-01-06 14:18:02 -0800145 cookiePath = "resources_";
The Android Open Source Project88b60792009-03-03 19:28:42 -0800146 }
The Android Open Source Projectfdd3a102009-03-11 12:11:54 -0700147
148 if (!isMobile) {
Scott Main3f7d1df2009-11-02 15:31:04 -0800149 $("#resize-packages-nav").resizable({handles: "s", resize: function(e, ui) { resizePackagesHeight(); } });
The Android Open Source Projectfdd3a102009-03-11 12:11:54 -0700150 $(".side-nav-resizable").resizable({handles: "e", resize: function(e, ui) { resizeWidth(); } });
Dirk Dougherty4405a232009-07-07 17:43:27 -0700151 var cookieWidth = readCookie(cookiePath+'width');
152 var cookieHeight = readCookie(cookiePath+'height');
The Android Open Source Projectfdd3a102009-03-11 12:11:54 -0700153 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 Project88b60792009-03-03 19:28:42 -0800163 }
164
Roman Nurik78eff9f2010-03-01 18:35:13 -0800165 if (devdocNav.length) { // only dev guide, resources, and sdk
166 tryPopulateResourcesNav();
167 highlightNav(location.href);
The Android Open Source Project88b60792009-03-03 19:28:42 -0800168 }
169}
170
Roman Nurik78eff9f2010-03-01 18:35:13 -0800171function tryPopulateResourcesNav() {
172 var sampleList = $('#devdoc-nav-sample-list');
173 var articleList = $('#devdoc-nav-article-list');
174 var tutorialList = $('#devdoc-nav-tutorial-list');
175 var topicList = $('#devdoc-nav-topic-list');
176
177 if (!topicList.length || !ANDROID_TAGS || !ANDROID_RESOURCES)
178 return;
179
180 var topics = [];
181 for (var topic in ANDROID_TAGS['topic']) {
182 topics.push({name:topic,title:ANDROID_TAGS['topic'][topic]});
183 }
184 topics.sort(function(x,y){ return (x.title < y.title) ? -1 : 1; });
185 for (var i = 0; i < topics.length; i++) {
186 topicList.append(
187 $('<li>').append(
188 $('<a>')
189 .attr('href', toRoot + "resources/browser.html?tag=" + topics[i].name)
190 .append($('<span>')
191 .addClass('en')
192 .html(topics[i].title)
193 )
194 )
195 );
196 }
197
198 var _renderResourceList = function(tag, listNode) {
199 var resources = [];
200 var tags;
201 var resource;
202 var i, j;
203 for (i = 0; i < ANDROID_RESOURCES.length; i++) {
204 resource = ANDROID_RESOURCES[i];
205 tags = resource.tags || [];
206 var hasTag = false;
207 for (j = 0; j < tags.length; j++)
208 if (tags[j] == tag) {
209 hasTag = true;
210 break;
211 }
212 if (!hasTag)
213 continue;
214 resources.push(resource);
215 }
216 //resources.sort(function(x,y){ return (x.title.en < y.title.en) ? -1 : 1; });
217 for (i = 0; i < resources.length; i++) {
218 resource = resources[i];
219 var listItemNode = $('<li>').append(
220 $('<a>')
221 .attr('href', toRoot + "resources/" + resource.path)
222 .append($('<span>')
223 .addClass('en')
224 .html(resource.title.en)
225 )
226 );
227 tags = resource.tags || [];
228 for (j = 0; j < tags.length; j++) {
229 if (tags[j] == 'new') {
230 listItemNode.get(0).innerHTML += '&nbsp;<span class="new">new!</span>';
231 break;
232 }
233 }
234 listNode.append(listItemNode);
235 }
236 };
237
238 _renderResourceList('sample', sampleList);
239 _renderResourceList('article', articleList);
240 _renderResourceList('tutorial', tutorialList);
241}
242
The Android Open Source Project88b60792009-03-03 19:28:42 -0800243function highlightNav(fullPageName) {
244 var lastSlashPos = fullPageName.lastIndexOf("/");
Dirk Dougherty502c4982009-12-02 18:01:16 -0800245 var firstSlashPos;
246 if (fullPageName.indexOf("/guide/") != -1) {
247 firstSlashPos = fullPageName.indexOf("/guide/");
248 } else if (fullPageName.indexOf("/sdk/") != -1) {
249 firstSlashPos = fullPageName.indexOf("/sdk/");
250 } else {
251 firstSlashPos = fullPageName.indexOf("/resources/");
252 }
The Android Open Source Project88b60792009-03-03 19:28:42 -0800253 if (lastSlashPos == (fullPageName.length - 1)) { // if the url ends in slash (add 'index.html')
254 fullPageName = fullPageName + "index.html";
255 }
Roman Nurik78eff9f2010-03-01 18:35:13 -0800256 // First check if the exact URL, with query string and all, is in the navigation menu
257 var pathPageName = fullPageName.substr(firstSlashPos);
The Android Open Source Project88b60792009-03-03 19:28:42 -0800258 var link = $("#devdoc-nav a[href$='"+ pathPageName+"']");
Roman Nurik78eff9f2010-03-01 18:35:13 -0800259 if (link.length == 0) {
260 var htmlPos = fullPageName.lastIndexOf(".html", fullPageName.length);
261 pathPageName = fullPageName.slice(firstSlashPos, htmlPos + 5); // +5 advances past ".html"
262 link = $("#devdoc-nav a[href$='"+ pathPageName+"']");
263 if ((link.length == 0) && ((fullPageName.indexOf("/guide/") != -1) || (fullPageName.indexOf("/resources/") != -1))) {
264 // if there's no match, then let's backstep through the directory until we find an index.html page
265 // that matches our ancestor directories (only for dev guide and resources)
266 lastBackstep = pathPageName.lastIndexOf("/");
267 while (link.length == 0) {
268 backstepDirectory = pathPageName.lastIndexOf("/", lastBackstep);
269 link = $("#devdoc-nav a[href$='"+ pathPageName.slice(0, backstepDirectory + 1)+"index.html']");
270 lastBackstep = pathPageName.lastIndexOf("/", lastBackstep - 1);
271 if (lastBackstep == 0) break;
272 }
The Android Open Source Project88b60792009-03-03 19:28:42 -0800273 }
274 }
Scott Mainee629d92010-02-05 14:30:08 -0800275
276 // add 'selected' to the <li> or <div> that wraps this <a>
The Android Open Source Project88b60792009-03-03 19:28:42 -0800277 link.parent().addClass('selected');
Scott Mainee629d92010-02-05 14:30:08 -0800278
279 // if we're in a toggleable root link (<li class=toggle-list><div><a>)
280 if (link.parent().parent().hasClass('toggle-list')) {
281 toggle(link.parent().parent(), false); // open our own list
282 // then also check if we're in a third-level nested list that's toggleable
283 if (link.parent().parent().parent().is(':hidden')) {
284 toggle(link.parent().parent().parent().parent(), false); // open the super parent list
285 }
286 }
287 // if we're in a normal nav link (<li><a>) and the parent <ul> is hidden
288 else if (link.parent().parent().is(':hidden')) {
289 toggle(link.parent().parent().parent(), false); // open the parent list
290 // then also check if the parent list is also nested in a hidden list
291 if (link.parent().parent().parent().parent().is(':hidden')) {
292 toggle(link.parent().parent().parent().parent().parent(), false); // open the super parent list
293 }
The Android Open Source Project88b60792009-03-03 19:28:42 -0800294 }
295}
296
Scott Main3f7d1df2009-11-02 15:31:04 -0800297/* Resize the height of the nav panels in the reference,
298 * and save the new size to a cookie */
299function resizePackagesHeight() {
The Android Open Source Project88b60792009-03-03 19:28:42 -0800300 var windowHeight = ($(window).height() - HEADER_HEIGHT);
Scott Main3f7d1df2009-11-02 15:31:04 -0800301 var swapperHeight = windowHeight - 13; // move 13px for swapper link at the bottom
The Android Open Source Project88b60792009-03-03 19:28:42 -0800302 resizePackagesNav.css({maxHeight:swapperHeight + "px"});
303 classesNav.css({height:swapperHeight - parseInt(resizePackagesNav.css("height")) + "px"});
Scott Main3f7d1df2009-11-02 15:31:04 -0800304
305 $("#swapper").css({height:swapperHeight + "px"});
The Android Open Source Project88b60792009-03-03 19:28:42 -0800306 $("#packages-nav").css({height:parseInt(resizePackagesNav.css("height")) - 6 + "px"}); //move 6px for handle
Scott Main3f7d1df2009-11-02 15:31:04 -0800307
Dirk Doughertyc13d0452009-07-08 14:39:31 -0700308 var basePath = getBaseUri(location.pathname);
309 var section = basePath.substring(1,basePath.indexOf("/",1));
Dirk Dougherty4405a232009-07-07 17:43:27 -0700310 writeCookie("height", resizePackagesNav.css("height"), section, null);
The Android Open Source Project88b60792009-03-03 19:28:42 -0800311}
312
Scott Main3f7d1df2009-11-02 15:31:04 -0800313/* Resize the height of the side-nav and doc-content divs,
314 * which creates the frame effect */
315function resizeHeight() {
Scott Main13b79b22010-01-12 13:37:00 -0800316 var docContent = $("#doc-content");
317
Scott Main3f7d1df2009-11-02 15:31:04 -0800318 // Get the window height and always resize the doc-content and side-nav divs
319 var windowHeight = ($(window).height() - HEADER_HEIGHT);
Scott Main13b79b22010-01-12 13:37:00 -0800320 docContent.css({height:windowHeight + "px"});
321 $("#side-nav").css({height:windowHeight + "px"});
Scott Main3f7d1df2009-11-02 15:31:04 -0800322
323 var href = location.href;
324 // If in the reference docs, also resize the "swapper", "classes-nav", and "nav-tree" divs
325 if (href.indexOf("/reference/") != -1) {
326 var swapperHeight = windowHeight - 13;
327 $("#swapper").css({height:swapperHeight + "px"});
328 $("#classes-nav").css({height:swapperHeight - parseInt(resizePackagesNav.css("height")) + "px"});
329 $("#nav-tree").css({height:swapperHeight + "px"});
330
331 // If in the dev guide docs, also resize the "devdoc-nav" div
332 } else if (href.indexOf("/guide/") != -1) {
333 $("#devdoc-nav").css({height:sidenav.css("height")});
Dirk Dougherty502c4982009-12-02 18:01:16 -0800334 } else if (href.indexOf("/resources/") != -1) {
335 $("#devdoc-nav").css({height:sidenav.css("height")});
Scott Main3f7d1df2009-11-02 15:31:04 -0800336 }
Scott Main13b79b22010-01-12 13:37:00 -0800337
338 // Hide the "Go to top" link if there's no vertical scroll
339 if ( parseInt($("#jd-content").css("height")) <= parseInt(docContent.css("height")) ) {
340 $("a[href='#top']").css({'display':'none'});
341 } else {
342 $("a[href='#top']").css({'display':'inline'});
343 }
Scott Main3f7d1df2009-11-02 15:31:04 -0800344}
345
346/* Resize the width of the "side-nav" and the left margin of the "doc-content" div,
347 * which creates the resizable side bar */
The Android Open Source Project88b60792009-03-03 19:28:42 -0800348function resizeWidth() {
349 var windowWidth = $(window).width() + "px";
350 if (sidenav.length) {
351 var sidenavWidth = sidenav.css("width");
352 } else {
353 var sidenavWidth = 0;
354 }
Scott Main3f7d1df2009-11-02 15:31:04 -0800355 content.css({marginLeft:parseInt(sidenavWidth) + 6 + "px"}); //account for 6px-wide handle-bar
356
357 if (isIE6) {
358 content.css({width:parseInt(windowWidth) - parseInt(sidenavWidth) - 6 + "px"}); // necessary in order to for scrollbars to be visible
359 }
360
The Android Open Source Project88b60792009-03-03 19:28:42 -0800361 resizePackagesNav.css({width:sidenavWidth});
362 classesNav.css({width:sidenavWidth});
363 $("#packages-nav").css({width:sidenavWidth});
Scott Main3f7d1df2009-11-02 15:31:04 -0800364
Scott Mainb6da4802010-01-06 14:18:02 -0800365 if ($(".side-nav-resizable").length) { // Must check if the nav is resizable because IE6 calls resizeWidth() from resizeAll() for all pages
366 var basePath = getBaseUri(location.pathname);
367 var section = basePath.substring(1,basePath.indexOf("/",1));
368 writeCookie("width", sidenavWidth, section, null);
369 }
The Android Open Source Project88b60792009-03-03 19:28:42 -0800370}
371
Scott Main3f7d1df2009-11-02 15:31:04 -0800372/* For IE6 only,
373 * because it can't properly perform auto width for "doc-content" div,
374 * avoiding this for all browsers provides better performance */
The Android Open Source Project88b60792009-03-03 19:28:42 -0800375function resizeAll() {
Scott Main3f7d1df2009-11-02 15:31:04 -0800376 resizeHeight();
Scott Mainb6da4802010-01-06 14:18:02 -0800377 resizeWidth();
The Android Open Source Project88b60792009-03-03 19:28:42 -0800378}
379
Dirk Dougherty4405a232009-07-07 17:43:27 -0700380function getBaseUri(uri) {
Dirk Doughertyefdcda42009-07-15 16:41:48 -0700381 var intlUrl = (uri.substring(0,6) == "/intl/");
Dirk Dougherty4405a232009-07-07 17:43:27 -0700382 if (intlUrl) {
383 base = uri.substring(uri.indexOf('intl/')+5,uri.length);
384 base = base.substring(base.indexOf('/')+1, base.length);
385 //alert("intl, returning base url: /" + base);
386 return ("/" + base);
387 } else {
388 //alert("not intl, returning uri as found.");
389 return uri;
390 }
391}
392
Dirk Doughertyefdcda42009-07-15 16:41:48 -0700393function requestAppendHL(uri) {
394//append "?hl=<lang> to an outgoing request (such as to blog)
395 var lang = getLangPref();
396 if (lang) {
397 var q = 'hl=' + lang;
398 uri += '?' + q;
399 window.location = uri;
400 return false;
401 } else {
402 return true;
403 }
404}
405
The Android Open Source Project88b60792009-03-03 19:28:42 -0800406function loadLast(cookiePath) {
407 var location = window.location.href;
408 if (location.indexOf("/"+cookiePath+"/") != -1) {
409 return true;
410 }
Dirk Dougherty4405a232009-07-07 17:43:27 -0700411 var lastPage = readCookie(cookiePath + "_lastpage");
The Android Open Source Project88b60792009-03-03 19:28:42 -0800412 if (lastPage) {
413 window.location = lastPage;
414 return false;
415 }
416 return true;
417}
418
419$(window).unload(function(){
Dirk Dougherty4405a232009-07-07 17:43:27 -0700420 var path = getBaseUri(location.pathname);
421 if (path.indexOf("/reference/") != -1) {
422 writeCookie("lastpage", path, "reference", null);
423 } else if (path.indexOf("/guide/") != -1) {
424 writeCookie("lastpage", path, "guide", null);
Dirk Dougherty502c4982009-12-02 18:01:16 -0800425 } else if (path.indexOf("/resources/") != -1) {
426 writeCookie("lastpage", path, "resources", null);
The Android Open Source Project88b60792009-03-03 19:28:42 -0800427 }
428});
429
The Android Open Source Project88b60792009-03-03 19:28:42 -0800430function toggle(obj, slide) {
Scott Mainee629d92010-02-05 14:30:08 -0800431 var ul = $("ul:first", obj);
The Android Open Source Project88b60792009-03-03 19:28:42 -0800432 var li = ul.parent();
433 if (li.hasClass("closed")) {
434 if (slide) {
435 ul.slideDown("fast");
436 } else {
437 ul.show();
438 }
439 li.removeClass("closed");
440 li.addClass("open");
441 $(".toggle-img", li).attr("title", "hide pages");
442 } else {
443 ul.slideUp("fast");
444 li.removeClass("open");
445 li.addClass("closed");
446 $(".toggle-img", li).attr("title", "show pages");
447 }
448}
449
The Android Open Source Project88b60792009-03-03 19:28:42 -0800450function buildToggleLists() {
451 $(".toggle-list").each(
452 function(i) {
Scott Mainee629d92010-02-05 14:30:08 -0800453 $("div:first", this).append("<a class='toggle-img' href='#' title='show pages' onClick='toggle(this.parentNode.parentNode, true); return false;'></a>");
The Android Open Source Project88b60792009-03-03 19:28:42 -0800454 $(this).addClass("closed");
455 });
456}
457
458function getNavPref() {
Dirk Dougherty4405a232009-07-07 17:43:27 -0700459 var v = readCookie('reference_nav');
The Android Open Source Project88b60792009-03-03 19:28:42 -0800460 if (v != NAV_PREF_TREE) {
461 v = NAV_PREF_PANELS;
462 }
463 return v;
464}
465
466function chooseDefaultNav() {
467 nav_pref = getNavPref();
468 if (nav_pref == NAV_PREF_TREE) {
469 $("#nav-panels").toggle();
470 $("#panel-link").toggle();
471 $("#nav-tree").toggle();
472 $("#tree-link").toggle();
473 }
474}
475
476function swapNav() {
477 if (nav_pref == NAV_PREF_TREE) {
478 nav_pref = NAV_PREF_PANELS;
479 } else {
480 nav_pref = NAV_PREF_TREE;
Dirk Dougherty3b1ee372009-07-29 12:25:44 -0700481 init_default_navtree(toRoot);
The Android Open Source Project88b60792009-03-03 19:28:42 -0800482 }
483 var date = new Date();
484 date.setTime(date.getTime()+(10*365*24*60*60*1000)); // keep this for 10 years
Dirk Dougherty4405a232009-07-07 17:43:27 -0700485 writeCookie("nav", nav_pref, "reference", date.toGMTString());
The Android Open Source Project88b60792009-03-03 19:28:42 -0800486
487 $("#nav-panels").toggle();
488 $("#panel-link").toggle();
489 $("#nav-tree").toggle();
490 $("#tree-link").toggle();
491
492 if ($("#nav-tree").is(':visible')) scrollIntoView("nav-tree");
493 else {
494 scrollIntoView("packages-nav");
495 scrollIntoView("classes-nav");
496 }
497}
498
499function scrollIntoView(nav) {
500 var navObj = $("#"+nav);
501 if (navObj.is(':visible')) {
502 var selected = $(".selected", navObj);
503 if (selected.length == 0) return;
504 if (selected.is("div")) selected = selected.parent();
505
506 var scrolling = document.getElementById(nav);
507 var navHeight = navObj.height();
508 var offsetTop = selected.position().top;
509 if (selected.parent().parent().is(".toggle-list")) offsetTop += selected.parent().parent().position().top;
510 if(offsetTop > navHeight - 92) {
511 scrolling.scrollTop = offsetTop - navHeight + 92;
512 }
513 }
514}
515
Dirk Dougherty4405a232009-07-07 17:43:27 -0700516function changeTabLang(lang) {
517 var nodes = $("#header-tabs").find("."+lang);
Roman Nurik78eff9f2010-03-01 18:35:13 -0800518 for (i=0; i < nodes.length; i++) { // for each node in this language
Dirk Dougherty4405a232009-07-07 17:43:27 -0700519 var node = $(nodes[i]);
Roman Nurik78eff9f2010-03-01 18:35:13 -0800520 node.siblings().css("display","none"); // hide all siblings
521 if (node.not(":empty").length != 0) { //if this languages node has a translation, show it
Dirk Dougherty4405a232009-07-07 17:43:27 -0700522 node.css("display","inline");
Roman Nurik78eff9f2010-03-01 18:35:13 -0800523 } else { //otherwise, show English instead
Dirk Dougherty4405a232009-07-07 17:43:27 -0700524 node.css("display","none");
525 node.siblings().filter(".en").css("display","inline");
526 }
527 }
528}
529
530function changeNavLang(lang) {
531 var nodes = $("#side-nav").find("."+lang);
Roman Nurik78eff9f2010-03-01 18:35:13 -0800532 for (i=0; i < nodes.length; i++) { // for each node in this language
Dirk Dougherty4405a232009-07-07 17:43:27 -0700533 var node = $(nodes[i]);
Roman Nurik78eff9f2010-03-01 18:35:13 -0800534 node.siblings().css("display","none"); // hide all siblings
535 if (node.not(":empty").length != 0) { // if this languages node has a translation, show it
Dirk Dougherty4405a232009-07-07 17:43:27 -0700536 node.css("display","inline");
Roman Nurik78eff9f2010-03-01 18:35:13 -0800537 } else { // otherwise, show English instead
Dirk Dougherty4405a232009-07-07 17:43:27 -0700538 node.css("display","none");
539 node.siblings().filter(".en").css("display","inline");
540 }
541 }
542}
543
544function changeDocLang(lang) {
545 changeTabLang(lang);
546 changeNavLang(lang);
547}
548
549function changeLangPref(lang, refresh) {
550 var date = new Date();
551 expires = date.toGMTString(date.setTime(date.getTime()+(10*365*24*60*60*1000))); // keep this for 50 years
552 //alert("expires: " + expires)
553 writeCookie("pref_lang", lang, null, expires);
554 //changeDocLang(lang);
555 if (refresh) {
556 l = getBaseUri(location.pathname);
557 window.location = l;
558 }
559}
560
561function loadLangPref() {
562 var lang = readCookie("pref_lang");
563 if (lang != 0) {
564 $("#language").find("option[value='"+lang+"']").attr("selected",true);
565 }
566}
567
568function getLangPref() {
Dirk Doughertyefdcda42009-07-15 16:41:48 -0700569 var lang = $("#language").find(":selected").attr("value");
570 if (!lang) {
571 lang = readCookie("pref_lang");
572 }
573 return (lang != 0) ? lang : 'en';
Dirk Dougherty4405a232009-07-07 17:43:27 -0700574}
Scott Main462cc372009-10-23 16:19:37 -0700575
576
577function toggleContent(obj) {
578 var button = $(obj);
579 var div = $(obj.parentNode);
580 var toggleMe = $(".toggle-content-toggleme",div);
581 if (button.hasClass("show")) {
582 toggleMe.slideDown();
583 button.removeClass("show").addClass("hide");
584 } else {
585 toggleMe.slideUp();
586 button.removeClass("hide").addClass("show");
587 }
588 $("span", button).toggle();
589}