Bläddra i källkod

fix link highlighting in manual (#23113)

Greggman 3 år sedan
förälder
incheckning
f87682a5f7
1 ändrade filer med 29 tillägg och 10 borttagningar
  1. 29 10
      manual/index.html

+ 29 - 10
manual/index.html

@@ -151,7 +151,12 @@
 
 			// Activate content and title change on browser navigation
 
-			window.onpopstate = createNewIframe;
+			window.onpopstate = function() {
+
+				updateNavigation();
+				createNewIframe();
+
+			}
 
 			// Create the navigation panel and configure the iframe
 
@@ -189,14 +194,7 @@
 				window.location.hash = pageURL;
 				panel.classList.remove( 'open' );
 
-
-				content.querySelectorAll( 'a' ).forEach( function ( item ) {
-
-					item.classList.remove( 'selected' );
-
-				} );
-
-				link.classList.add( 'selected' );
+				updateNavigation();
 
 			} );
 
@@ -224,7 +222,7 @@
 			}
 
 			const categories = list[ language ];
-			const selectedPage = window.location.hash.substring( 1 );
+			const selectedPage = window.location.hash.substring( 1 ).replace( /\.html$/, '' );
 
 			for ( const category in categories ) {
 
@@ -286,6 +284,26 @@
 
 		}
 
+		function updateNavigation() {
+
+			const selectedPage = window.location.hash.substring( 1 ).replace( /\.html$/, '' );
+
+			content.querySelectorAll( 'a' ).forEach( function ( item ) {
+
+				if ( item.href.includes( selectedPage ) ) {
+
+					item.classList.add( 'selected' );
+
+				} else {
+
+					item.classList.remove( 'selected' );
+
+				}
+
+			} );
+
+		}
+
 		// Auto change language url. If a reader open a document in English, when he click "zh", the document he read will auto change into Chinese version
 
 		function autoChangeUrlLanguage( language ) {
@@ -430,6 +448,7 @@
 					} else {
 
 						window.location.hash = newHash;
+						updateNavigation();
 						createNewIframe();
 
 					}