From 015d616af8cf72cf609b19257604e520a70c3286 Mon Sep 17 00:00:00 2001 From: Scott Main Date: Tue, 29 Jan 2013 09:01:52 -0800 Subject: [PATCH] docs: use devsite hdf bool as a javascript condition for managing the lang toggle. sync the sdk and ds templates so we can move toward one template set Change-Id: I5316d4cd085734a47953beba203ba8beeb64549e --- tools/droiddoc/templates-ds/assets/js/docs.js | 22 ++++- tools/droiddoc/templates-ds/customizations.cs | 7 +- tools/droiddoc/templates-ds/head_tag.cs | 5 ++ .../droiddoc/templates-sdk/assets/js/docs.js | 81 ++++++++++++------- .../droiddoc/templates-sdk/customizations.cs | 7 +- tools/droiddoc/templates-sdk/head_tag.cs | 5 ++ 6 files changed, 80 insertions(+), 47 deletions(-) diff --git a/tools/droiddoc/templates-ds/assets/js/docs.js b/tools/droiddoc/templates-ds/assets/js/docs.js index a7440c7cfa..557a242cd3 100644 --- a/tools/droiddoc/templates-ds/assets/js/docs.js +++ b/tools/droiddoc/templates-ds/assets/js/docs.js @@ -15,8 +15,10 @@ var SITE_ROOT = toRoot + basePath.substring(1,basePath.indexOf("/",1)); var navBarIsFixed = false; $(document).ready(function() { - // move the lang selector into the overflow menu - $("#moremenu .mid div.header:last").after($("#language").detach()); + if (devsite) { + // move the lang selector into the overflow menu + $("#moremenu .mid div.header:last").after($("#language").detach()); + } // init the fullscreen toggle click event $('#nav-swap .fullscreen').click(function(){ @@ -1051,8 +1053,20 @@ function changeLangPref(lang, submit) { // keep this for 50 years //alert("expires: " + expires) writeCookie("pref_lang", lang, null, expires); - if (submit) { - $("#setlang").submit(); + + // ####### TODO: Remove this condition once we're stable on devsite ####### + // This condition is only needed if we still need to support legacy GAE server + if (devsite) { + // Switch language when on Devsite server + if (submit) { + $("#setlang").submit(); + } + } else { + // Switch language when on legacy GAE server + changeDocLang(lang); + if (submit) { + window.location = getBaseUri(location.pathname); + } } } diff --git a/tools/droiddoc/templates-ds/customizations.cs b/tools/droiddoc/templates-ds/customizations.cs index 342dd49650..75559e68ed 100644 --- a/tools/droiddoc/templates-ds/customizations.cs +++ b/tools/droiddoc/templates-ds/customizations.cs @@ -330,12 +330,7 @@ def:custom_left_nav() ?> - diff --git a/tools/droiddoc/templates-sdk/assets/js/docs.js b/tools/droiddoc/templates-sdk/assets/js/docs.js index 43bcb8f84b..557a242cd3 100644 --- a/tools/droiddoc/templates-sdk/assets/js/docs.js +++ b/tools/droiddoc/templates-sdk/assets/js/docs.js @@ -15,6 +15,11 @@ var SITE_ROOT = toRoot + basePath.substring(1,basePath.indexOf("/",1)); var navBarIsFixed = false; $(document).ready(function() { + if (devsite) { + // move the lang selector into the overflow menu + $("#moremenu .mid div.header:last").after($("#language").detach()); + } + // init the fullscreen toggle click event $('#nav-swap .fullscreen').click(function(){ if ($(this).hasClass('disabled')) { @@ -489,6 +494,36 @@ false; // navigate across topic boundaries only in design docs resizeNav(); + /* init the language selector based on user cookie for lang */ + loadLangPref(); + changeNavLang(getLangPref()); + + /* setup event handlers to ensure the overflow menu is visible while picking lang */ + $("#language select") + .mousedown(function() { + $("div.morehover").addClass("hover"); }) + .blur(function() { + $("div.morehover").removeClass("hover"); }); + + /* some global variable setup */ + resizePackagesNav = $("#resize-packages-nav"); + classesNav = $("#classes-nav"); + devdocNav = $("#devdoc-nav"); + + var cookiePath = ""; + if (location.href.indexOf("/reference/") != -1) { + cookiePath = "reference_"; + } else if (location.href.indexOf("/guide/") != -1) { + cookiePath = "guide_"; + } else if (location.href.indexOf("/tools/") != -1) { + cookiePath = "tools_"; + } else if (location.href.indexOf("/training/") != -1) { + cookiePath = "training_"; + } else if (location.href.indexOf("/design/") != -1) { + cookiePath = "design_"; + } else if (location.href.indexOf("/distribute/") != -1) { + cookiePath = "distribute_"; + } }); @@ -576,28 +611,6 @@ addLoadEvent( function() { prettyPrint(); } ); -function init() { - //resizeNav(); - - resizePackagesNav = $("#resize-packages-nav"); - classesNav = $("#classes-nav"); - devdocNav = $("#devdoc-nav"); - - var cookiePath = ""; - if (location.href.indexOf("/reference/") != -1) { - cookiePath = "reference_"; - } else if (location.href.indexOf("/guide/") != -1) { - cookiePath = "guide_"; - } else if (location.href.indexOf("/tools/") != -1) { - cookiePath = "tools_"; - } else if (location.href.indexOf("/training/") != -1) { - cookiePath = "training_"; - } else if (location.href.indexOf("/design/") != -1) { - cookiePath = "design_"; - } else if (location.href.indexOf("/distribute/") != -1) { - cookiePath = "distribute_"; - } -} @@ -1034,20 +1047,26 @@ function changeNavLang(lang) { }); } -function changeDocLang(lang) { - changeNavLang(lang); -} - -function changeLangPref(lang, refresh) { +function changeLangPref(lang, submit) { var date = new Date(); expires = date.toGMTString(date.setTime(date.getTime()+(10*365*24*60*60*1000))); // keep this for 50 years //alert("expires: " + expires) writeCookie("pref_lang", lang, null, expires); - changeDocLang(lang); - if (refresh) { - l = getBaseUri(location.pathname); - window.location = l; + + // ####### TODO: Remove this condition once we're stable on devsite ####### + // This condition is only needed if we still need to support legacy GAE server + if (devsite) { + // Switch language when on Devsite server + if (submit) { + $("#setlang").submit(); + } + } else { + // Switch language when on legacy GAE server + changeDocLang(lang); + if (submit) { + window.location = getBaseUri(location.pathname); + } } } diff --git a/tools/droiddoc/templates-sdk/customizations.cs b/tools/droiddoc/templates-sdk/customizations.cs index a45e4bac3c..6aa8f4f01e 100644 --- a/tools/droiddoc/templates-sdk/customizations.cs +++ b/tools/droiddoc/templates-sdk/customizations.cs @@ -330,12 +330,7 @@ def:custom_left_nav() ?> -