From 79a8543aa1cc39b4134de3d3bb5df827e628a53e Mon Sep 17 00:00:00 2001 From: Lance Willett Date: Thu, 20 Sep 2012 16:28:27 +0000 Subject: [PATCH] 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: http://core.svn.wordpress.org/trunk@21929 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- functions.php | 2 +- js/navigation.js | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/functions.php b/functions.php index f4f347e48..e399343ee 100644 --- a/functions.php +++ b/functions.php @@ -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. diff --git a/js/navigation.js b/js/navigation.js index e544e292c..1260f61ba 100644 --- a/js/navigation.js +++ b/js/navigation.js @@ -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'; } )(); \ No newline at end of file