Twenty Twenty-One: Check for navigation element before using it.
This prevents a javascript error in case the primary navigation has been removed, for example in a child theme. Props sushmak. Fixes #52773. Built from https://develop.svn.wordpress.org/trunk@51072 git-svn-id: http://core.svn.wordpress.org/trunk@50681 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
36cf03ca52
commit
eaea2f3b45
|
@ -96,7 +96,13 @@ function twentytwentyoneExpandSubMenu( el ) { // jshint ignore:line
|
||||||
*/
|
*/
|
||||||
var navMenu = function( id ) {
|
var navMenu = function( id ) {
|
||||||
var wrapper = document.body, // this is the element to which a CSS class is added when a mobile nav menu is open
|
var wrapper = document.body, // this is the element to which a CSS class is added when a mobile nav menu is open
|
||||||
mobileButton = document.getElementById( id + '-mobile-menu' );
|
mobileButton = document.getElementById( id + '-mobile-menu' ),
|
||||||
|
navMenuEl = document.getElementById( 'site-navigation' );
|
||||||
|
|
||||||
|
// If there's no nav menu, none of this is necessary.
|
||||||
|
if ( ! navMenuEl ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ( mobileButton ) {
|
if ( mobileButton ) {
|
||||||
mobileButton.onclick = function() {
|
mobileButton.onclick = function() {
|
||||||
|
@ -167,7 +173,7 @@ function twentytwentyoneExpandSubMenu( el ) { // jshint ignore:line
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
document.getElementById( 'site-navigation' ).querySelectorAll( '.menu-wrapper > .menu-item-has-children' ).forEach( function( li ) {
|
navMenuEl.querySelectorAll( '.menu-wrapper > .menu-item-has-children' ).forEach( function( li ) {
|
||||||
li.addEventListener( 'mouseenter', function() {
|
li.addEventListener( 'mouseenter', function() {
|
||||||
this.querySelector( '.sub-menu-toggle' ).setAttribute( 'aria-expanded', 'true' );
|
this.querySelector( '.sub-menu-toggle' ).setAttribute( 'aria-expanded', 'true' );
|
||||||
twentytwentyoneSubmenuPosition( li );
|
twentytwentyoneSubmenuPosition( li );
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '5.8-alpha-51071';
|
$wp_version = '5.8-alpha-51072';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue