@@ -11,17 +11,25 @@ const initToc = () => {
11
11
document . querySelector ( 'nav.onthispage' ) . classList . add ( 'no_sidebar_content' )
12
12
}
13
13
14
- // Initialize the TOC bot
15
- tocbot . init ( {
16
- tocSelector : 'nav.onthispage' ,
17
- contentSelector : '.c-textbook__content' ,
18
- headingSelector : 'h1, h2, h3' ,
19
- orderedList : false ,
20
- collapseDepth : 6 ,
21
- listClass : 'toc__menu' ,
22
- activeListItemClass : " " , // Not using, can't be empty
23
- activeLinkClass : " " , // Not using, can't be empty
24
- } ) ;
14
+ // Initialize the TOC bot if we have TOC headers
15
+ const tocContent = '.c-textbook__content' ;
16
+ const tocHeaders = 'h1, h2, h3' ;
17
+ var headers = document . querySelector ( tocContent ) . querySelectorAll ( tocHeaders ) ;
18
+ if ( headers . length > 0 ) {
19
+ document . querySelector ( 'aside.sidebar__right' ) . classList . remove ( 'hidden' ) ;
20
+ tocbot . init ( {
21
+ tocSelector : 'nav.onthispage' ,
22
+ contentSelector : tocContent ,
23
+ headingSelector : tocHeaders ,
24
+ orderedList : false ,
25
+ collapseDepth : 6 ,
26
+ listClass : 'toc__menu' ,
27
+ activeListItemClass : " " , // Not using, can't be empty
28
+ activeLinkClass : " " , // Not using, can't be empty
29
+ } ) ;
30
+ } else {
31
+ document . querySelector ( 'aside.sidebar__right' ) . classList . add ( 'hidden' ) ;
32
+ }
25
33
26
34
// Disable Turbolinks for TOC links
27
35
document . querySelectorAll ( '.toc-list-item a' )
0 commit comments