refactor(core): add router

This commit is contained in:
qingwei.li 2017-02-18 11:41:33 +08:00 • committed by cinwell.li
commit 30da0d5d46
17 changed files with 316 additions and 88 deletions

View file

@ -1,22 +1,22 @@
import { dom } from '../dom'
import * as dom from '../dom'
import { get } from '../../fetch/ajax'
function replaceVar (block, themeColor) {
function replaceVar (block, color) {
block.innerHTML = block.innerHTML
.replace(/var\(\s*--theme-color.*?\)/g, themeColor)
.replace(/var\(\s*--theme-color.*?\)/g, color)
}
export default function (themeColor) {
export default function (color) {
// Variable support
if (window.CSS
&& window.CSS.supports
&& window.CSS.supports('(--foo: red)')) return
if (window.CSS &&
window.CSS.supports &&
window.CSS.supports('(--v:red)')) return
const styleBlocks = dom.findAll('style:not(.inserted),link')
;[].forEach.call(styleBlocks, block => {
if (block.nodeName === 'STYLE') {
replaceVar(block, themeColor)
replaceVar(block, color)
} else if (block.nodeName === 'LINK') {
const href = block.getAttribute('href')
@ -26,7 +26,7 @@ export default function (themeColor) {
const style = dom.create('style', res)
dom.head.appendChild(style)
replaceVar(style, themeColor)
replaceVar(style, color)
})
}
})