[build] 4.3.1

This commit is contained in:
qingwei.li 2017-08-30 21:54:48 +08:00
commit a72e7a3a3f
6 changed files with 132 additions and 14 deletions

View file

@ -1,6 +1,6 @@
![logo](_media/icon.svg)
# docsify <small>4.3.0</small>
# docsify <small>4.3.1</small>
> A magical documentation site generator.

View file

@ -3031,15 +3031,127 @@ function getAndActive (router, el, isParent, autoTitle) {
return target
}
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) { descriptor.writable = true; } Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) { defineProperties(Constructor.prototype, protoProps); } if (staticProps) { defineProperties(Constructor, staticProps); } return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Tweezer = function () {
function Tweezer() {
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, Tweezer);
this.duration = opts.duration || 1000;
this.ease = opts.easing || this._defaultEase;
this.start = opts.start;
this.end = opts.end;
this.frame = null;
this.next = null;
this.isRunning = false;
this.events = {};
this.direction = this.start < this.end ? 'up' : 'down';
}
_createClass(Tweezer, [{
key: 'begin',
value: function begin() {
if (!this.isRunning && this.next !== this.end) {
this.frame = window.requestAnimationFrame(this._tick.bind(this));
}
return this;
}
}, {
key: 'stop',
value: function stop() {
window.cancelAnimationFrame(this.frame);
this.isRunning = false;
this.frame = null;
this.timeStart = null;
this.next = null;
return this;
}
}, {
key: 'on',
value: function on(name, handler) {
this.events[name] = this.events[name] || [];
this.events[name].push(handler);
return this;
}
}, {
key: 'emit',
value: function emit(name, val) {
var _this = this;
var e = this.events[name];
e && e.forEach(function (handler) {
return handler.call(_this, val);
});
}
}, {
key: '_tick',
value: function _tick(currentTime) {
this.isRunning = true;
var lastTick = this.next || this.start;
if (!this.timeStart) { this.timeStart = currentTime; }
this.timeElapsed = currentTime - this.timeStart;
this.next = Math.round(this.ease(this.timeElapsed, this.start, this.end - this.start, this.duration));
if (this._shouldTick(lastTick)) {
this.emit('tick', this.next);
this.frame = window.requestAnimationFrame(this._tick.bind(this));
} else {
this.emit('tick', this.end);
this.emit('done', null);
}
}
}, {
key: '_shouldTick',
value: function _shouldTick(lastTick) {
return {
up: this.next < this.end && lastTick <= this.next,
down: this.next > this.end && lastTick >= this.next
}[this.direction];
}
}, {
key: '_defaultEase',
value: function _defaultEase(t, b, c, d) {
if ((t /= d / 2) < 1) { return c / 2 * t * t + b; }
return -c / 2 * (--t * (t - 2) - 1) + b;
}
}]);
return Tweezer;
}();
var nav = {};
var hoverOver = false;
var scroller = null;
var enableScrollEvent = true;
function scrollTo (el) {
if (scroller) { scroller.stop(); }
enableScrollEvent = false;
scroller = new Tweezer({
start: window.scrollY,
end: el.getBoundingClientRect().top + window.scrollY,
duration: 500
})
.on('tick', function (v) { return window.scrollTo(0, v); })
.on('done', function () { enableScrollEvent = true; scroller = null; })
.begin();
}
function highlight () {
if (!enableScrollEvent) { return }
var sidebar = getNode('.sidebar');
var anchors = findAll('.anchor');
var wrap = find(sidebar, '.sidebar-nav');
var active = find(sidebar, 'li.active');
var top = body.scrollTop;
var doc = document.documentElement;
var top = doc && doc.scrollTop || document.body.scrollTop;
var last;
for (var i = 0, len = anchors.length; i < len; i += 1) {
@ -3109,7 +3221,13 @@ function scrollActiveSidebar (router) {
function scrollIntoView (id) {
var section = find('#' + id);
section && section.scrollIntoView();
section && scrollTo(section);
var li = nav[id];
var sidebar = getNode('.sidebar');
var active = find(sidebar, 'li.active');
active && active.classList.remove('active');
li && li.classList.add('active');
}
var scrollEl = $.scrollingElement || $.documentElement;
@ -3826,7 +3944,7 @@ initGlobalAPI();
/**
* Version
*/
Docsify.version = '4.3.0';
Docsify.version = '4.3.1';
/**
* Run Docsify

4
lib/docsify.min.js vendored

File diff suppressed because one or more lines are too long

View file

@ -37,5 +37,5 @@
"integrity": "sha1-6DWIAbhrg7F1YNTjw4LXrvIQCUQ="
}
},
"version": "4.3.0"
"version": "4.3.1"
}

View file

@ -1,6 +1,6 @@
{
"name": "docsify-server-renderer",
"version": "4.3.0",
"version": "4.3.1",
"description": "docsify server renderer",
"author": {
"name": "qingwei-li",

View file

@ -8,15 +8,15 @@ let scroller = null
let enableScrollEvent = true
function scrollTo (el) {
if (scroller) scroller.stop();
enableScrollEvent = false;
if (scroller) scroller.stop()
enableScrollEvent = false
scroller = new Tweezer({
start: window.scrollY,
end: el.getBoundingClientRect().top + window.scrollY,
duration: 500
})
.on('tick', v => window.scrollTo(0, v))
.on('done', () => { enableScrollEvent = true; scroller = null; })
.on('done', () => { enableScrollEvent = true; scroller = null })
.begin()
}
@ -26,7 +26,7 @@ function highlight () {
const anchors = dom.findAll('.anchor')
const wrap = dom.find(sidebar, '.sidebar-nav')
let active = dom.find(sidebar, 'li.active')
let doc = document.documentElement
const doc = document.documentElement
const top = doc && doc.scrollTop || document.body.scrollTop
let last
@ -99,9 +99,9 @@ export function scrollIntoView (id) {
const section = dom.find('#' + id)
section && scrollTo(section)
let li = nav[id]
const li = nav[id]
const sidebar = dom.getNode('.sidebar')
let active = dom.find(sidebar, 'li.active')
const active = dom.find(sidebar, 'li.active')
active && active.classList.remove('active')
li && li.classList.add('active')
}