bump 1.6.0
This commit is contained in:
parent
510ae37a04
commit
87b373b841
6 changed files with 52 additions and 31 deletions
|
|
@ -175,10 +175,12 @@ var merge = Object.assign || function (to) {
|
|||
function scrollActiveSidebar () {
|
||||
if (isMobile()) { return }
|
||||
|
||||
var hoveredOverSidebar = false;
|
||||
var anchors = document.querySelectorAll('.anchor');
|
||||
var sidebar = document.querySelector('aside.sidebar');
|
||||
var nav = {};
|
||||
var lis = document.querySelectorAll('.sidebar li');
|
||||
var active = null;
|
||||
var lis = sidebar.querySelectorAll('li');
|
||||
var active = sidebar.querySelector('li.active');
|
||||
|
||||
for (var i = 0, len = lis.length; i < len; i += 1) {
|
||||
var li = lis[i];
|
||||
|
|
@ -193,27 +195,34 @@ function scrollActiveSidebar () {
|
|||
}
|
||||
|
||||
function highlight () {
|
||||
var top = document.body.scrollTop;
|
||||
var last;
|
||||
|
||||
for (var i = 0, len = anchors.length; i < len; i += 1) {
|
||||
var node = anchors[i];
|
||||
var bcr = node.getBoundingClientRect();
|
||||
|
||||
if (bcr.top < 10 && bcr.bottom > 10) {
|
||||
var li = nav[node.getAttribute('data-id')];
|
||||
|
||||
if (!li || li === active) { return }
|
||||
if (active) { active.setAttribute('class', ''); }
|
||||
|
||||
li.setAttribute('class', 'active');
|
||||
active = li;
|
||||
|
||||
return
|
||||
if (node.offsetTop > top) {
|
||||
if (!last) { last = node; }
|
||||
break
|
||||
} else {
|
||||
last = node;
|
||||
}
|
||||
}
|
||||
if (!last) { return }
|
||||
var li = nav[last.getAttribute('data-id')];
|
||||
|
||||
if (!li || li === active) { return }
|
||||
if (active) { active.classList.remove('active'); }
|
||||
|
||||
li.classList.add('active');
|
||||
active = li;
|
||||
!hoveredOverSidebar && active.scrollIntoView();
|
||||
}
|
||||
|
||||
window.removeEventListener('scroll', highlight);
|
||||
window.addEventListener('scroll', highlight);
|
||||
highlight();
|
||||
sidebar.addEventListener('mouseover', function () { hoveredOverSidebar = true; });
|
||||
sidebar.addEventListener('mouseleave', function () { hoveredOverSidebar = false; });
|
||||
}
|
||||
|
||||
function scrollIntoView () {
|
||||
|
|
@ -221,7 +230,9 @@ function scrollIntoView () {
|
|||
if (!id || !id.length) { return }
|
||||
var section = document.querySelector(decodeURIComponent(id[0]));
|
||||
|
||||
if (section) { section.scrollIntoView(); }
|
||||
if (section) { setTimeout(function () { return section.scrollIntoView(); }, 0); }
|
||||
|
||||
return section
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -237,13 +248,13 @@ function activeLink (dom, activeParent) {
|
|||
.forEach(function (node) {
|
||||
if (host.indexOf(node.href) === 0 && !target) {
|
||||
activeParent
|
||||
? node.parentNode.setAttribute('class', 'active')
|
||||
: node.setAttribute('class', 'active');
|
||||
? node.parentNode.classList.add('active')
|
||||
: node.classList.add('active');
|
||||
target = node;
|
||||
} else {
|
||||
activeParent
|
||||
? node.parentNode.removeAttribute('class')
|
||||
: node.removeAttribute('class');
|
||||
? node.parentNode.classList.remove('active')
|
||||
: node.classList.remove('active');
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -261,13 +272,18 @@ function bindToggle (dom) {
|
|||
dom.addEventListener('click', function () { return body.classList.toggle('close'); });
|
||||
|
||||
if (isMobile()) {
|
||||
document.querySelector('aside')
|
||||
.addEventListener('click', function (_) { return body.classList.toggle('close'); });
|
||||
var sidebar = document.querySelector('aside.sidebar');
|
||||
document.body.addEventListener('click', function (e) {
|
||||
if (e.target !== dom && !dom.contains(e.target)) { body.classList.toggle('close'); }
|
||||
if (sidebar.contains(e.target)) { setTimeout(function () { return activeLink(sidebar, true); }, 0); }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function scroll2Top () {
|
||||
document.body.scrollTop = 0;
|
||||
function scroll2Top (offset) {
|
||||
if ( offset === void 0 ) offset = 0;
|
||||
|
||||
document.body.scrollTop = offset === true ? 0 : Number(offset);
|
||||
}
|
||||
|
||||
function sticky () {
|
||||
|
|
@ -2439,6 +2455,7 @@ var OPTIONS$1 = {};
|
|||
var markdown = marked;
|
||||
var toc = [];
|
||||
var CACHE = {};
|
||||
var TIP_RE = /^!\s/;
|
||||
|
||||
var renderTo = function (dom, content) {
|
||||
dom = typeof dom === 'object' ? dom : document.querySelector(dom);
|
||||
|
|
@ -2488,6 +2505,10 @@ function init (options) {
|
|||
|
||||
return ("<a href=\"" + href + "\" title=\"" + (title || '') + "\">" + text + "</a>")
|
||||
};
|
||||
renderer.paragraph = function (text) {
|
||||
var isTip = TIP_RE.test(text);
|
||||
return isTip ? ("<p class=\"tip\">" + (text.replace(TIP_RE, '')) + "</p>") : ("<p>" + text + "</p>")
|
||||
};
|
||||
|
||||
if (typeof OPTIONS$1.markdown === 'function') {
|
||||
markdown.setOptions({ renderer: renderer });
|
||||
|
|
@ -2531,7 +2552,7 @@ function renderArticle (content) {
|
|||
var vm = new Vue({ el: 'main' }); // eslint-disable-line
|
||||
vm.$nextTick(function (_) { return scrollActiveSidebar(); });
|
||||
}
|
||||
if (OPTIONS$1.auto2top) { scroll2Top(); }
|
||||
if (OPTIONS$1.auto2top) { setTimeout(function () { return scroll2Top(OPTIONS$1.auto2top); }, 0); }
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -2561,7 +2582,7 @@ function renderSidebar (content) {
|
|||
|
||||
renderTo('aside.sidebar', html);
|
||||
var target = activeLink('aside.sidebar', true);
|
||||
if (content) { renderSubSidebar(target); }
|
||||
if (target) { renderSubSidebar(target); }
|
||||
toc = [];
|
||||
|
||||
scrollActiveSidebar();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue