[build] 4.3.1
This commit is contained in:
parent
26c22a9843
commit
a72e7a3a3f
6 changed files with 132 additions and 14 deletions
124
lib/docsify.js
124
lib/docsify.js
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue