1
+ navigationPageText = fetch ( pathToRoot + "navigation.html" ) . then ( response => response . text ( ) )
2
+
3
+ window . addEventListener ( 'DOMContentLoaded' , ( ) => {
4
+ navigationPageText . then ( data => {
5
+ document . getElementById ( "sideMenu" ) . innerHTML = data ;
6
+ } ) . then ( ( ) => {
7
+ document . querySelectorAll ( ".overview > a" ) . forEach ( link => {
8
+ link . setAttribute ( "href" , pathToRoot + link . getAttribute ( "href" ) ) ;
9
+ } )
10
+ } ) . then ( ( ) => {
11
+ document . querySelectorAll ( ".sideMenuPart" ) . forEach ( nav => {
12
+ if ( ! nav . classList . contains ( "hidden" ) ) nav . classList . add ( "hidden" )
13
+ } )
14
+ } ) . then ( ( ) => {
15
+ revealNavigationForCurrentPage ( )
16
+ } )
17
+
18
+ /* Smooth scrolling support for going to the top of the page */
19
+ document . querySelectorAll ( '.footer a[href^="#"]' ) . forEach ( anchor => {
20
+ anchor . addEventListener ( 'click' , function ( e ) {
21
+ e . preventDefault ( ) ;
22
+
23
+ document . querySelector ( this . getAttribute ( 'href' ) ) . scrollIntoView ( {
24
+ behavior : 'smooth'
25
+ } ) ;
26
+ } ) ;
27
+ } ) ;
28
+ } )
29
+
30
+ revealNavigationForCurrentPage = ( ) => {
31
+ let pageId = document . getElementById ( "content" ) . attributes [ "pageIds" ] . value . toString ( ) ;
32
+ let parts = document . querySelectorAll ( ".sideMenuPart" ) ;
33
+ let found = 0 ;
34
+ do {
35
+ parts . forEach ( part => {
36
+ if ( part . attributes [ 'pageId' ] . value . indexOf ( pageId ) !== - 1 && found === 0 ) {
37
+ found = 1 ;
38
+ if ( part . classList . contains ( "hidden" ) ) {
39
+ part . classList . remove ( "hidden" ) ;
40
+ part . setAttribute ( 'data-active' , "" ) ;
41
+ }
42
+ revealParents ( part )
43
+ }
44
+ } ) ;
45
+ pageId = pageId . substring ( 0 , pageId . lastIndexOf ( "/" ) )
46
+ } while ( pageId . indexOf ( "/" ) !== - 1 && found === 0 )
47
+ } ;
48
+
49
+ revealParents = ( part ) => {
50
+ if ( part . classList . contains ( "sideMenuPart" ) ) {
51
+ if ( part . classList . contains ( "hidden" ) ) part . classList . remove ( "hidden" ) ;
52
+ revealParents ( part . parentNode )
53
+ }
54
+ } ;
0 commit comments