bump 1.4.0
This commit is contained in:
parent
b287f57c86
commit
3069ad3928
4 changed files with 75 additions and 55 deletions
122
lib/docsify.js
122
lib/docsify.js
|
|
@ -130,7 +130,10 @@ function scrollActiveSidebar () {
|
||||||
var li = lis[i];
|
var li = lis[i];
|
||||||
var href = li.querySelector('a').getAttribute('href');
|
var href = li.querySelector('a').getAttribute('href');
|
||||||
|
|
||||||
if (href !== '/') { href = href.match(/#([^#]+)$/g)[0].slice(1); }
|
if (href !== '/') {
|
||||||
|
var match = href.match('#([^#]+)$');
|
||||||
|
if (match && match.length) { href = match[0].slice(1); }
|
||||||
|
}
|
||||||
|
|
||||||
nav[decodeURIComponent(href)] = li;
|
nav[decodeURIComponent(href)] = li;
|
||||||
}
|
}
|
||||||
|
|
@ -174,19 +177,23 @@ function activeLink (dom, activeParent) {
|
||||||
var host = window.location.href;
|
var host = window.location.href;
|
||||||
|
|
||||||
dom = typeof dom === 'object' ? dom : document.querySelector(dom);
|
dom = typeof dom === 'object' ? dom : document.querySelector(dom);
|
||||||
if (!dom) { return
|
if (!dom) { return }
|
||||||
|
var target;[].slice.call(dom.querySelectorAll('a'))
|
||||||
|
.sort(function (a, b) { return b.href.length - a.href.length; })
|
||||||
|
.forEach(function (node) {
|
||||||
|
if (host.indexOf(node.href) === 0 && !target) {
|
||||||
|
activeParent
|
||||||
|
? node.parentNode.setAttribute('class', 'active')
|
||||||
|
: node.setAttribute('class', 'active');
|
||||||
|
target = node;
|
||||||
|
} else {
|
||||||
|
activeParent
|
||||||
|
? node.parentNode.removeAttribute('class')
|
||||||
|
: node.removeAttribute('class');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
; }[].slice.call(dom.querySelectorAll('a')).forEach(function (node) {
|
return target
|
||||||
if (node.href === host) {
|
|
||||||
activeParent
|
|
||||||
? node.parentNode.setAttribute('class', 'active')
|
|
||||||
: node.setAttribute('class', 'active');
|
|
||||||
} else {
|
|
||||||
activeParent
|
|
||||||
? node.parentNode.removeAttribute('class')
|
|
||||||
: node.removeAttribute('class');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -2348,7 +2355,7 @@ function cover () {
|
||||||
var SL = ', 100%, 85%';
|
var SL = ', 100%, 85%';
|
||||||
var bgc = "linear-gradient(to left bottom, hsl(" + (Math.floor(Math.random() * 255) + SL) + ") 0%, hsl(" + (Math.floor(Math.random() * 255) + SL) + ") 100%)";
|
var bgc = "linear-gradient(to left bottom, hsl(" + (Math.floor(Math.random() * 255) + SL) + ") 0%, hsl(" + (Math.floor(Math.random() * 255) + SL) + ") 100%)";
|
||||||
|
|
||||||
return ("<section class=\"cover\" style=\"background: " + bgc + "\">\n <div class=\"cover-main\"></div>\n </section>")
|
return ("<section class=\"cover\" style=\"background: " + bgc + "\">\n <div class=\"cover-main\"></div>\n <div class=\"mask\"></div>\n </section>")
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggle () {
|
function toggle () {
|
||||||
|
|
@ -2452,12 +2459,12 @@ function renderApp (dom, replace) {
|
||||||
*/
|
*/
|
||||||
function renderArticle (content) {
|
function renderArticle (content) {
|
||||||
renderTo('article', content ? marked(content) : 'not found');
|
renderTo('article', content ? marked(content) : 'not found');
|
||||||
if (!renderSidebar.rendered) { renderSidebar(null, OPTIONS$1); }
|
if (!OPTIONS$1.sidebar && !OPTIONS$1.loadSidebar) { renderSidebar(); }
|
||||||
if (!renderNavbar.rendered) { renderNavbar(null, OPTIONS$1); }
|
|
||||||
renderSidebar.rendered = false;
|
|
||||||
renderNavbar.rendered = false;
|
|
||||||
|
|
||||||
if (content && typeof Vue !== 'undefined' && typeof Vuep !== 'undefined') { new Vue({ el: 'main' }); } // eslint-disable-line
|
if (content && typeof Vue !== 'undefined' && typeof Vuep !== 'undefined') {
|
||||||
|
var vm = new Vue({ el: 'main' }); // eslint-disable-line
|
||||||
|
vm.$nextTick(function (_) { return scrollActiveSidebar(); });
|
||||||
|
}
|
||||||
if (OPTIONS$1.auto2top) { scroll2Top(); }
|
if (OPTIONS$1.auto2top) { scroll2Top(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2467,7 +2474,6 @@ function renderArticle (content) {
|
||||||
function renderNavbar (content) {
|
function renderNavbar (content) {
|
||||||
if (CACHE.navbar && CACHE.navbar === content) { return }
|
if (CACHE.navbar && CACHE.navbar === content) { return }
|
||||||
CACHE.navbar = content;
|
CACHE.navbar = content;
|
||||||
renderNavbar.rendered = true;
|
|
||||||
|
|
||||||
if (content) { renderTo('nav', marked(content)); }
|
if (content) { renderTo('nav', marked(content)); }
|
||||||
activeLink('nav');
|
activeLink('nav');
|
||||||
|
|
@ -2477,23 +2483,27 @@ function renderNavbar (content) {
|
||||||
* sidebar
|
* sidebar
|
||||||
*/
|
*/
|
||||||
function renderSidebar (content) {
|
function renderSidebar (content) {
|
||||||
var isToc = false;
|
var html;
|
||||||
|
|
||||||
if (content) {
|
if (content) {
|
||||||
content = marked(content);
|
html = marked(content);
|
||||||
} else if (OPTIONS$1.sidebar) {
|
} else if (OPTIONS$1.sidebar) {
|
||||||
content = tree(OPTIONS$1.sidebar, '<ul>');
|
html = tree(OPTIONS$1.sidebar, '<ul>');
|
||||||
} else {
|
} else {
|
||||||
content = tree(genTree(toc, OPTIONS$1.maxLevel), '<ul>');
|
html = tree(genTree(toc, OPTIONS$1.maxLevel), '<ul>');
|
||||||
isToc = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
renderSidebar.rendered = true;
|
renderTo('aside.sidebar', html);
|
||||||
if (CACHE.sidebar && CACHE.sidebar === content) { return }
|
var target = activeLink('aside.sidebar', true);
|
||||||
CACHE.sidebar = content;
|
if (content) { renderSubSidebar(target); }
|
||||||
renderTo('aside.sidebar', content);
|
|
||||||
if (isToc) { scrollActiveSidebar(); }
|
|
||||||
toc = [];
|
toc = [];
|
||||||
|
|
||||||
|
scrollActiveSidebar();
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderSubSidebar (target) {
|
||||||
|
if (!OPTIONS$1.subMaxLevel) { return }
|
||||||
|
target.parentNode.innerHTML += tree(genTree(toc, OPTIONS$1.subMaxLevel), '<ul>');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -2502,12 +2512,31 @@ function renderSidebar (content) {
|
||||||
function renderCover (content) {
|
function renderCover (content) {
|
||||||
renderCover.dom = renderCover.dom || document.querySelector('section.cover');
|
renderCover.dom = renderCover.dom || document.querySelector('section.cover');
|
||||||
if (!content) {
|
if (!content) {
|
||||||
renderCover.dom.classList.add('hidden');
|
renderCover.dom.classList.remove('show');
|
||||||
} else {
|
return
|
||||||
renderCover.dom.classList.remove('hidden');
|
|
||||||
!renderCover.rendered && renderTo('.cover-main', marked(content));
|
|
||||||
renderCover.rendered = true;
|
|
||||||
}
|
}
|
||||||
|
renderCover.dom.classList.add('show');
|
||||||
|
if (renderCover.rendered) { return }
|
||||||
|
|
||||||
|
// render cover
|
||||||
|
var html = marked(content);
|
||||||
|
var match = html.trim().match('<p><img[^s]+src="(.*?)"[^a]+alt="(.*?)"></p>$');
|
||||||
|
|
||||||
|
// render background
|
||||||
|
if (match) {
|
||||||
|
var coverEl = document.querySelector('section.cover');
|
||||||
|
|
||||||
|
if (match[2] === 'color') {
|
||||||
|
coverEl.style.background = match[1];
|
||||||
|
} else {
|
||||||
|
coverEl.classList.add('has-mask');
|
||||||
|
coverEl.style.backgroundImage = "url(" + (match[1]) + ")";
|
||||||
|
}
|
||||||
|
html = html.replace(match[0], '');
|
||||||
|
}
|
||||||
|
|
||||||
|
renderTo('.cover-main', html);
|
||||||
|
renderCover.rendered = true;
|
||||||
|
|
||||||
sticky();
|
sticky();
|
||||||
}
|
}
|
||||||
|
|
@ -2561,6 +2590,7 @@ var OPTIONS = {
|
||||||
el: '#app',
|
el: '#app',
|
||||||
repo: '',
|
repo: '',
|
||||||
maxLevel: 6,
|
maxLevel: 6,
|
||||||
|
subMaxLevel: 0,
|
||||||
sidebar: '',
|
sidebar: '',
|
||||||
sidebarToggle: false,
|
sidebarToggle: false,
|
||||||
loadSidebar: null,
|
loadSidebar: null,
|
||||||
|
|
@ -2595,7 +2625,6 @@ var mainRender = function (cb) {
|
||||||
var route = OPTIONS.basePath + getRoute();
|
var route = OPTIONS.basePath + getRoute();
|
||||||
if (cacheRoute === route) { return cb() }
|
if (cacheRoute === route) { return cb() }
|
||||||
|
|
||||||
var wait;
|
|
||||||
var basePath = cacheRoute = route;
|
var basePath = cacheRoute = route;
|
||||||
|
|
||||||
if (!/\//.test(basePath)) {
|
if (!/\//.test(basePath)) {
|
||||||
|
|
@ -2627,22 +2656,16 @@ var mainRender = function (cb) {
|
||||||
if (OPTIONS.coverpage && page !== OPTIONS.homepage) { renderCover(); }
|
if (OPTIONS.coverpage && page !== OPTIONS.homepage) { renderCover(); }
|
||||||
// render sidebar
|
// render sidebar
|
||||||
if (OPTIONS.loadSidebar) {
|
if (OPTIONS.loadSidebar) {
|
||||||
if (wait === false) { cb(); }
|
load(basePath + OPTIONS.loadSidebar)
|
||||||
wait = false;
|
.then(function (result) {
|
||||||
|
renderSidebar(result);
|
||||||
|
cb();
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
cb();
|
cb();
|
||||||
}
|
}
|
||||||
}, function (_) { return renderArticle(null); });
|
}, function (_) { return renderArticle(null); });
|
||||||
|
|
||||||
// Render sidebar
|
|
||||||
if (OPTIONS.loadSidebar) {
|
|
||||||
load(basePath + OPTIONS.loadSidebar).then(function (result) {
|
|
||||||
renderSidebar(result);
|
|
||||||
if (wait === false) { cb(); }
|
|
||||||
wait = false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render navbar
|
// Render navbar
|
||||||
if (OPTIONS.loadNavbar) {
|
if (OPTIONS.loadNavbar) {
|
||||||
load(basePath + OPTIONS.loadNavbar).then(renderNavbar);
|
load(basePath + OPTIONS.loadNavbar).then(renderNavbar);
|
||||||
|
|
@ -2653,10 +2676,7 @@ var Docsify = function () {
|
||||||
var dom = document.querySelector(OPTIONS.el) || document.body;
|
var dom = document.querySelector(OPTIONS.el) || document.body;
|
||||||
var replace = dom !== document.body;
|
var replace = dom !== document.body;
|
||||||
var main = function () {
|
var main = function () {
|
||||||
mainRender(function (_) {
|
mainRender(function (_) { return scrollIntoView(); });
|
||||||
activeLink('aside.sidebar', true);
|
|
||||||
scrollIntoView();
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Render app
|
// Render app
|
||||||
|
|
|
||||||
4
lib/docsify.min.js
vendored
4
lib/docsify.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue