[improvement] rename docs/src to docs/site (#3660)

This commit is contained in:
neverland
2019-06-27 11:37:44 +08:00
committed by GitHub
parent 75c79b7044
commit 425ba7ecf7
17 changed files with 6 additions and 6 deletions
+18
View File
@@ -0,0 +1,18 @@
// component mixin
import { get } from '../../../src/utils';
import { camelize } from '../../../src/utils/format/string';
export default {
computed: {
$t() {
const { name } = this.$options;
const prefix = name ? camelize(name) + '.' : '';
const messages = this.$vantMessages[this.$vantLang];
return (path, ...args) => {
const message = get(messages, prefix + path) || get(messages, path);
return typeof message === 'function' ? message(...args) : message;
};
}
}
};
+36
View File
@@ -0,0 +1,36 @@
/**
* 同步父窗口和 iframe 的 vue-router 状态
*/
import { setLang } from './lang';
import { iframeReady, isMobile } from '.';
export function initIframeRouter() {
window.syncPath = function () {
const router = window.vueRouter;
const isInIframe = window !== window.top;
const currentDir = router.history.current.path;
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);
} else if (isInIframe) {
window.top.changePath(lang, currentDir);
}
};
window.changePath = function (lang, path = '') {
setLang(lang);
window.vueRouter.replace(path);
};
}
+33
View File
@@ -0,0 +1,33 @@
function iframeReady(iframe, callback) {
const doc = iframe.contentDocument || iframe.contentWindow.document;
const interval = () => {
if (iframe.contentWindow.changePath) {
callback();
} else {
setTimeout(() => {
interval();
}, 50);
}
};
if (doc.readyState === 'complete') {
interval();
} else {
iframe.onload = interval;
}
}
const ua = navigator.userAgent.toLowerCase();
const isMobile = /ios|iphone|ipod|ipad|android/.test(ua);
function importAll(map, r) {
r.keys().forEach(key => {
map[key] = r(key);
});
}
export {
isMobile,
importAll,
iframeReady
};
+45
View File
@@ -0,0 +1,45 @@
import Locale from '../../../src/locale';
import zhCN from '../../../src/locale/lang/zh-CN';
import enUS from '../../../src/locale/lang/en-US';
const langMap = {
'en-US': {
title: 'Vant - Mobile UI Components built on Vue',
messages: enUS
},
'zh-CN': {
title: 'Vant - 轻量、可靠的移动端 Vue 组件库',
messages: zhCN
}
};
let currentLang = '';
function getDefaultLang() {
const langs = Object.keys(langMap);
const { hash } = location;
for (let i = 0; i < langs.length; i++) {
if (hash.indexOf(langs[i]) !== -1) {
return langs[i];
}
}
const userLang = localStorage.getItem('VANT_LANGUAGE') || navigator.language || 'en-US';
return userLang.indexOf('zh-') !== -1 ? 'zh-CN' : 'en-US';
}
export function setLang(lang) {
if (currentLang === lang) {
return;
}
currentLang = lang;
if (window.localStorage) {
localStorage.setItem('VANT_LANGUAGE', lang);
}
Locale.use(lang, langMap[lang].messages);
document.title = langMap[lang].title;
}
setLang(getDefaultLang());