Twenty Twelve: avoid JavaScript errors if navigation wrapper markup is removed from header. Fixes #22307.

git-svn-id: http://core.svn.wordpress.org/trunk@22574 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Lance Willett 2012-11-14 20:21:01 +00:00
parent ea96da65e1
commit a8c0e1dfe9
1 changed files with 9 additions and 7 deletions

View File

@ -4,16 +4,18 @@
* Handles toggling the navigation menu for small screens. * Handles toggling the navigation menu for small screens.
*/ */
( function() { ( function() {
var button = document.getElementById( 'site-navigation' ).getElementsByTagName( 'h3' )[0], var nav = document.getElementById( 'site-navigation' ), button, menu;
menu = document.getElementById( 'site-navigation' ).getElementsByTagName( 'ul' )[0]; if ( ! nav )
return;
if ( undefined === button ) button = nav.getElementsByTagName( 'h3' )[0];
return false; menu = nav.getElementsByTagName( 'ul' )[0];
if ( ! button )
return;
// Hide button if menu is missing or empty. // Hide button if menu is missing or empty.
if ( undefined === menu || ! menu.childNodes.length ) { if ( ! menu || ! menu.childNodes.length ) {
button.style.display = 'none'; button.style.display = 'none';
return false; return;
} }
button.onclick = function() { button.onclick = function() {