Twenty Twenty-One: Check if anchor exists before triggering in-page navigation.

This prevents JavaScript errors when using hash in URLs without matching them to any existing anchor in the page.

Props rixeo, sabernhardt, pbearne.
Fixes #53619.

Built from https://develop.svn.wordpress.org/trunk@52213


git-svn-id: http://core.svn.wordpress.org/trunk@51805 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
audrasjb 2021-11-19 13:03:01 +00:00
parent 9f91a2a245
commit 096e903010
2 changed files with 4 additions and 2 deletions

View File

@ -180,7 +180,9 @@ function twentytwentyoneExpandSubMenu( el ) { // jshint ignore:line
// Wait 550 and scroll to the anchor.
setTimeout(function () {
var anchor = document.getElementById(event.target.hash.slice(1));
anchor.scrollIntoView();
if ( anchor ) {
anchor.scrollIntoView();
}
}, 550);
}
} );

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.9-alpha-52212';
$wp_version = '5.9-alpha-52213';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.