bump 2.3.0

This commit is contained in:
qingwei.li 2017-02-13 22:51:31 +08:00
commit ec8b17bd43
11 changed files with 183 additions and 66 deletions

View file

@ -176,7 +176,6 @@ function emojify (text) {
}
var utils = Object.freeze({
load: load,
genTree: genTree,
@ -208,7 +207,9 @@ function scrollActiveSidebar () {
for (var i = 0, len = lis.length; i < len; i += 1) {
var li = lis[i];
var href = li.querySelector('a').getAttribute('href');
var a = li.querySelector('a');
if (!a) { continue }
var href = a.getAttribute('href');
if (href !== '/') {
var match = href.match('#([^#]+)$');
@ -322,10 +323,12 @@ function bindToggle (dom) {
}
}
var scrollingElement = document.scrollingElement || document.documentElement;
function scroll2Top (offset) {
if ( offset === void 0 ) offset = 0;
document.body.scrollTop = offset === true ? 0 : Number(offset);
scrollingElement.scrollTop = offset === true ? 0 : Number(offset);
}
function sticky () {
@ -2543,6 +2546,7 @@ function cssVars () {
var markdown = marked;
var toc = [];
var CACHE = {};
var originTitle = document.title;
var renderTo = function (dom, content) {
dom = typeof dom === 'object' ? dom : document.querySelector(dom);
@ -2579,10 +2583,9 @@ function init () {
return ("<pre v-pre data-lang=\"" + lang + "\"><code class=\"lang-" + lang + "\">" + hl + "</code></pre>")
};
renderer.link = function (href, title, text) {
if (!/:/.test(href)) {
if (!/:|(\/{2})/.test(href)) {
href = ("#/" + href).replace(/\/+/g, '/');
}
return ("<a href=\"" + href + "\" title=\"" + (title || '') + "\">" + text + "</a>")
};
renderer.paragraph = function (text) {
@ -2593,11 +2596,19 @@ function init () {
}
return ("<p>" + text + "</p>")
};
renderer.image = function (href, title, text) {
var url = /:|(\/{2})/.test(href) ? href : ($docsify.basePath + href).replace(/\/+/g, '/');
var titleHTML = title ? (" title=\"" + title + "\"") : '';
return ("<img src=\"" + url + "\" alt=\"" + text + "\"" + titleHTML + " />")
};
if (typeof $docsify.markdown === 'function') {
markdown.setOptions({ renderer: renderer });
markdown = $docsify.markdown.call(this, markdown);
markdown = $docsify.markdown.call(this, markdown, renderer);
} else {
if ($docsify.markdown && $docsify.markdown.renderer) {
$docsify.markdown.renderer = merge(renderer, $docsify.markdown.renderer);
}
markdown.setOptions(merge({ renderer: renderer }, $docsify.markdown));
}
@ -2653,25 +2664,34 @@ function renderApp (dom, replace) {
* article
*/
function renderArticle (content) {
renderTo('article', content ? markdown(content) : 'not found');
if (!$docsify.loadSidebar) { renderSidebar(); }
var hook = window.Docsify.hook;
var renderFn = function (data) {
renderTo('article', data);
if (!$docsify.loadSidebar) { renderSidebar(); }
if (content && typeof Vue !== 'undefined') {
CACHE.vm && CACHE.vm.$destroy();
if (data && typeof Vue !== 'undefined') {
CACHE.vm && CACHE.vm.$destroy();
var script = [].slice.call(
document.body.querySelectorAll('article>script'))
.filter(function (script) { return !/template/.test(script.type); }
)[0];
var code = script ? script.innerText.trim() : null;
var script = [].slice.call(
document.body.querySelectorAll('article>script'))
.filter(function (script) { return !/template/.test(script.type); }
)[0];
var code = script ? script.innerText.trim() : null;
script && script.remove();
CACHE.vm = code
? new Function(("return " + code))()
: new Vue({ el: 'main' }); // eslint-disable-line
CACHE.vm && CACHE.vm.$nextTick(function (_) { return scrollActiveSidebar(); });
}
if ($docsify.auto2top) { setTimeout(function () { return scroll2Top($docsify.auto2top); }, 0); }
script && script.remove();
CACHE.vm = code
? new Function(("return " + code))()
: new Vue({ el: 'main' }); // eslint-disable-line
CACHE.vm && CACHE.vm.$nextTick(function (_) { return scrollActiveSidebar(); });
}
if ($docsify.auto2top) { setTimeout(function () { return scroll2Top($docsify.auto2top); }, 0); }
};
hook.emit('before', content, function (result) {
var html = result ? markdown(result) : '';
hook.emit('after', html, function (result) { return renderFn(result || 'not found'); });
});
}
/**
@ -2700,15 +2720,21 @@ function renderSidebar (content) {
}
renderTo('.sidebar-nav', html);
if (toc[0] && toc[0].level === 1) {
document.title = "" + (toc[0].title) + (originTitle ? ' - ' + originTitle : '');
}
var target = activeLink('.sidebar-nav', true);
if (target) { renderSubSidebar(target); }
toc = [];
toc = [];
scrollActiveSidebar();
}
function renderSubSidebar (target) {
if (!$docsify.subMaxLevel) { return }
toc[0] && toc[0].level === 1 && toc.shift();
target.parentNode.innerHTML += tree(genTree(toc, $docsify.subMaxLevel), '<ul>');
}
@ -2787,6 +2813,57 @@ function renderLoading (ref) {
}
}
var Hook = function Hook () {
this.beforeHooks = [];
this.afterHooks = [];
this.initHooks = [];
this.readyHooks = [];
};
Hook.prototype.beforeEach = function beforeEach (fn) {
this.beforeHooks.push(fn);
};
Hook.prototype.afterEach = function afterEach (fn) {
this.afterHooks.push(fn);
};
Hook.prototype.init = function init (fn) {
this.initHooks.push(fn);
};
Hook.prototype.ready = function ready (fn) {
this.readyHooks.push(fn);
};
Hook.prototype.emit = function emit (name, data, next) {
var newData = data;
var queue = this[name + 'Hooks'];
var step = function (index) {
var hook = queue[index];
if (index >= queue.length) {
next && next(newData);
} else {
if (typeof hook === 'function') {
if (hook.length === 2) {
hook(data, function (result) {
newData = result;
step(index + 1);
});
} else {
var result = hook(data);
newData = result !== undefined ? result : newData;
step(index + 1);
}
} else {
step(index + 1);
}
}
};
step(0);
};
var OPTIONS = merge({
el: '#app',
repo: '',
@ -2818,11 +2895,14 @@ if (script) {
if (OPTIONS.name === true) { OPTIONS.name = ''; }
}
var hook = new Hook();
// utils
window.$docsify = OPTIONS;
window.Docsify = {
installed: true,
utils: merge({}, utils)
utils: merge({}, utils),
hook: hook
};
// load options
@ -2831,11 +2911,20 @@ init();
var cacheRoute = null;
var cacheXhr = null;
var getAlias = function (route) {
if (OPTIONS.alias[route]) {
return getAlias(OPTIONS.alias[route])
} else {
return route
}
};
var mainRender = function (cb) {
var route = OPTIONS.basePath + getRoute();
var page;
var route = getRoute();
if (cacheRoute === route) { return cb() }
var basePath = cacheRoute = route;
var basePath = cacheRoute = OPTIONS.basePath + route;
if (!/\//.test(basePath)) {
basePath = '';
@ -2843,10 +2932,18 @@ var mainRender = function (cb) {
basePath = basePath.match(/(\S*\/)[^\/]+$/)[1];
}
var page;
// replace route
route = '/' + route;
if (OPTIONS.alias && OPTIONS.alias[route]) {
route = getAlias(route);
} else {
route = (OPTIONS.basePath + route).replace(/\/+/, '/');
}
if (!route) {
page = OPTIONS.homepage || 'README.md';
} else if (/\.md$/.test(route)) {
page = route;
} else if (/\/$/.test(route)) {
page = route + "README.md";
} else {
@ -2884,21 +2981,26 @@ var mainRender = function (cb) {
};
var Docsify = function () {
var dom = document.querySelector(OPTIONS.el) || document.body;
var replace = dom !== document.body;
var main = function () {
mainRender(function (_) {
scrollIntoView();
activeLink('nav')
;[].concat(window.$docsify.plugins).forEach(function (fn) { return fn && fn(); });
});
};
setTimeout(function (_) {
[].concat(OPTIONS.plugins).forEach(function (fn) { return typeof fn === 'function' && fn(hook); });
window.Docsify.hook.emit('init');
// Render app
renderApp(dom, replace);
main();
if (!/^#\//.test(window.location.hash)) { window.location.hash = '#/'; }
window.addEventListener('hashchange', main);
var dom = document.querySelector(OPTIONS.el) || document.body;
var replace = dom !== document.body;
var main = function () {
mainRender(function (_) {
scrollIntoView();
activeLink('nav');
});
};
// Render app
renderApp(dom, replace);
main();
if (!/^#\//.test(window.location.hash)) { window.location.hash = '#/'; }
window.addEventListener('hashchange', main);
window.Docsify.hook.emit('ready');
}, 0);
};
var index = Docsify();