mirror of https://github.com/IoTcat/docsify.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
845 B
36 lines
845 B
import * as dom from '../dom' |
|
import {get} from '../../fetch/ajax' |
|
|
|
function replaceVar(block, color) { |
|
block.innerHTML = block.innerHTML.replace( |
|
/var\(\s*--theme-color.*?\)/g, |
|
color |
|
) |
|
} |
|
|
|
export default function (color) { |
|
// Variable support |
|
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, color) |
|
} else if (block.nodeName === 'LINK') { |
|
const href = block.getAttribute('href') |
|
|
|
if (!/\.css$/.test(href)) { |
|
return |
|
} |
|
|
|
get(href).then(res => { |
|
const style = dom.create('style', res) |
|
|
|
dom.head.appendChild(style) |
|
replaceVar(style, color) |
|
}) |
|
} |
|
}) |
|
}
|
|
|