Twenty Twelve: update navigation script to check for missing button and menu children earlier; allows an empty menu to be set without showing the button. See #21678.

git-svn-id: https://develop.svn.wordpress.org/trunk@21929 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Lance Willett 2012-09-20 16:28:27 +00:00
parent 42ca24f54e
commit 4d4babe751
2 changed files with 8 additions and 6 deletions

View File

@ -98,7 +98,7 @@ function twentytwelve_scripts_styles() {
/*
* Adds JavaScript for handling the navigation menu hide-and-show behavior.
*/
wp_enqueue_script( 'twentytwelve-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20120824', true );
wp_enqueue_script( 'twentytwelve-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20120920', true );
/*
* Loads our special font CSS file.

View File

@ -7,9 +7,15 @@
var button = document.getElementById( 'site-navigation' ).getElementsByTagName( 'h3' )[0],
menu = document.getElementById( 'site-navigation' ).getElementsByTagName( 'ul' )[0];
if ( undefined == button || undefined == menu )
if ( undefined === button )
return false;
// Hide button if menu is missing or empty.
if ( undefined === menu || ! menu.childNodes.length ) {
button.style.display = 'none';
return false;
}
button.onclick = function() {
if ( -1 == menu.className.indexOf( 'nav-menu' ) )
menu.className = 'nav-menu';
@ -22,8 +28,4 @@
menu.className += ' toggled-on';
}
};
// Hide menu toggle button if menu is empty.
if ( ! menu.childNodes.length )
button.style.display = 'none';
} )();