-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Docs: Highlight selected links and move them into view. (#30460)
- Loading branch information
Showing
3 changed files
with
117 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
const panel = document.getElementById( 'panel' ); | ||
const panelScrim = document.getElementById( 'panelScrim' ); | ||
const expandButton = document.getElementById( 'expandButton' ); | ||
const clearSearchButton = document.getElementById( 'clearSearchButton' ); | ||
const filterInput = document.getElementById( 'filterInput' ); | ||
|
||
// Functionality for hamburger button (on small devices) | ||
|
||
expandButton.onclick = function ( event ) { | ||
|
||
event.preventDefault(); | ||
panel.classList.toggle( 'open' ); | ||
|
||
}; | ||
|
||
panelScrim.onclick = function ( event ) { | ||
|
||
event.preventDefault(); | ||
panel.classList.toggle( 'open' ); | ||
|
||
}; | ||
|
||
// Functionality for search/filter input field | ||
|
||
filterInput.onfocus = function () { | ||
|
||
panel.classList.add( 'searchFocused' ); | ||
|
||
}; | ||
|
||
filterInput.onblur = function () { | ||
|
||
if ( filterInput.value === '' ) { | ||
|
||
panel.classList.remove( 'searchFocused' ); | ||
|
||
} | ||
|
||
}; | ||
|
||
filterInput.oninput = function () { | ||
|
||
const term = filterInput.value.trim(); | ||
|
||
// eslint-disable-next-line no-undef | ||
search( term ); // defined in search.js | ||
|
||
}; | ||
|
||
clearSearchButton.onclick = function () { | ||
|
||
filterInput.value = ''; | ||
filterInput.focus(); | ||
// eslint-disable-next-line no-undef | ||
hideSearch(); // defined in search.js | ||
|
||
}; | ||
|
||
// | ||
|
||
window.addEventListener( 'DOMContentLoaded', updateNavigation ); | ||
window.addEventListener( 'hashchange', updateNavigation ); | ||
|
||
function updateNavigation() { | ||
|
||
// unselected elements | ||
|
||
const selected = document.querySelectorAll( 'nav a.selected' ); | ||
selected.forEach( link => link.classList.remove( 'selected' ) ); | ||
|
||
// determine target | ||
|
||
const filename = window.location.pathname.split( '/' ).pop(); | ||
const pagename = filename.split( '.' )[ 0 ]; | ||
|
||
let target = pagename; | ||
|
||
if ( pagename === 'global' ) { | ||
|
||
target = window.location.hash.split( '#' ).pop(); | ||
|
||
} | ||
|
||
if ( target === '' ) return; | ||
|
||
// select target and move into view | ||
|
||
const liElement = document.querySelector( `li[data-name="${target}"]` ); | ||
|
||
if ( liElement !== null ) { | ||
|
||
const aElement = liElement.firstChild; | ||
|
||
aElement.scrollIntoView( { block: 'center' } ); | ||
aElement.classList.add( 'selected' ); | ||
|
||
} | ||
|
||
} | ||
|
||
// eslint-disable-next-line no-undef | ||
prettyPrint(); | ||
|
||
console.log( [ | ||
' __ __', | ||
' __/ __\\ / __\\__ ____ _____ _____', | ||
'/ __/ /\\/ / /___\\/ ____\\/ _____\\/ _____\\', | ||
'\\/_ __/ / _ / / __/ / __ / / __ /_ __ _____', | ||
'/ / / / / / / / / / / / ___/ / ___/\\ _\\/ __\\/ _____\\', | ||
'\\/__/ \\/__/\\/__/\\/__/ \\/_____/\\/_____/\\/__/ / / / ___/', | ||
' / __/ / \\__ \\', | ||
' \\/____/\\/_____/' | ||
].join( '\n' ) ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters