Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c233950

Browse files
committed
Fix TOC TypeError when current section is null, and only update current class when there's a change (as LI will never equal H2/H3).
1 parent a49eb80 commit c233950

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

‎docs_js_css/toc.js‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,21 @@ class TOC {
6969
if (top == TOC.lastTop) return;
7070
TOC.lastTop = top;
7171

72-
let minDiff = 1000000000, current = null;
72+
let minDiff = 1000000000, currentId = null;
7373
for (let section of TOC.sections) {
7474
let ot = section.offsetTop - 50;
7575
if (ot > top) continue;
7676
let diff = top - ot;
7777
if (diff < minDiff) {
7878
minDiff = diff;
79-
current = section;
79+
currentId = section.id;
8080
}
8181
}
82-
if (TOC.lastLi != current) {
82+
83+
let currentLi = currentId ? document.querySelector(`#li_${currentId}`) : null;
84+
if (TOC.lastLi != currentLi) {
8385
if (TOC.lastLi != null) TOC.lastLi.classList.remove('current');
84-
TOC.lastLi = document.getElementById('li_'+current.id);
86+
TOC.lastLi = currentLi||null;
8587
if (TOC.lastLi != null) TOC.lastLi.classList.add('current');
8688
}
8789
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /