forked from mirror/_s
* Only set button and menu if container is not null. * Break up the "return early" conditional into multiple parts. * Shorten the name of the toggled class from `toggled-on` to `toggled`. * Restore the "Hide menu toggle button if menu is empty." documentation. * Remove the `nav-menu` class. The previous code would replace any custom custom classes applied via `wp_nav_menu()` or template file. * Replace the `nav-menu` selector is style.css with selectors that will target both a custom nav menu and a page menu. These changes could use critical feedback. Do you know of an edge case where they might not work as expected?
This commit is contained in:
parent
75f612d365
commit
4c396f6f9b
|
@ -5,28 +5,28 @@
|
|||
*/
|
||||
( function() {
|
||||
var container = document.getElementById( 'site-navigation' ),
|
||||
button = container.getElementsByTagName( 'h1' )[0],
|
||||
menu = container.getElementsByTagName( 'ul' )[0];
|
||||
button,
|
||||
menu;
|
||||
|
||||
if ( undefined == button || undefined == menu )
|
||||
return false;
|
||||
if ( ! container )
|
||||
return;
|
||||
|
||||
button = container.getElementsByTagName( 'h1' )[0];
|
||||
if ( 'undefined' == typeof button )
|
||||
return;
|
||||
|
||||
menu = container.getElementsByTagName( 'ul' )[0];
|
||||
|
||||
// Hide menu toggle button if menu is empty and return early.
|
||||
if ( 'undefined' == typeof menu ) {
|
||||
button.style.display = 'none';
|
||||
return;
|
||||
}
|
||||
|
||||
button.onclick = function() {
|
||||
if ( -1 == menu.className.indexOf( 'nav-menu' ) )
|
||||
menu.className = 'nav-menu';
|
||||
|
||||
if ( -1 != button.className.indexOf( 'toggled-on' ) ) {
|
||||
button.className = button.className.replace( ' toggled-on', '' );
|
||||
menu.className = menu.className.replace( ' toggled-on', '' );
|
||||
container.className = container.className.replace( 'main-small-navigation', 'navigation-main' );
|
||||
} else {
|
||||
button.className += ' toggled-on';
|
||||
menu.className += ' toggled-on';
|
||||
container.className = container.className.replace( 'navigation-main', 'main-small-navigation' );
|
||||
}
|
||||
if ( -1 != container.className.indexOf( 'toggled' ) )
|
||||
container.className = container.className.replace( ' toggled', '' );
|
||||
else
|
||||
container.className += ' toggled';
|
||||
};
|
||||
|
||||
// Hide menu toggle button if menu is empty.
|
||||
if ( ! menu.childNodes.length )
|
||||
button.style.display = 'none';
|
||||
} )();
|
|
@ -447,7 +447,8 @@ a:active {
|
|||
|
||||
@media screen and (max-width: 600px) {
|
||||
.menu-toggle,
|
||||
.main-small-navigation ul.nav-menu.toggled-on {
|
||||
.navigation-main.toggled ul.menu,
|
||||
.navigation-main.toggled div.menu > ul {
|
||||
display: block;
|
||||
}
|
||||
|
||||
|
@ -456,6 +457,7 @@ a:active {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/* =Content
|
||||
----------------------------------------------- */
|
||||
|
||||
|
|
Reference in New Issue