Skip to content

Commit d45e325

Browse files
committedFeb 5, 2017
bump 2.0
1 parent f2f37ee commit d45e325

File tree

5 files changed

+64
-41
lines changed

5 files changed

+64
-41
lines changed
 

‎lib/docsify.js

+59-36
Original file line numberDiff line numberDiff line change
@@ -2447,8 +2447,8 @@ function corner (data) {
24472447
/**
24482448
* Render main content
24492449
*/
2450-
function main (tpl) {
2451-
var aside = tpl + "<aside class=\"sidebar\"></aside>";
2450+
function main () {
2451+
var aside = (toggle()) + "<aside class=\"sidebar\"></aside>";
24522452

24532453
return (isMobile() ? (aside + "<main>") : ("<main>" + aside)) +
24542454
"<section class=\"content\">\n <article class=\"markdown-section\"></article>\n </section>\n </main>"
@@ -2493,7 +2493,34 @@ function helper (className, content) {
24932493
return ("<p class=\"" + className + "\">" + (content.slice(5).trim()) + "</p>")
24942494
}
24952495

2496-
var OPTIONS$1 = {};
2496+
function theme (color) {
2497+
return ("<style>:root{--theme-color: " + color + ";}</style>")
2498+
}
2499+
2500+
function replaceVar (block) {
2501+
block.innerHTML = block.innerHTML.replace(/var\(\s*--theme-color.*?\)/g, __docsify__.themeColor);
2502+
}
2503+
2504+
function cssVars () {
2505+
// variable support
2506+
if (window.CSS && window.CSS.supports && window.CSS.supports('(--foo: red)')) { return }
2507+
2508+
var styleBlocks = document.querySelectorAll('style:not(.inserted),link');[].forEach.call(styleBlocks, function (block) {
2509+
if (block.nodeName === 'STYLE') {
2510+
replaceVar(block);
2511+
} else if (block.nodeName === 'LINK') {
2512+
load(block.getAttribute('href'))
2513+
.then(function (res) {
2514+
var style = document.createElement('style');
2515+
2516+
style.innerHTML = res;
2517+
document.head.appendChild(style);
2518+
replaceVar(style);
2519+
});
2520+
}
2521+
});
2522+
}
2523+
24972524
var markdown = marked;
24982525
var toc = [];
24992526
var CACHE = {};
@@ -2508,11 +2535,8 @@ var renderTo = function (dom, content) {
25082535

25092536
/**
25102537
* init render
2511-
* @param {Object} options
25122538
*/
2513-
function init (options) {
2514-
OPTIONS$1 = options;
2515-
2539+
function init () {
25162540
var renderer = new marked.Renderer();
25172541
/**
25182542
* render anchor tag
@@ -2522,10 +2546,7 @@ function init (options) {
25222546
var slug = slugify(text);
25232547
var route = '';
25242548

2525-
if (OPTIONS$1.router) {
2526-
route = "#/" + (getRoute());
2527-
}
2528-
2549+
route = "#/" + (getRoute());
25292550
toc.push({ level: level, slug: (route + "#" + (encodeURIComponent(slug))), title: text });
25302551

25312552
return ("<h" + level + " id=\"" + slug + "\"><a href=\"" + route + "#" + slug + "\" data-id=\"" + slug + "\" class=\"anchor\"><span>" + text + "</span></a></h" + level + ">")
@@ -2539,7 +2560,7 @@ function init (options) {
25392560
return ("<pre v-pre data-lang=\"" + lang + "\"><code class=\"lang-" + lang + "\">" + (hl.replace(/:/g, '__colon__')) + "</code></pre>")
25402561
};
25412562
renderer.link = function (href, title, text) {
2542-
if (OPTIONS$1.router && !/:/.test(href)) {
2563+
if (!/:/.test(href)) {
25432564
href = ("#/" + href).replace(/\/\//g, '/');
25442565
}
25452566

@@ -2554,11 +2575,11 @@ function init (options) {
25542575
return ("<p>" + text + "</p>")
25552576
};
25562577

2557-
if (typeof OPTIONS$1.markdown === 'function') {
2578+
if (typeof __docsify__.markdown === 'function') {
25582579
markdown.setOptions({ renderer: renderer });
2559-
markdown = OPTIONS$1.markdown.call(this, markdown);
2580+
markdown = __docsify__.markdown.call(this, markdown);
25602581
} else {
2561-
markdown.setOptions(merge({ renderer: renderer }, OPTIONS$1.markdown));
2582+
markdown.setOptions(merge({ renderer: renderer }, __docsify__.markdown));
25622583
}
25632584

25642585
var md = markdown;
@@ -2572,17 +2593,23 @@ function init (options) {
25722593
function renderApp (dom, replace) {
25732594
var nav = document.querySelector('nav') || document.createElement('nav');
25742595

2575-
if (!OPTIONS$1.repo) { nav.classList.add('no-badge'); }
2596+
if (!__docsify__.repo) { nav.classList.add('no-badge'); }
25762597

2577-
dom[replace ? 'outerHTML' : 'innerHTML'] = corner(OPTIONS$1.repo) +
2578-
(OPTIONS$1.coverpage ? cover() : '') +
2579-
main(OPTIONS$1.sidebarToggle ? toggle() : '');
2598+
dom[replace ? 'outerHTML' : 'innerHTML'] = corner(__docsify__.repo) +
2599+
(__docsify__.coverpage ? cover() : '') +
2600+
main();
25802601
document.body.insertBefore(nav, document.body.children[0]);
25812602

2603+
// theme color
2604+
if (__docsify__.themeColor) {
2605+
document.head.innerHTML += theme(__docsify__.themeColor);
2606+
cssVars();
2607+
}
2608+
25822609
// bind toggle
25832610
bindToggle('button.sidebar-toggle');
25842611
// bind sticky effect
2585-
if (OPTIONS$1.coverpage) {
2612+
if (__docsify__.coverpage) {
25862613
!isMobile() && window.addEventListener('scroll', sticky);
25872614
} else {
25882615
document.body.classList.add('sticky');
@@ -2594,7 +2621,7 @@ function renderApp (dom, replace) {
25942621
*/
25952622
function renderArticle (content) {
25962623
renderTo('article', content ? markdown(content) : 'not found');
2597-
if (!OPTIONS$1.sidebar && !OPTIONS$1.loadSidebar) { renderSidebar(); }
2624+
if (!__docsify__.loadSidebar) { renderSidebar(); }
25982625

25992626
if (content && typeof Vue !== 'undefined') {
26002627
CACHE.vm && CACHE.vm.$destroy();
@@ -2611,7 +2638,7 @@ function renderArticle (content) {
26112638
: new Vue({ el: 'main' }); // eslint-disable-line
26122639
CACHE.vm && CACHE.vm.$nextTick(function (_) { return scrollActiveSidebar(); });
26132640
}
2614-
if (OPTIONS$1.auto2top) { setTimeout(function () { return scroll2Top(OPTIONS$1.auto2top); }, 0); }
2641+
if (__docsify__.auto2top) { setTimeout(function () { return scroll2Top(__docsify__.auto2top); }, 0); }
26152642
}
26162643

26172644
/**
@@ -2635,13 +2662,11 @@ function renderSidebar (content) {
26352662
html = markdown(content);
26362663
// find url tag
26372664
html = html.match(/<ul[^>]*>([\s\S]+)<\/ul>/g)[0];
2638-
} else if (OPTIONS$1.sidebar) {
2639-
html = tree(OPTIONS$1.sidebar, '<ul>');
26402665
} else {
2641-
html = tree(genTree(toc, OPTIONS$1.maxLevel), '<ul>');
2666+
html = tree(genTree(toc, __docsify__.maxLevel), '<ul>');
26422667
}
26432668

2644-
html = (OPTIONS$1.name ? ("<h1><a href=\"" + (OPTIONS$1.nameLink) + "\">" + (OPTIONS$1.name) + "</a></h1>") : '') + html;
2669+
html = (__docsify__.name ? ("<h1><a href=\"" + (__docsify__.nameLink) + "\">" + (__docsify__.name) + "</a></h1>") : '') + html;
26452670
renderTo('aside.sidebar', html);
26462671
var target = activeLink('aside.sidebar', true);
26472672
if (target) { renderSubSidebar(target); }
@@ -2651,8 +2676,8 @@ function renderSidebar (content) {
26512676
}
26522677

26532678
function renderSubSidebar (target) {
2654-
if (!OPTIONS$1.subMaxLevel) { return }
2655-
target.parentNode.innerHTML += tree(genTree(toc, OPTIONS$1.subMaxLevel), '<ul>');
2679+
if (!__docsify__.subMaxLevel) { return }
2680+
target.parentNode.innerHTML += tree(genTree(toc, __docsify__.subMaxLevel), '<ul>');
26562681
}
26572682

26582683
/**
@@ -2735,16 +2760,14 @@ var OPTIONS = merge({
27352760
repo: '',
27362761
maxLevel: 6,
27372762
subMaxLevel: 0,
2738-
sidebar: '',
2739-
sidebarToggle: false,
27402763
loadSidebar: null,
27412764
loadNavbar: null,
2742-
router: false,
27432765
homepage: 'README.md',
27442766
coverpage: '',
27452767
basePath: '',
27462768
auto2top: false,
27472769
name: '',
2770+
themeColor: '',
27482771
nameLink: window.location.pathname
27492772
}, window.$docsify);
27502773
var script = document.currentScript || [].slice.call(document.getElementsByTagName('script')).pop();
@@ -2760,9 +2783,11 @@ if (script) {
27602783
if (OPTIONS.coverpage === true) { OPTIONS.coverpage = '_coverpage.md'; }
27612784
if (OPTIONS.repo === true) { OPTIONS.repo = ''; }
27622785
if (OPTIONS.name === true) { OPTIONS.name = ''; }
2763-
if (OPTIONS.sidebar) { OPTIONS.sidebar = window[OPTIONS.sidebar]; }
27642786
}
27652787

2788+
// utils
2789+
window.__docsify__ = OPTIONS;
2790+
27662791
// load options
27672792
init(OPTIONS);
27682793

@@ -2833,10 +2858,8 @@ var Docsify = function () {
28332858
// Render app
28342859
renderApp(dom, replace);
28352860
main();
2836-
if (OPTIONS.router) {
2837-
if (!/^#\//.test(window.location.hash)) { window.location.hash = '#/'; }
2838-
window.addEventListener('hashchange', main);
2839-
}
2861+
if (!/^#\//.test(window.location.hash)) { window.location.hash = '#/'; }
2862+
window.addEventListener('hashchange', main);
28402863
};
28412864

28422865
var index = Docsify();

‎lib/docsify.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/themes/buble.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)