Skip to content

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-
letminDiff=1000000000,current=null;
72+
letminDiff=1000000000,currentId=null;
7373
for(letsectionofTOC.sections){
7474
letot=section.offsetTop-50;
7575
if(ot>top)continue;
7676
letdiff=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+
letcurrentLi=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)