* [doc] Fix website bug.
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/c55b9dfd Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/c55b9dfd Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/c55b9dfd Branch: refs/heads/master Commit: c55b9dfd3fafbd6a9a176654f09bcb45652cb7cc Parents: 46e1b28 Author: Yun Dong <[email protected]> Authored: Thu Feb 23 15:19:53 2017 +0800 Committer: Yun Dong <[email protected]> Committed: Thu Feb 23 15:19:53 2017 +0800 ---------------------------------------------------------------------- doc/themes/weex/layout/_partial/head.ejs | 32 ++++++++++++++++++++++----- doc/themes/weex/source/js/common.js | 4 ++-- 2 files changed, 28 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/c55b9dfd/doc/themes/weex/layout/_partial/head.ejs ---------------------------------------------------------------------- diff --git a/doc/themes/weex/layout/_partial/head.ejs b/doc/themes/weex/layout/_partial/head.ejs index 259979d..f3d428c 100644 --- a/doc/themes/weex/layout/_partial/head.ejs +++ b/doc/themes/weex/layout/_partial/head.ejs @@ -32,16 +32,36 @@ currentLang = navigator.browserLanguage; } - if (window.localStorage) { - selectedLang = window.localStorage.getItem('lang') + if (window.sessionStorage) { + selectedLang = window.sessionStorage.getItem('lang') } - if (currentLang.indexOf('zh') >= 0 - && currentPathname.indexOf('/cn/') != 0 - && !selectedLang) { - location.href = currentOrigin + '/cn' + currentPathname; + if (!selectedLang) { + if (currentLang.indexOf('zh') >= 0 && currentPathname.indexOf('/cn/') != 0) { + location.href = getUrl('cn', currentOrigin, currentPathname); + } else if (currentLang.indexOf('en') >= 0 && currentPathname.indexOf('/cn/') == 0) { + location.href = getUrl('en', currentOrigin, currentPathname); + } } + function getUrl (lang, origin, path) { + if (lang == 'en') { + if (path.indexOf('/cn/') == 0) { + return origin + path.substr(3) + } else { + return origin + path + } + } else { + var langPath = '/' + lang + '/' + var pathStart = path.indexOf(langPath) + + if (pathStart == 0) { + return origin + path + } else { + return origin + langPath + path.substr(1) + } + } + } })(); </script> <%- open_graph({twitter_id: theme.twitter, google_plus: theme.google_plus, fb_admins: theme.fb_admins, fb_app_id: theme.fb_app_id}) %> http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/c55b9dfd/doc/themes/weex/source/js/common.js ---------------------------------------------------------------------- diff --git a/doc/themes/weex/source/js/common.js b/doc/themes/weex/source/js/common.js index 12a569f..1eddfc6 100644 --- a/doc/themes/weex/source/js/common.js +++ b/doc/themes/weex/source/js/common.js @@ -87,8 +87,8 @@ if (pick.contains(target)) { var lang = target.getAttribute('data-lang') - if (window.localStorage) { - window.localStorage.setItem('lang', lang) + if (window.sessionStorage) { + window.sessionStorage.setItem('lang', lang) } location.href = target.href
