Browse Source

Docs and examples switching retains filter (#22507)

* Docs and examples switching retains filter

* Using the same code formatting

* Last code formatting fix

* Simplified code
Octo 3 years ago
parent
commit
3877bba9e3
2 changed files with 52 additions and 1 deletions
  1. 26 0
      docs/index.html
  2. 26 1
      examples/index.html

+ 26 - 0
docs/index.html

@@ -55,6 +55,9 @@
 		const filterInput = document.getElementById( 'filterInput' );
 		let iframe = document.querySelector( 'iframe' );
 
+		const sectionLink = document.querySelector( '#sections > a' );
+		const sectionDefaultHref = sectionLink.href;
+
 		const pageProperties = {};
 		const titles = {};
 		const categoryElements = [];
@@ -185,6 +188,10 @@
 
 				updateFilter();
 
+			} else {
+
+				updateLink( '' );
+
 			}
 
 		}
@@ -387,6 +394,25 @@
 
 			displayFilteredPanel();
 
+			updateLink( v );
+
+		}
+
+		function updateLink( search ) {
+
+			// update examples link
+
+			if ( search ) {
+
+				let link = sectionLink.href.split( /[?#]/ )[ 0 ];
+				sectionLink.href = `${link}?q=${search}`;
+
+			} else {
+
+				sectionLink.href = sectionDefaultHref;
+
+			}
+
 		}
 
 		function displayFilteredPanel() {

+ 26 - 1
examples/index.html

@@ -53,9 +53,11 @@
 		const expandButton = document.getElementById( 'expandButton' );
 		const viewSrcButton = document.getElementById( 'button' );
 		const panelScrim = document.getElementById( 'panelScrim' );
-
 		const previewsToggler = document.getElementById( 'previewsToggler' );
 
+		const sectionLink = document.querySelector( '#sections > a' );
+		const sectionDefaultHref = sectionLink.href;
+
 		const links = {};
 		const validRedirects = new Map();
 		const container = document.createElement( 'div' );
@@ -120,6 +122,10 @@
 
 				updateFilter( files, tags );
 
+			} else {
+
+				updateLink( '' );
+
 			}
 
 			// Events
@@ -267,6 +273,25 @@
 
 			layoutList( files );
 
+			updateLink( v );
+
+		}
+
+		function updateLink( search ) {
+
+			// update docs link
+
+			if ( search ) {
+
+				let link = sectionLink.href.split( /[?#]/ )[ 0 ];
+				sectionLink.href = `${link}?q=${search}`;
+
+			} else {
+
+				sectionLink.href = sectionDefaultHref;
+
+			}
+
 		}
 
 		function filterExample( file, exp, tags ) {