Skip to content

Commit a72e7a3

Browse files
committed
[build] 4.3.1
1 parent 26c22a9 commit a72e7a3

File tree

6 files changed

+132
-14
lines changed

6 files changed

+132
-14
lines changed

docs/_coverpage.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
![logo](_media/icon.svg)
22

3-
# docsify <small>4.3.0</small>
3+
# docsify <small>4.3.1</small>
44

55
> A magical documentation site generator.
66

lib/docsify.js

+121-3
Original file line numberDiff line numberDiff line change
@@ -3031,15 +3031,127 @@ function getAndActive (router, el, isParent, autoTitle) {
30313031
return target
30323032
}
30333033

3034+
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; }; }();
3035+
3036+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3037+
3038+
var Tweezer = function () {
3039+
function Tweezer() {
3040+
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
3041+
3042+
_classCallCheck(this, Tweezer);
3043+
3044+
this.duration = opts.duration || 1000;
3045+
this.ease = opts.easing || this._defaultEase;
3046+
this.start = opts.start;
3047+
this.end = opts.end;
3048+
3049+
this.frame = null;
3050+
this.next = null;
3051+
this.isRunning = false;
3052+
this.events = {};
3053+
this.direction = this.start < this.end ? 'up' : 'down';
3054+
}
3055+
3056+
_createClass(Tweezer, [{
3057+
key: 'begin',
3058+
value: function begin() {
3059+
if (!this.isRunning && this.next !== this.end) {
3060+
this.frame = window.requestAnimationFrame(this._tick.bind(this));
3061+
}
3062+
return this;
3063+
}
3064+
}, {
3065+
key: 'stop',
3066+
value: function stop() {
3067+
window.cancelAnimationFrame(this.frame);
3068+
this.isRunning = false;
3069+
this.frame = null;
3070+
this.timeStart = null;
3071+
this.next = null;
3072+
return this;
3073+
}
3074+
}, {
3075+
key: 'on',
3076+
value: function on(name, handler) {
3077+
this.events[name] = this.events[name] || [];
3078+
this.events[name].push(handler);
3079+
return this;
3080+
}
3081+
}, {
3082+
key: 'emit',
3083+
value: function emit(name, val) {
3084+
var _this = this;
3085+
3086+
var e = this.events[name];
3087+
e && e.forEach(function (handler) {
3088+
return handler.call(_this, val);
3089+
});
3090+
}
3091+
}, {
3092+
key: '_tick',
3093+
value: function _tick(currentTime) {
3094+
this.isRunning = true;
3095+
3096+
var lastTick = this.next || this.start;
3097+
3098+
if (!this.timeStart) { this.timeStart = currentTime; }
3099+
this.timeElapsed = currentTime - this.timeStart;
3100+
this.next = Math.round(this.ease(this.timeElapsed, this.start, this.end - this.start, this.duration));
3101+
3102+
if (this._shouldTick(lastTick)) {
3103+
this.emit('tick', this.next);
3104+
this.frame = window.requestAnimationFrame(this._tick.bind(this));
3105+
} else {
3106+
this.emit('tick', this.end);
3107+
this.emit('done', null);
3108+
}
3109+
}
3110+
}, {
3111+
key: '_shouldTick',
3112+
value: function _shouldTick(lastTick) {
3113+
return {
3114+
up: this.next < this.end && lastTick <= this.next,
3115+
down: this.next > this.end && lastTick >= this.next
3116+
}[this.direction];
3117+
}
3118+
}, {
3119+
key: '_defaultEase',
3120+
value: function _defaultEase(t, b, c, d) {
3121+
if ((t /= d / 2) < 1) { return c / 2 * t * t + b; }
3122+
return -c / 2 * (--t * (t - 2) - 1) + b;
3123+
}
3124+
}]);
3125+
3126+
return Tweezer;
3127+
}();
3128+
30343129
var nav = {};
30353130
var hoverOver = false;
3131+
var scroller = null;
3132+
var enableScrollEvent = true;
3133+
3134+
function scrollTo (el) {
3135+
if (scroller) { scroller.stop(); }
3136+
enableScrollEvent = false;
3137+
scroller = new Tweezer({
3138+
start: window.scrollY,
3139+
end: el.getBoundingClientRect().top + window.scrollY,
3140+
duration: 500
3141+
})
3142+
.on('tick', function (v) { return window.scrollTo(0, v); })
3143+
.on('done', function () { enableScrollEvent = true; scroller = null; })
3144+
.begin();
3145+
}
30363146

30373147
function highlight () {
3148+
if (!enableScrollEvent) { return }
30383149
var sidebar = getNode('.sidebar');
30393150
var anchors = findAll('.anchor');
30403151
var wrap = find(sidebar, '.sidebar-nav');
30413152
var active = find(sidebar, 'li.active');
3042-
var top = body.scrollTop;
3153+
var doc = document.documentElement;
3154+
var top = doc && doc.scrollTop || document.body.scrollTop;
30433155
var last;
30443156

30453157
for (var i = 0, len = anchors.length; i < len; i += 1) {
@@ -3109,7 +3221,13 @@ function scrollActiveSidebar (router) {
31093221

31103222
function scrollIntoView (id) {
31113223
var section = find('#' + id);
3112-
section && section.scrollIntoView();
3224+
section && scrollTo(section);
3225+
3226+
var li = nav[id];
3227+
var sidebar = getNode('.sidebar');
3228+
var active = find(sidebar, 'li.active');
3229+
active && active.classList.remove('active');
3230+
li && li.classList.add('active');
31133231
}
31143232

31153233
var scrollEl = $.scrollingElement || $.documentElement;
@@ -3826,7 +3944,7 @@ initGlobalAPI();
38263944
/**
38273945
* Version
38283946
*/
3829-
Docsify.version = '4.3.0';
3947+
Docsify.version = '4.3.1';
38303948

38313949
/**
38323950
* Run Docsify

lib/docsify.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/docsify-server-renderer/package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/docsify-server-renderer/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "docsify-server-renderer",
3-
"version": "4.3.0",
3+
"version": "4.3.1",
44
"description": "docsify server renderer",
55
"author": {
66
"name": "qingwei-li",

src/core/event/scroll.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ let scroller = null
88
let enableScrollEvent = true
99

1010
function scrollTo (el) {
11-
if (scroller) scroller.stop();
12-
enableScrollEvent = false;
11+
if (scroller) scroller.stop()
12+
enableScrollEvent = false
1313
scroller = new Tweezer({
1414
start: window.scrollY,
1515
end: el.getBoundingClientRect().top + window.scrollY,
1616
duration: 500
1717
})
1818
.on('tick', v => window.scrollTo(0, v))
19-
.on('done', () => { enableScrollEvent = true; scroller = null; })
19+
.on('done', () => { enableScrollEvent = true; scroller = null })
2020
.begin()
2121
}
2222

@@ -26,7 +26,7 @@ function highlight () {
2626
const anchors = dom.findAll('.anchor')
2727
const wrap = dom.find(sidebar, '.sidebar-nav')
2828
let active = dom.find(sidebar, 'li.active')
29-
let doc = document.documentElement
29+
const doc = document.documentElement
3030
const top = doc && doc.scrollTop || document.body.scrollTop
3131
let last
3232

@@ -99,9 +99,9 @@ export function scrollIntoView (id) {
9999
const section = dom.find('#' + id)
100100
section && scrollTo(section)
101101

102-
let li = nav[id]
102+
const li = nav[id]
103103
const sidebar = dom.getNode('.sidebar')
104-
let active = dom.find(sidebar, 'li.active')
104+
const active = dom.find(sidebar, 'li.active')
105105
active && active.classList.remove('active')
106106
li && li.classList.add('active')
107107
}

0 commit comments

Comments
 (0)