bump 1.1.0

This commit is contained in:
qingwei.li 2016-12-16 22:38:44 +08:00
commit 7f0b1089c0
5 changed files with 65 additions and 20 deletions

View file

@ -4,11 +4,12 @@ var Docsify = (function () {
/**
* Simple ajax
* @param {String} url
* @param {String} [method=get]
* @param {String} [method=GET]
* @param {Function} [loading] handle loading
* @return {Promise}
*/
function load (url, method) {
if ( method === void 0 ) method = 'get';
function load (url, method, loading) {
if ( method === void 0 ) method = 'GET';
var xhr = new XMLHttpRequest();
@ -19,13 +20,18 @@ function load (url, method) {
then: function (success, error) {
if ( error === void 0 ) error = function () {};
if (loading) {
xhr.addEventListener('progress', loading);
xhr.addEventListener('loaded', loading);
}
xhr.addEventListener('error', error);
xhr.addEventListener('load', function (ref) {
var target = ref.target;
target.status >= 400 ? error(target) : success(target.response);
});
}
},
abort: function () { return xhr.readyState !== 4 && xhr.abort(); }
}
}
@ -191,6 +197,12 @@ function bindToggle (dom) {
});
}
var cacheContentDOM;
function scroll2Top (dom) {
cacheContentDOM = cacheContentDOM || document.querySelector(dom);
cacheContentDOM.scrollTop = 0;
}
var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
@ -2399,6 +2411,8 @@ function renderArticle (content) {
if (!renderNavbar.rendered) { renderNavbar(null, OPTIONS$1); }
renderSidebar.rendered = false;
renderNavbar.rendered = false;
if (OPTIONS$1.auto2top) { scroll2Top('section.content'); }
}
/**
@ -2436,6 +2450,30 @@ function renderSidebar (content) {
toc = [];
}
/**
* render loading bar
* @return {[type]} [description]
*/
function renderLoading (ref) {
var loaded = ref.loaded;
var total = ref.total;
var num = Math.floor(loaded / total * 100);
if (!CACHE['loading']) {
var div = document.createElement('div');
div.classList.add('progress');
document.body.appendChild(div);
CACHE['loading'] = div;
}
CACHE['loading'].style.width = num >= 95 ? '0%' : num + '%';
}
/**
* Load Config
* @param {Object} options
*/
function config (options) {
OPTIONS$1 = options;
}
@ -2448,7 +2486,8 @@ var OPTIONS = {
sidebarToggle: false,
loadSidebar: null,
loadNavbar: null,
router: false
router: false,
auto2top: false
};
var script = document.currentScript || [].slice.call(document.getElementsByTagName('script')).pop();
@ -2467,6 +2506,7 @@ if (script) {
config(OPTIONS);
var cacheRoute = null;
var cacheXhr = null;
var mainRender = function (cb) {
var route = getRoute();
@ -2480,17 +2520,22 @@ var mainRender = function (cb) {
basePath = basePath.match(/(\S*\/)[^\/]+$/)[1];
}
cacheXhr && cacheXhr.abort && cacheXhr.abort();
// Render markdown file
load((!route || /\/$/.test(route)) ? (route + "README.md") : (route + ".md"))
.then(function (result) {
renderArticle(result);
if (OPTIONS.loadSidebar) {
if (wait === false) { cb(); }
wait = false;
} else {
cb();
}
}, function (_) { return renderArticle(null); });
cacheXhr = load(
(!route || /\/$/.test(route)) ? (route + "README.md") : (route + ".md"),
'GET',
renderLoading);
cacheXhr.then(function (result) {
renderArticle(result);
if (OPTIONS.loadSidebar) {
if (wait === false) { cb(); }
wait = false;
} else {
cb();
}
}, function (_) { return renderArticle(null); });
// Render sidebar
if (OPTIONS.loadSidebar) {

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