1+ ( function ( ) {
2+ // for sticky table of contents
3+ const tocBody = document . querySelector ( ".docs-aside #js-toc-panel" ) ;
4+ const options = {
5+ root : null ,
6+ rootMargin : `0px 0px -90% 0px` ,
7+ threshold : 1.0 ,
8+ } ;
9+ const activeClassName = "active" ;
10+ const observer = new IntersectionObserver ( ( entries ) => {
11+ entries . forEach ( ( entry ) => {
12+ if ( entry . isIntersecting ) {
13+ const activeAnchor = tocBody . querySelector (
14+ `a.${ activeClassName } `
15+ ) ;
16+ if ( activeAnchor ) {
17+ activeAnchor . parentNode . classList . remove ( activeClassName ) ;
18+ activeAnchor . classList . remove ( activeClassName ) ;
19+ }
20+
21+ const nextActiveAnchor = tocBody . querySelector (
22+ `a[href="#${ entry . target . id } "]`
23+ ) ;
24+ if ( nextActiveAnchor ) {
25+ nextActiveAnchor . parentNode . classList . add ( activeClassName ) ;
26+ nextActiveAnchor . classList . add ( activeClassName ) ;
27+ }
28+ }
29+ } ) ;
30+ } , options ) ;
31+ if ( window . matchMedia ( "(min-width: 1400px)" ) . matches ) {
32+ document
33+ . querySelectorAll (
34+ "#main > div > h2[id], #main > div > h3[id], #main > div > h4[id]" // only h2, h3, h4 are shown in toc
35+ )
36+ . forEach ( ( el ) => observer . observe ( el ) ) ;
37+ }
38+ } ) ( ) ;
39+
140( function ( ) {
241 var toc_trigger = document . getElementById ( "js-toc-label" ) ,
342 toc = document . getElementById ( "js-toc-panel" ) ,
@@ -279,4 +318,4 @@ if (index) {
279318
280319document . addEventListener ( "DOMContentLoaded" , ( ) => {
281320 anchors . add ( ".docs-content h2:not(.c-toc__label), .docs-content h3, .docs-content h4" ) ;
282- } ) ;
321+ } ) ;
0 commit comments