[Doc] optimzie demo display (#626)

This commit is contained in:
neverland
2018-02-08 15:58:27 +08:00
committed by GitHub
parent 6ed43f8c75
commit 267390212b
10 changed files with 139 additions and 55 deletions

View File

@@ -10,19 +10,21 @@ window.syncPath = function(dir) {
const router = window.vueRouter;
const isInIframe = window !== window.top;
const currentDir = router.history.current.path;
const iframe = document.querySelector('iframe');
const pathParts = currentDir.split('/');
let lang = pathParts[0];
if (currentDir[0] === '/') {
lang = pathParts[1];
}
if (!isInIframe && !isMobile && iframe) {
const pathParts = currentDir.split('/');
let lang = pathParts[0];
if (currentDir[0] === '/') {
lang = pathParts[1];
if (!isInIframe && !isMobile) {
const iframe = document.querySelector('iframe');
if (iframe) {
iframeReady(iframe, () => {
iframe.contentWindow.changePath(lang, currentDir);
});
}
setLang(lang);
iframeReady(iframe, () => {
iframe.contentWindow.changePath(lang, currentDir);
});
} else if (isInIframe) {
window.top.changePath(lang, currentDir);
}
};

View File

@@ -12,6 +12,7 @@ const langMap = {
messages: zhCN
}
};
let currentLang = '';
setLang(getDefaultLang());
@@ -30,6 +31,11 @@ function getDefaultLang() {
}
export function setLang(lang) {
if (currentLang === lang) {
return;
}
currentLang = lang;
if (window.localStorage) {
localStorage.setItem('VANT_LANGUAGE', lang);
}