jekyll-text-theme 1.5.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +41 -153
- data/_data/authors.yml +0 -0
- data/_data/licenses.yml +16 -0
- data/_data/locale.yml +4 -10
- data/_data/navigation.yml +13 -0
- data/_data/variables.yml +22 -6
- data/_includes/analytics-providers/custom.html +0 -0
- data/_includes/analytics-providers/google.html +16 -0
- data/_includes/analytics.html +7 -0
- data/_includes/article-footer/custom.html +1 -0
- data/_includes/article-footer/license.html +24 -0
- data/_includes/article-info.html +90 -0
- data/_includes/aside/toc.html +1 -0
- data/_includes/author-profile.html +50 -0
- data/_includes/comments-providers/custom.html +0 -0
- data/_includes/comments-providers/disqus.html +22 -0
- data/_includes/comments-providers/gitalk.html +32 -0
- data/_includes/comments.html +9 -0
- data/_includes/follow-me.html +84 -0
- data/_includes/footer.html +39 -0
- data/_includes/head.html +54 -0
- data/_includes/header.html +33 -0
- data/_includes/markdown-enhancements.html +32 -0
- data/_includes/{utils → markdown-enhancements}/chart.html +1 -3
- data/_includes/{utils → markdown-enhancements}/mathjax.html +11 -4
- data/_includes/{utils → markdown-enhancements}/mermaid.html +1 -3
- data/_includes/pageview-providers/custom.html +0 -0
- data/_includes/pageview-providers/custom/home.html +0 -0
- data/_includes/pageview-providers/custom/post.html +0 -0
- data/_includes/pageview-providers/leancloud/home.html +35 -0
- data/_includes/pageview-providers/leancloud/leancloud.js +71 -0
- data/_includes/pageview-providers/leancloud/post.html +31 -0
- data/_includes/pageview.html +31 -0
- data/_includes/scripts/archieve.js +238 -0
- data/_includes/scripts/article-list.html +27 -0
- data/_includes/scripts/article.js +24 -0
- data/_includes/scripts/aside/affix.js +26 -0
- data/_includes/scripts/aside/toc.js +37 -0
- data/_includes/scripts/common.js +3 -0
- data/_includes/scripts/home.js +3 -0
- data/_includes/scripts/lib/affix.js +103 -0
- data/_includes/scripts/{utils.html → lib/lazyload.js} +55 -92
- data/_includes/scripts/lib/scroll.js +13 -0
- data/_includes/scripts/lib/throttle.js +28 -0
- data/_includes/scripts/lib/toc.js +106 -0
- data/_includes/scripts/page.js +3 -0
- data/_includes/scripts/sidebar.js +14 -0
- data/_includes/scripts/utils.js +38 -0
- data/_includes/scripts/variables.html +27 -0
- data/_includes/sidebar/toc.html +27 -0
- data/_includes/snippets/assign.html +5 -0
- data/_includes/snippets/get-nav-url.html +3 -2
- data/_includes/snippets/page-title.html +11 -6
- data/_includes/snippets/page-url.html +3 -1
- data/_includes/snippets/to-boolean.html +7 -0
- data/_includes/{icon → svg/icon}/social/behance.svg +0 -0
- data/_includes/{icon → svg/icon}/social/douban.svg +0 -0
- data/_includes/{icon → svg/icon}/social/facebook.svg +0 -0
- data/_includes/{icon → svg/icon}/social/flicker.svg +0 -0
- data/_includes/{icon → svg/icon}/social/github.svg +0 -0
- data/_includes/{icon → svg/icon}/social/googleplus.svg +0 -0
- data/_includes/{icon → svg/icon}/social/linkedin.svg +0 -0
- data/_includes/{icon → svg/icon}/social/mail.svg +0 -0
- data/_includes/{icon → svg/icon}/social/pinterest.svg +0 -0
- data/_includes/{icon → svg/icon}/social/qq.svg +0 -0
- data/_includes/{icon → svg/icon}/social/twitter.svg +0 -0
- data/_includes/{icon → svg/icon}/social/weibo.svg +0 -0
- data/_includes/{icon → svg/icon}/social/weixin.svg +0 -0
- data/_includes/{icon → svg/icon}/social/zhihu.svg +0 -0
- data/_includes/{logo → svg}/logo.svg +1 -1
- data/_includes/tags.html +52 -0
- data/_layouts/404.html +12 -0
- data/_layouts/archive.html +25 -0
- data/_layouts/article.html +78 -0
- data/_layouts/base.html +13 -33
- data/_layouts/home.html +135 -121
- data/_layouts/landing.html +164 -0
- data/_layouts/page.html +157 -9
- data/_sass/additional/_alert.scss +25 -0
- data/_sass/additional/_photo-frame.scss +17 -0
- data/_sass/animate/_fade-in-down.scss +1 -1
- data/_sass/animate/_fade-in.scss +1 -1
- data/_sass/common/_classes.scss +5 -2
- data/_sass/common/_reset.scss +32 -22
- data/_sass/common/_variables.scss +87 -31
- data/_sass/common/classes/_animation.scss +9 -0
- data/_sass/common/classes/_clearfix.scss +8 -0
- data/_sass/common/classes/_grid.scss +48 -0
- data/_sass/common/classes/_horizontal-rules.scss +14 -0
- data/_sass/common/classes/_link.scss +18 -145
- data/_sass/common/classes/_media.scss +1 -2
- data/_sass/common/classes/_overflow.scss +8 -0
- data/_sass/common/classes/_pseudo.scss +26 -0
- data/_sass/common/classes/_shadow.scss +13 -5
- data/_sass/common/classes/_spacing.scss +52 -0
- data/_sass/common/components/_button.scss +179 -47
- data/_sass/common/components/_card.scss +18 -0
- data/_sass/common/components/_menu.scss +43 -0
- data/_sass/common/components/_toc.scss +125 -0
- data/_sass/components/_article.content.scss +37 -45
- data/_sass/components/_article.info.scss +25 -0
- data/_sass/components/_author-profile.scss +43 -0
- data/_sass/components/_follow-me.scss +16 -19
- data/_sass/components/_footer.scss +16 -6
- data/_sass/components/_header.scss +26 -18
- data/_sass/components/_license.scss +1 -25
- data/_sass/components/_main.scss +13 -11
- data/_sass/components/_tags.scss +17 -36
- data/_sass/layout/{_error-404.scss → _404.scss} +2 -2
- data/_sass/layout/_all.scss +72 -63
- data/_sass/layout/_article.scss +44 -0
- data/_sass/layout/_home.scss +61 -52
- data/_sass/layout/_landing.scss +104 -0
- data/_sass/layout/_page.scss +155 -0
- data/_sass/{colors → skins}/_chocolate.scss +17 -6
- data/_sass/skins/_dark.scss +56 -0
- data/_sass/{colors → skins}/_default.scss +16 -5
- data/_sass/{colors → skins}/_forest.scss +16 -5
- data/_sass/{colors → skins}/_ocean.scss +16 -5
- data/_sass/{colors → skins}/_orange.scss +20 -9
- data/assets/android-chrome-192x192.png +0 -0
- data/assets/android-chrome-512x512.png +0 -0
- data/assets/apple-touch-icon.png +0 -0
- data/assets/browserconfig.xml +9 -0
- data/assets/css/main.scss +46 -0
- data/assets/favicon-16x16.png +0 -0
- data/assets/favicon-32x32.png +0 -0
- data/assets/favicon.ico +0 -0
- data/assets/images/logo/logo.svg +1 -1
- data/assets/mstile-144x144.png +0 -0
- data/assets/mstile-150x150.png +0 -0
- data/assets/mstile-310x150.png +0 -0
- data/assets/mstile-310x310.png +0 -0
- data/assets/mstile-70x70.png +0 -0
- data/assets/safari-pinned-tab.svg +38 -0
- data/assets/site.webmanifest +19 -0
- metadata +108 -76
- data/_includes/common-head.html +0 -10
- data/_includes/components/article-data.html +0 -55
- data/_includes/components/follow-me.html +0 -78
- data/_includes/components/footer.html +0 -10
- data/_includes/components/header.html +0 -42
- data/_includes/components/license.html +0 -26
- data/_includes/components/tags.html +0 -52
- data/_includes/head-icons-rel.html +0 -38
- data/_includes/icon/clear.svg +0 -3
- data/_includes/icon/link.svg +0 -1
- data/_includes/icon/menu.svg +0 -3
- data/_includes/icon/next.svg +0 -3
- data/_includes/icon/omit.svg +0 -1
- data/_includes/icon/previous.svg +0 -3
- data/_includes/icon/search.svg +0 -3
- data/_includes/scripts/all.html +0 -244
- data/_includes/scripts/common.html +0 -30
- data/_includes/scripts/data.html +0 -27
- data/_includes/scripts/home.html +0 -26
- data/_includes/scripts/page-post.html +0 -32
- data/_includes/scripts/post.html +0 -183
- data/_includes/utils/comment-disqus.html +0 -19
- data/_includes/utils/comment-gitalk.html +0 -25
- data/_includes/utils/google-analytics.html +0 -11
- data/_layouts/all.html +0 -20
- data/_layouts/error-404.html +0 -9
- data/_layouts/post.html +0 -60
- data/_sass/colors/_dark.scss +0 -45
- data/_sass/common/classes/_shape.scss +0 -19
- data/_sass/common/classes/_space.scss +0 -40
- data/_sass/components/_article.content.extra.scss +0 -41
- data/_sass/components/_article.data.scss +0 -36
- data/_sass/components/_pagination.scss +0 -19
- data/_sass/components/_toc.scss +0 -72
- data/_sass/layout/_default.scss +0 -19
- data/_sass/layout/_post.scss +0 -80
- data/assets/css/blog.scss +0 -41
- data/assets/images/logo/icon-120x120.png +0 -0
- data/assets/images/logo/icon-128x128.png +0 -0
- data/assets/images/logo/icon-150x150.png +0 -0
- data/assets/images/logo/icon-152x152.png +0 -0
- data/assets/images/logo/icon-167x167.png +0 -0
- data/assets/images/logo/icon-16x16.png +0 -0
- data/assets/images/logo/icon-180x180.png +0 -0
- data/assets/images/logo/icon-192x192.png +0 -0
- data/assets/images/logo/icon-310x150.png +0 -0
- data/assets/images/logo/icon-310x310.png +0 -0
- data/assets/images/logo/icon-48x48.png +0 -0
- data/assets/images/logo/icon-70x70.png +0 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
(function() {
|
2
|
+
var SOURCES = window.TEXT_VARIABLES.sources;
|
3
|
+
var TOC_SELECTOR = window.TEXT_VARIABLES.site.toc.selectors;
|
4
|
+
window.Lazyload.js(SOURCES.jquery, function() {
|
5
|
+
var $window = $(window);
|
6
|
+
var $articleContent = $('.js-article-content');
|
7
|
+
var $tocRoot = $('.js-toc-root'), $col2 = $('.js-col-2');
|
8
|
+
var toc;
|
9
|
+
var tocDisabled = false;
|
10
|
+
var hasSidebar = $('.js-page-root').hasClass('layout--page--sidebar');
|
11
|
+
var hasToc = $articleContent.find(TOC_SELECTOR).length > 0;
|
12
|
+
|
13
|
+
function disabled() {
|
14
|
+
return $col2.css('display') === 'none' || !hasToc;
|
15
|
+
}
|
16
|
+
|
17
|
+
tocDisabled = disabled();
|
18
|
+
|
19
|
+
setTimeout(function() {
|
20
|
+
toc = $tocRoot.toc({
|
21
|
+
selectors: TOC_SELECTOR,
|
22
|
+
container: $articleContent,
|
23
|
+
scrollTarget: hasSidebar ? '.js-page-main' : null,
|
24
|
+
scroller: hasSidebar ? '.js-page-main' : null,
|
25
|
+
disabled: tocDisabled
|
26
|
+
});
|
27
|
+
}, 1000);
|
28
|
+
|
29
|
+
$window.on('resize', window.throttle(function() {
|
30
|
+
tocDisabled = disabled();
|
31
|
+
toc && toc.setOptions({
|
32
|
+
disabled: tocDisabled
|
33
|
+
});
|
34
|
+
}, 100));
|
35
|
+
|
36
|
+
});
|
37
|
+
})();
|
@@ -0,0 +1,103 @@
|
|
1
|
+
(function() {
|
2
|
+
var SOURCES = window.TEXT_VARIABLES.sources;
|
3
|
+
window.Lazyload.js(SOURCES.jquery, function() {
|
4
|
+
var $window = $(window), $root, $scrollTarget, $scroller, $scroll;
|
5
|
+
var rootTop, rootLeft, rootHeight, scrollBottom, rootBottomTop, lastScrollTop;
|
6
|
+
var offsetBottom = 0, disabled = false, scrollTarget = window, scroller = 'html, body', scroll = window.document;
|
7
|
+
var hasInit = false, isOverallScroller = true;
|
8
|
+
|
9
|
+
function setOptions(options) {
|
10
|
+
var _options = options || {};
|
11
|
+
_options.offsetBottom && (offsetBottom = _options.offsetBottom);
|
12
|
+
_options.scrollTarget && (scrollTarget = _options.scrollTarget);
|
13
|
+
_options.scroller && (scroller = _options.scroller);
|
14
|
+
_options.scroll && (scroll = _options.scroll);
|
15
|
+
_options.disabled !== undefined && (disabled = _options.disabled);
|
16
|
+
$scrollTarget = $(scrollTarget);
|
17
|
+
$scroller = $(scroller);
|
18
|
+
isOverallScroller = window.isOverallScroller($scroller[0]);
|
19
|
+
$scroll = $(scroll);
|
20
|
+
calc(true);
|
21
|
+
}
|
22
|
+
function initData() {
|
23
|
+
top();
|
24
|
+
rootHeight = $root.outerHeight();
|
25
|
+
rootTop = $root.offset().top + (isOverallScroller ? 0 : $scroller.scrollTop());
|
26
|
+
rootLeft = $root.offset().left;
|
27
|
+
}
|
28
|
+
function calc(needInitData) {
|
29
|
+
needInitData && initData();
|
30
|
+
scrollBottom = $scroll.outerHeight() - offsetBottom - rootHeight;
|
31
|
+
rootBottomTop = scrollBottom - rootTop;
|
32
|
+
}
|
33
|
+
function top() {
|
34
|
+
$root.removeClass('fixed').css({
|
35
|
+
left: 0,
|
36
|
+
top: 0
|
37
|
+
});
|
38
|
+
}
|
39
|
+
function fixed() {
|
40
|
+
$root.addClass('fixed').css({
|
41
|
+
left: rootLeft + 'px',
|
42
|
+
top: 0
|
43
|
+
});
|
44
|
+
}
|
45
|
+
function bottom() {
|
46
|
+
$root.removeClass('fixed').css({
|
47
|
+
left: 0,
|
48
|
+
top: rootBottomTop + 'px'
|
49
|
+
});
|
50
|
+
}
|
51
|
+
function setState(force) {
|
52
|
+
force !== true && (force = false);
|
53
|
+
var scrollTop = $scrollTarget.scrollTop();
|
54
|
+
if (scrollTop >= rootTop && scrollTop <= scrollBottom) {
|
55
|
+
(!force && lastScrollTop >= rootTop && lastScrollTop <= scrollBottom) || fixed();
|
56
|
+
} else if (scrollTop < rootTop) {
|
57
|
+
(!force && lastScrollTop < rootTop) || top();
|
58
|
+
} else {
|
59
|
+
(!force && lastScrollTop > scrollBottom) || bottom();
|
60
|
+
}
|
61
|
+
lastScrollTop = scrollTop;
|
62
|
+
}
|
63
|
+
function init() {
|
64
|
+
if(!hasInit) {
|
65
|
+
var interval, timeout;
|
66
|
+
calc(true); setState();
|
67
|
+
// run calc every 1.5 seconds
|
68
|
+
interval = setInterval(function() {
|
69
|
+
calc();
|
70
|
+
}, 1500);
|
71
|
+
timeout = setTimeout(function() {
|
72
|
+
clearInterval(interval);
|
73
|
+
}, 50000);
|
74
|
+
window.pageLoad.then(function() {
|
75
|
+
clearInterval(interval);
|
76
|
+
clearTimeout(timeout);
|
77
|
+
});
|
78
|
+
$scrollTarget.on('scroll', function() {
|
79
|
+
disabled || setState();
|
80
|
+
});
|
81
|
+
$window.on('resize', window.throttle(function() {
|
82
|
+
disabled || (calc(true), setState(true));
|
83
|
+
}, 100));
|
84
|
+
hasInit = true;
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
function affix(options) {
|
89
|
+
$root = this;
|
90
|
+
setOptions(options);
|
91
|
+
if (!disabled) {
|
92
|
+
init();
|
93
|
+
}
|
94
|
+
$window.on('resize', window.throttle(function() {
|
95
|
+
init();
|
96
|
+
}, 200));
|
97
|
+
return {
|
98
|
+
setOptions: setOptions
|
99
|
+
};
|
100
|
+
}
|
101
|
+
$.fn.affix = affix;
|
102
|
+
});
|
103
|
+
})();
|
@@ -1,65 +1,60 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
window.Lazyload = (function(doc) {
|
9
|
-
var queue = {js: [], css: []}, sources = {js: {}, css: {}}, context = this;
|
10
|
-
var Set = (function() {
|
11
|
-
var add = function(item) {
|
12
|
-
var i, data = this._data;
|
13
|
-
for (i = 0; i < data.length; i++) {
|
14
|
-
if (data[i] === item) {
|
15
|
-
return;
|
16
|
-
}
|
1
|
+
(function() {
|
2
|
+
var Set = (function() {
|
3
|
+
var add = function(item) {
|
4
|
+
var i, data = this._data;
|
5
|
+
for (i = 0; i < data.length; i++) {
|
6
|
+
if (data[i] === item) {
|
7
|
+
return;
|
17
8
|
}
|
18
|
-
this.size ++;
|
19
|
-
data.push(item);
|
20
|
-
return data;
|
21
9
|
}
|
10
|
+
this.size ++;
|
11
|
+
data.push(item);
|
12
|
+
return data;
|
13
|
+
};
|
22
14
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
15
|
+
var Set = function(data) {
|
16
|
+
this.size = 0;
|
17
|
+
this._data = [];
|
18
|
+
var i;
|
19
|
+
if (data.length > 0) {
|
20
|
+
for (i = 0; i < data.length; i++) {
|
21
|
+
add.call(this, data[i]);
|
30
22
|
}
|
31
23
|
}
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
24
|
+
};
|
25
|
+
Set.prototype.add = add;
|
26
|
+
Set.prototype.get = function(index) { return this._data[index]; };
|
27
|
+
Set.prototype.has = function(item) {
|
28
|
+
var i, data = this._data;
|
29
|
+
for (i = 0; i < data.length; i++) {
|
30
|
+
if (this.get(i) === item) {
|
31
|
+
return true;
|
40
32
|
}
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
33
|
+
}
|
34
|
+
return false;
|
35
|
+
};
|
36
|
+
Set.prototype.is = function(map) {
|
37
|
+
if (map._data.length !== this._data.length) { return false; }
|
38
|
+
var i, j, flag, tData = this._data, mData = map._data;
|
39
|
+
for (i = 0; i < tData.length; i++) {
|
40
|
+
for (flag = false, j = 0; j < mData.length; j++) {
|
41
|
+
if (tData[i] === mData[j]) {
|
42
|
+
flag = true;
|
43
|
+
break;
|
52
44
|
}
|
53
|
-
if (!flag) { return false; }
|
54
45
|
}
|
55
|
-
return
|
56
|
-
}
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
return
|
61
|
-
}
|
46
|
+
if (!flag) { return false; }
|
47
|
+
}
|
48
|
+
return true;
|
49
|
+
};
|
50
|
+
Set.prototype.values = function() {
|
51
|
+
return this._data;
|
52
|
+
};
|
53
|
+
return Set;
|
54
|
+
})();
|
62
55
|
|
56
|
+
window.Lazyload = (function(doc) {
|
57
|
+
var queue = {js: [], css: []}, sources = {js: {}, css: {}}, context = this;
|
63
58
|
var createNode = function(name, attrs) {
|
64
59
|
var node = doc.createElement(name), attr;
|
65
60
|
for (attr in attrs) {
|
@@ -68,10 +63,9 @@
|
|
68
63
|
}
|
69
64
|
}
|
70
65
|
return node;
|
71
|
-
}
|
72
|
-
var end = function(type, url
|
73
|
-
var s, q, qi, cbs, i, j, cur,
|
74
|
-
val, flag;
|
66
|
+
};
|
67
|
+
var end = function(type, url) {
|
68
|
+
var s, q, qi, cbs, i, j, cur, val, flag;
|
75
69
|
if (type === 'js' || type ==='css') {
|
76
70
|
s = sources[type], q = queue[type];
|
77
71
|
s[url] = true;
|
@@ -81,7 +75,7 @@
|
|
81
75
|
qi = cur, val = qi.urls.values();
|
82
76
|
qi && (cbs = qi.callbacks);
|
83
77
|
for (flag = true, j = 0; j < val.length; j++) {
|
84
|
-
cur = val[j]
|
78
|
+
cur = val[j];
|
85
79
|
if (!s[cur]) {
|
86
80
|
flag = false;
|
87
81
|
}
|
@@ -97,7 +91,7 @@
|
|
97
91
|
}
|
98
92
|
};
|
99
93
|
var load = function(type, urls, callback) {
|
100
|
-
var s,
|
94
|
+
var s, q, qi, node, i, cur,
|
101
95
|
_urls = typeof urls === 'string' ? new Set([urls]) : new Set(urls), val, url;
|
102
96
|
if (type === 'js' || type ==='css') {
|
103
97
|
s = sources[type], q = queue[type];
|
@@ -127,7 +121,7 @@
|
|
127
121
|
node.onload = (function(type, url) {
|
128
122
|
return function() {
|
129
123
|
end(type, url);
|
130
|
-
}
|
124
|
+
};
|
131
125
|
})(type, url);
|
132
126
|
(doc.head || doc.body).appendChild(node);
|
133
127
|
s[url] = false;
|
@@ -146,35 +140,4 @@
|
|
146
140
|
}
|
147
141
|
};
|
148
142
|
})(this.document);
|
149
|
-
|
150
|
-
window.throttle = function(func, wait) {
|
151
|
-
var args, result, thisArg, timeoutId, lastCalled = 0;
|
152
|
-
|
153
|
-
function trailingCall() {
|
154
|
-
lastCalled = new Date;
|
155
|
-
timeoutId = null;
|
156
|
-
result = func.apply(thisArg, args);
|
157
|
-
}
|
158
|
-
return function() {
|
159
|
-
var now = new Date,
|
160
|
-
remaining = wait - (now - lastCalled);
|
161
|
-
|
162
|
-
args = arguments;
|
163
|
-
thisArg = this;
|
164
|
-
|
165
|
-
if (remaining <= 0) {
|
166
|
-
clearTimeout(timeoutId);
|
167
|
-
timeoutId = null;
|
168
|
-
lastCalled = now;
|
169
|
-
result = func.apply(thisArg, args);
|
170
|
-
} else if (!timeoutId) {
|
171
|
-
timeoutId = setTimeout(trailingCall, remaining);
|
172
|
-
}
|
173
|
-
return result;
|
174
|
-
};
|
175
|
-
};
|
176
|
-
|
177
|
-
window.hasEvent = function(event) {
|
178
|
-
return 'on'.concat(event) in window.document;
|
179
|
-
}
|
180
|
-
</script>
|
143
|
+
})();
|
@@ -0,0 +1,13 @@
|
|
1
|
+
(function() {
|
2
|
+
var SOURCES = window.TEXT_VARIABLES.sources;
|
3
|
+
window.Lazyload.js(SOURCES.jquery, function() {
|
4
|
+
function scrollToAnchor(anchor, duration, callback) {
|
5
|
+
var $root = this;
|
6
|
+
$root.animate({ scrollTop: $(anchor).position().top }, duration, function() {
|
7
|
+
window.history.replaceState(null, '', window.location.href.split('#')[0] + anchor);
|
8
|
+
callback && callback();
|
9
|
+
});
|
10
|
+
}
|
11
|
+
$.fn.scrollToAnchor = scrollToAnchor;
|
12
|
+
});
|
13
|
+
})();
|
@@ -0,0 +1,28 @@
|
|
1
|
+
(function() {
|
2
|
+
window.throttle = function(func, wait) {
|
3
|
+
var args, result, thisArg, timeoutId, lastCalled = 0;
|
4
|
+
|
5
|
+
function trailingCall() {
|
6
|
+
lastCalled = new Date;
|
7
|
+
timeoutId = null;
|
8
|
+
result = func.apply(thisArg, args);
|
9
|
+
}
|
10
|
+
return function() {
|
11
|
+
var now = new Date,
|
12
|
+
remaining = wait - (now - lastCalled);
|
13
|
+
|
14
|
+
args = arguments;
|
15
|
+
thisArg = this;
|
16
|
+
|
17
|
+
if (remaining <= 0) {
|
18
|
+
clearTimeout(timeoutId);
|
19
|
+
timeoutId = null;
|
20
|
+
lastCalled = now;
|
21
|
+
result = func.apply(thisArg, args);
|
22
|
+
} else if (!timeoutId) {
|
23
|
+
timeoutId = setTimeout(trailingCall, remaining);
|
24
|
+
}
|
25
|
+
return result;
|
26
|
+
};
|
27
|
+
};
|
28
|
+
})();
|
@@ -0,0 +1,106 @@
|
|
1
|
+
(function() {
|
2
|
+
var SOURCES = window.TEXT_VARIABLES.sources;
|
3
|
+
window.Lazyload.js(SOURCES.jquery, function() {
|
4
|
+
var $window = $(window), $root, $scrollTarget, $scroller, $tocUl = $('<ul class="toc"></ul>'), $tocLi, $headings, $activeLast, $activeCur;
|
5
|
+
var selectors = 'h1,h2,h3', container = 'body', scrollTarget = window, scroller = 'html, body', disabled = false;
|
6
|
+
var headingsPos, scrolling = false, rendered = false, hasInit = false;
|
7
|
+
function setOptions(options) {
|
8
|
+
var _options = options || {};
|
9
|
+
_options.selectors && (selectors = _options.selectors);
|
10
|
+
_options.container && (container = _options.container);
|
11
|
+
_options.scrollTarget && (scrollTarget = _options.scrollTarget);
|
12
|
+
_options.scroller && (scroller = _options.scroller);
|
13
|
+
_options.disabled !== undefined && (disabled = _options.disabled);
|
14
|
+
$headings = $(container).find(selectors);
|
15
|
+
$scrollTarget = $(scrollTarget);
|
16
|
+
$scroller = $(scroller);
|
17
|
+
calc();
|
18
|
+
}
|
19
|
+
function calc() {
|
20
|
+
headingsPos = [];
|
21
|
+
$headings.each(function() {
|
22
|
+
headingsPos.push(Math.floor($(this).position().top));
|
23
|
+
});
|
24
|
+
}
|
25
|
+
function setState(element, disabled) {
|
26
|
+
var scrollTop = $scroller.scrollTop(), i;
|
27
|
+
if (disabled || !headingsPos || headingsPos.length < 1) { return; }
|
28
|
+
if (element) {
|
29
|
+
$activeCur = element;
|
30
|
+
} else {
|
31
|
+
for (i = 0; i < headingsPos.length; i++) {
|
32
|
+
if (scrollTop >= headingsPos[i]) {
|
33
|
+
$activeCur = $tocLi.eq(i);
|
34
|
+
} else {
|
35
|
+
$activeCur || ($activeCur = $tocLi.eq(i));
|
36
|
+
break;
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
40
|
+
$activeLast && $activeLast.removeClass('active');
|
41
|
+
($activeLast = $activeCur).addClass('active');
|
42
|
+
}
|
43
|
+
function render() {
|
44
|
+
if(!rendered) {
|
45
|
+
$root.append($tocUl);
|
46
|
+
$headings.each(function() {
|
47
|
+
var $this = $(this);
|
48
|
+
$tocUl.append($('<li></li>').addClass('toc-' + $this.prop('tagName').toLowerCase())
|
49
|
+
.append($('<a></a>').text($this.text()).attr('href', '#' + $this.prop('id'))));
|
50
|
+
});
|
51
|
+
$tocLi = $tocUl.children('li');
|
52
|
+
$tocUl.on('click', 'a', function(e) {
|
53
|
+
e.preventDefault();
|
54
|
+
var $this = $(this);
|
55
|
+
scrolling = true;
|
56
|
+
setState($this.parent());
|
57
|
+
$scroller.scrollToAnchor($this.attr('href'), 400, function() {
|
58
|
+
scrolling = false;
|
59
|
+
});
|
60
|
+
});
|
61
|
+
}
|
62
|
+
rendered = true;
|
63
|
+
}
|
64
|
+
function init() {
|
65
|
+
var interval, timeout;
|
66
|
+
if(!hasInit) {
|
67
|
+
render(); calc(); setState(null, scrolling);
|
68
|
+
// run calc every 1.5 seconds
|
69
|
+
interval = setInterval(function() {
|
70
|
+
calc();
|
71
|
+
}, 1500);
|
72
|
+
timeout = setTimeout(function() {
|
73
|
+
clearInterval(interval);
|
74
|
+
}, 50000);
|
75
|
+
window.pageLoad.then(function() {
|
76
|
+
clearInterval(interval);
|
77
|
+
clearTimeout(timeout);
|
78
|
+
});
|
79
|
+
$scrollTarget.on('scroll', function() {
|
80
|
+
disabled || setState(null, scrolling);
|
81
|
+
});
|
82
|
+
$window.on('resize', window.throttle(function() {
|
83
|
+
if (!disabled) {
|
84
|
+
render(); calc(); setState(null, scrolling);
|
85
|
+
}
|
86
|
+
}, 100));
|
87
|
+
}
|
88
|
+
hasInit = true;
|
89
|
+
}
|
90
|
+
function toc(options) {
|
91
|
+
$root = this;
|
92
|
+
setOptions(options);
|
93
|
+
if (!disabled) {
|
94
|
+
init();
|
95
|
+
}
|
96
|
+
$window.on('resize', window.throttle(function() {
|
97
|
+
init();
|
98
|
+
}, 200));
|
99
|
+
return {
|
100
|
+
setOptions: setOptions
|
101
|
+
};
|
102
|
+
}
|
103
|
+
toc.setOptions = setOptions;
|
104
|
+
$.fn.toc = toc;
|
105
|
+
});
|
106
|
+
})();
|