blob: 1099e6e0401a6cbd098b742c09d38b905c9e827d [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
Scott Maind8115ff2009-11-03 18:54:26 -080030if ((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 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() {
67 $("pre").addClass("prettyprint");
68 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=/";
The Android Open Source Project88b60792009-03-03 19:28:42 -0800129}
130
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
165 if (devdocNav.length) { // only dev guide and sdk
166 highlightNav(location.href);
167 }
168}
169
170function highlightNav(fullPageName) {
171 var lastSlashPos = fullPageName.lastIndexOf("/");
Dirk Dougherty502c4982009-12-02 18:01:16 -0800172 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 Project88b60792009-03-03 19:28:42 -0800180 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 Doughertyf32c5ac2009-12-15 18:48:38 -0800186 if ((link.length == 0) && ((fullPageName.indexOf("/guide/") != -1) || (fullPageName.indexOf("/resources/") != -1))) {
Scott Main0d8872e2009-10-23 13:04:31 -0700187// 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 Project88b60792009-03-03 19:28:42 -0800188 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 Main3f7d1df2009-11-02 15:31:04 -0800204/* Resize the height of the nav panels in the reference,
205 * and save the new size to a cookie */
206function resizePackagesHeight() {
The Android Open Source Project88b60792009-03-03 19:28:42 -0800207 var windowHeight = ($(window).height() - HEADER_HEIGHT);
Scott Main3f7d1df2009-11-02 15:31:04 -0800208 var swapperHeight = windowHeight - 13; // move 13px for swapper link at the bottom
The Android Open Source Project88b60792009-03-03 19:28:42 -0800209 resizePackagesNav.css({maxHeight:swapperHeight + "px"});
210 classesNav.css({height:swapperHeight - parseInt(resizePackagesNav.css("height")) + "px"});
Scott Main3f7d1df2009-11-02 15:31:04 -0800211
212 $("#swapper").css({height:swapperHeight + "px"});
The Android Open Source Project88b60792009-03-03 19:28:42 -0800213 $("#packages-nav").css({height:parseInt(resizePackagesNav.css("height")) - 6 + "px"}); //move 6px for handle
Scott Main3f7d1df2009-11-02 15:31:04 -0800214
Dirk Doughertyc13d0452009-07-08 14:39:31 -0700215 var basePath = getBaseUri(location.pathname);
216 var section = basePath.substring(1,basePath.indexOf("/",1));
Dirk Dougherty4405a232009-07-07 17:43:27 -0700217 writeCookie("height", resizePackagesNav.css("height"), section, null);
The Android Open Source Project88b60792009-03-03 19:28:42 -0800218}
219
Scott Main3f7d1df2009-11-02 15:31:04 -0800220/* Resize the height of the side-nav and doc-content divs,
221 * which creates the frame effect */
222function resizeHeight() {
Scott Main13b79b22010-01-12 13:37:00 -0800223 var docContent = $("#doc-content");
224
Scott Main3f7d1df2009-11-02 15:31:04 -0800225 // Get the window height and always resize the doc-content and side-nav divs
226 var windowHeight = ($(window).height() - HEADER_HEIGHT);
Scott Main13b79b22010-01-12 13:37:00 -0800227 docContent.css({height:windowHeight + "px"});
228 $("#side-nav").css({height:windowHeight + "px"});
Scott Main3f7d1df2009-11-02 15:31:04 -0800229
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 Dougherty502c4982009-12-02 18:01:16 -0800241 } else if (href.indexOf("/resources/") != -1) {
242 $("#devdoc-nav").css({height:sidenav.css("height")});
Scott Main3f7d1df2009-11-02 15:31:04 -0800243 }
Scott Main13b79b22010-01-12 13:37:00 -0800244
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 Main3f7d1df2009-11-02 15:31:04 -0800251}
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 Project88b60792009-03-03 19:28:42 -0800255function 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 Main3f7d1df2009-11-02 15:31:04 -0800262 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 Project88b60792009-03-03 19:28:42 -0800268 resizePackagesNav.css({width:sidenavWidth});
269 classesNav.css({width:sidenavWidth});
270 $("#packages-nav").css({width:sidenavWidth});
Scott Main3f7d1df2009-11-02 15:31:04 -0800271
Scott Mainb6da4802010-01-06 14:18:02 -0800272 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 Project88b60792009-03-03 19:28:42 -0800277}
278
Scott Main3f7d1df2009-11-02 15:31:04 -0800279/* 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 Project88b60792009-03-03 19:28:42 -0800282function resizeAll() {
Scott Main3f7d1df2009-11-02 15:31:04 -0800283 resizeHeight();
Scott Mainb6da4802010-01-06 14:18:02 -0800284 resizeWidth();
The Android Open Source Project88b60792009-03-03 19:28:42 -0800285}
286
Dirk Dougherty4405a232009-07-07 17:43:27 -0700287function getBaseUri(uri) {
Dirk Doughertyefdcda42009-07-15 16:41:48 -0700288 var intlUrl = (uri.substring(0,6) == "/intl/");
Dirk Dougherty4405a232009-07-07 17:43:27 -0700289 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 Doughertyefdcda42009-07-15 16:41:48 -0700300function 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 Project88b60792009-03-03 19:28:42 -0800313function loadLast(cookiePath) {
314 var location = window.location.href;
315 if (location.indexOf("/"+cookiePath+"/") != -1) {
316 return true;
317 }
Dirk Dougherty4405a232009-07-07 17:43:27 -0700318 var lastPage = readCookie(cookiePath + "_lastpage");
The Android Open Source Project88b60792009-03-03 19:28:42 -0800319 if (lastPage) {
320 window.location = lastPage;
321 return false;
322 }
323 return true;
324}
325
326$(window).unload(function(){
Dirk Dougherty4405a232009-07-07 17:43:27 -0700327 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 Dougherty502c4982009-12-02 18:01:16 -0800332 } else if (path.indexOf("/resources/") != -1) {
333 writeCookie("lastpage", path, "resources", null);
The Android Open Source Project88b60792009-03-03 19:28:42 -0800334 }
335});
336
The Android Open Source Project88b60792009-03-03 19:28:42 -0800337function 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 Project88b60792009-03-03 19:28:42 -0800357function 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
365function getNavPref() {
Dirk Dougherty4405a232009-07-07 17:43:27 -0700366 var v = readCookie('reference_nav');
The Android Open Source Project88b60792009-03-03 19:28:42 -0800367 if (v != NAV_PREF_TREE) {
368 v = NAV_PREF_PANELS;
369 }
370 return v;
371}
372
373function 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
383function swapNav() {
384 if (nav_pref == NAV_PREF_TREE) {
385 nav_pref = NAV_PREF_PANELS;
386 } else {
387 nav_pref = NAV_PREF_TREE;
Dirk Dougherty3b1ee372009-07-29 12:25:44 -0700388 init_default_navtree(toRoot);
The Android Open Source Project88b60792009-03-03 19:28:42 -0800389 }
390 var date = new Date();
391 date.setTime(date.getTime()+(10*365*24*60*60*1000)); // keep this for 10 years
Dirk Dougherty4405a232009-07-07 17:43:27 -0700392 writeCookie("nav", nav_pref, "reference", date.toGMTString());
The Android Open Source Project88b60792009-03-03 19:28:42 -0800393
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
406function 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
423function 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
441function 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 Dougherty4405a232009-07-07 17:43:27 -0700458
459
460function 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
474function 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
488function changeDocLang(lang) {
489 changeTabLang(lang);
490 changeNavLang(lang);
491}
492
493function 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
505function loadLangPref() {
506 var lang = readCookie("pref_lang");
507 if (lang != 0) {
508 $("#language").find("option[value='"+lang+"']").attr("selected",true);
509 }
510}
511
512function getLangPref() {
Dirk Doughertyefdcda42009-07-15 16:41:48 -0700513 var lang = $("#language").find(":selected").attr("value");
514 if (!lang) {
515 lang = readCookie("pref_lang");
516 }
517 return (lang != 0) ? lang : 'en';
Dirk Dougherty4405a232009-07-07 17:43:27 -0700518}
Scott Main462cc372009-10-23 16:19:37 -0700519
520
521function 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}