blob: 518850a6d14f18e317a8e18fc3c15ef2b452a94d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
var spy = function () {
var elems = document.querySelectorAll("h1, h2, h3, h4, h5, h6");
if (elems.length == 0) {
return;
}
var supportPageOffset = window.pageXOffset !== undefined;
var isCSS1Compat = ((document.compatMode || "") === "CSS1Compat");
var currentTop = supportPageOffset ? window.pageYOffset : isCSS1Compat ? document.documentElement.scrollTop : document.body.scrollTop;
var currentBottom = currentTop + window.height;
var pageBottom = window.pageBottom;
var meetUnread = false
var currentIndex = -1
elems.forEach(function (elem, idx) {
var elemTop = elem.offsetTop;
var id = elem.getAttribute('id');
//console.log(id,elem.offsetTop)
var navElem = document.getElementById(id + '-nav');
if (navElem==null) {
return
}
if (currentTop >= elemTop || currentBottom >= pageBottom) {
navElem.classList.add('toc-active');
} else {
if (meetUnread == false) {
meetUnread = true
currentIndex = idx - 1
}
navElem.classList.remove('toc-active');
}
})
document.querySelectorAll(".collapse").forEach(function(elem){
elem.classList.remove("collapse");
})
}
var onNavClick = function () {
}
/*$().ready(function () {
$(".collapse").each(function (idx) {
$(this).collapse("show");
});
//spy();
//$(window).bind('scroll', throttle(spy));
});*/
function throttle(func, timeout = 250) {
let last;
let timer;
return function () {
const context = this;
const args = arguments;
const now = +new Date();
if (last && now < last + timeout) {
clearTimeout(timer)
timer = setTimeout(function () {
last = now
func.apply(context, args)
}, timeout)
} else {
last = now
func.apply(context, args)
}
}
}
|