mirror of
https://gitee.com/docsifyjs/docsify.git
synced 2024-12-02 20:20:30 +08:00
bump 1.3.0
This commit is contained in:
parent
50addfdac6
commit
a39eddba74
@ -1,6 +1,6 @@
|
||||
![logo](_media/icon.svg)
|
||||
|
||||
# docsify <small>1.2.0</small>
|
||||
# docsify <small>1.3.0</small>
|
||||
|
||||
> A magical documentation site generator.
|
||||
|
||||
|
@ -137,11 +137,11 @@ function scrollActiveSidebar () {
|
||||
|
||||
function highlight () {
|
||||
for (var i = 0, len = anchors.length; i < len; i += 1) {
|
||||
var node = anchors[i].parentNode;
|
||||
var node = anchors[i];
|
||||
var bcr = node.getBoundingClientRect();
|
||||
|
||||
if (bcr.top < 10 && bcr.bottom > 10) {
|
||||
var li = nav[node.id];
|
||||
var li = nav[node.getAttribute('data-id')];
|
||||
|
||||
if (!li || li === active) { return }
|
||||
if (active) { active.setAttribute('class', ''); }
|
||||
@ -154,9 +154,8 @@ function scrollActiveSidebar () {
|
||||
}
|
||||
}
|
||||
|
||||
var dom = document.querySelector('main .content');
|
||||
dom.removeEventListener('scroll', highlight);
|
||||
dom.addEventListener('scroll', highlight);
|
||||
window.removeEventListener('scroll', highlight);
|
||||
window.addEventListener('scroll', highlight);
|
||||
highlight();
|
||||
}
|
||||
|
||||
@ -215,6 +214,19 @@ function scroll2Top () {
|
||||
cacheContentDOM.scrollTop = 0;
|
||||
}
|
||||
|
||||
function sticky () {
|
||||
var dom = document.querySelector('section.cover');
|
||||
var coverHeight = dom.getBoundingClientRect().height;
|
||||
|
||||
return (function () {
|
||||
if (window.pageYOffset >= coverHeight || dom.classList.contains('hidden')) {
|
||||
document.body.classList.add('sticky');
|
||||
} else {
|
||||
document.body.classList.remove('sticky');
|
||||
}
|
||||
})()
|
||||
}
|
||||
|
||||
var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
||||
|
||||
|
||||
@ -2324,14 +2336,22 @@ function corner (data) {
|
||||
|
||||
/**
|
||||
* Render main content
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
function main () {
|
||||
return "<main>\n <aside class=\"sidebar\"></aside>\n <section class=\"content\">\n <article class=\"markdown-section\"></article>\n </section>\n </main>"
|
||||
function main (tpl) {
|
||||
return ("<main>\n " + tpl + "\n <aside class=\"sidebar\"></aside>\n <section class=\"content\">\n <article class=\"markdown-section\"></article>\n </section>\n </main>")
|
||||
}
|
||||
|
||||
function toggle (bool) {
|
||||
if (!bool) { return '' }
|
||||
/**
|
||||
* Cover Page
|
||||
*/
|
||||
function cover () {
|
||||
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%)";
|
||||
|
||||
return ("<section class=\"cover\" style=\"background: " + bgc + "\">\n <div class=\"cover-main\"></div>\n </section>")
|
||||
}
|
||||
|
||||
function toggle () {
|
||||
return "<button class=\"sidebar-toggle\">\n <span></span><span></span><span></span>\n </button>"
|
||||
}
|
||||
|
||||
@ -2384,7 +2404,7 @@ renderer.heading = function (text, level) {
|
||||
|
||||
toc.push({ level: level, slug: (route + "#" + (encodeURIComponent(slug))), title: text });
|
||||
|
||||
return ("<h" + level + " id=\"" + slug + "\"><a href=\"" + route + "#" + slug + "\" class=\"anchor\"></a>" + text + "</h" + level + ">")
|
||||
return ("<a href=\"" + route + "#" + slug + "\" data-id=\"" + slug + "\" class=\"anchor\"><h" + level + " id=\"" + slug + "\">" + text + "</h" + level + "></a>")
|
||||
};
|
||||
// highlight code
|
||||
renderer.code = function (code, lang) {
|
||||
@ -2409,11 +2429,21 @@ marked.setOptions({ renderer: renderer });
|
||||
function renderApp (dom, replace) {
|
||||
var nav = document.querySelector('nav') || document.createElement('nav');
|
||||
|
||||
dom[replace ? 'outerHTML' : 'innerHTML'] = toggle(OPTIONS$1.sidebarToggle) + corner(OPTIONS$1.repo) + main();
|
||||
if (!OPTIONS$1.repo) { nav.classList.add('no-badge'); }
|
||||
|
||||
dom[replace ? 'outerHTML' : 'innerHTML'] = corner(OPTIONS$1.repo) +
|
||||
(OPTIONS$1.coverpage ? cover() : '') +
|
||||
main(OPTIONS$1.sidebarToggle ? toggle() : '');
|
||||
document.body.insertBefore(nav, document.body.children[0]);
|
||||
|
||||
// bind toggle
|
||||
bindToggle('button.sidebar-toggle');
|
||||
// bind sticky effect
|
||||
if (OPTIONS$1.coverpage) {
|
||||
!isMobile() && window.addEventListener('scroll', sticky);
|
||||
} else {
|
||||
document.body.classList.add('sticky');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2464,6 +2494,20 @@ function renderSidebar (content) {
|
||||
toc = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Cover Page
|
||||
*/
|
||||
function renderCover (content) {
|
||||
renderCover.dom = renderCover.dom || document.querySelector('section.cover');
|
||||
if (!content) {
|
||||
renderCover.dom.classList.add('hidden');
|
||||
} else {
|
||||
renderCover.dom.classList.remove('hidden');
|
||||
!renderCover.rendered && renderTo('.cover-main', marked(content));
|
||||
renderCover.rendered = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* render loading bar
|
||||
* @return {[type]} [description]
|
||||
@ -2519,6 +2563,7 @@ var OPTIONS = {
|
||||
loadNavbar: null,
|
||||
router: false,
|
||||
homepage: 'README.md',
|
||||
coverpage: '',
|
||||
basePath: '',
|
||||
auto2top: false
|
||||
};
|
||||
@ -2532,6 +2577,7 @@ if (script) {
|
||||
}
|
||||
if (OPTIONS.loadSidebar === true) { OPTIONS.loadSidebar = '_sidebar.md'; }
|
||||
if (OPTIONS.loadNavbar === true) { OPTIONS.loadNavbar = '_navbar.md'; }
|
||||
if (OPTIONS.coverpage === true) { OPTIONS.coverpage = '_coverpage.md'; }
|
||||
if (OPTIONS.sidebar) { OPTIONS.sidebar = window[OPTIONS.sidebar]; }
|
||||
}
|
||||
|
||||
@ -2563,6 +2609,15 @@ var mainRender = function (cb) {
|
||||
page = route + ".md";
|
||||
}
|
||||
|
||||
// Render Cover page
|
||||
if (OPTIONS.coverpage) {
|
||||
if (page === OPTIONS.homepage) {
|
||||
load(OPTIONS.coverpage).then(renderCover);
|
||||
} else {
|
||||
renderCover();
|
||||
}
|
||||
}
|
||||
|
||||
cacheXhr && cacheXhr.abort && cacheXhr.abort();
|
||||
// Render markdown file
|
||||
cacheXhr = load(page, 'GET', renderLoading);
|
||||
@ -2598,6 +2653,7 @@ var Docsify = function () {
|
||||
mainRender(function (_) {
|
||||
activeLink('aside.sidebar', true);
|
||||
scrollIntoView();
|
||||
OPTIONS.coverpage && sticky();
|
||||
});
|
||||
};
|
||||
|
||||
|
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
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user