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() {
|
( function() {
|
||||||
var container = document.getElementById( 'site-navigation' ),
|
var container = document.getElementById( 'site-navigation' ),
|
||||||
button = container.getElementsByTagName( 'h1' )[0],
|
button,
|
||||||
|
menu;
|
||||||
|
|
||||||
|
if ( ! container )
|
||||||
|
return;
|
||||||
|
|
||||||
|
button = container.getElementsByTagName( 'h1' )[0];
|
||||||
|
if ( 'undefined' == typeof button )
|
||||||
|
return;
|
||||||
|
|
||||||
menu = container.getElementsByTagName( 'ul' )[0];
|
menu = container.getElementsByTagName( 'ul' )[0];
|
||||||
|
|
||||||
if ( undefined == button || undefined == menu )
|
// Hide menu toggle button if menu is empty and return early.
|
||||||
return false;
|
if ( 'undefined' == typeof menu ) {
|
||||||
|
button.style.display = 'none';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
button.onclick = function() {
|
button.onclick = function() {
|
||||||
if ( -1 == menu.className.indexOf( 'nav-menu' ) )
|
if ( -1 != container.className.indexOf( 'toggled' ) )
|
||||||
menu.className = 'nav-menu';
|
container.className = container.className.replace( ' toggled', '' );
|
||||||
|
else
|
||||||
if ( -1 != button.className.indexOf( 'toggled-on' ) ) {
|
container.className += ' toggled';
|
||||||
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' );
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// 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) {
|
@media screen and (max-width: 600px) {
|
||||||
.menu-toggle,
|
.menu-toggle,
|
||||||
.main-small-navigation ul.nav-menu.toggled-on {
|
.navigation-main.toggled ul.menu,
|
||||||
|
.navigation-main.toggled div.menu > ul {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -456,6 +457,7 @@ a:active {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* =Content
|
/* =Content
|
||||||
----------------------------------------------- */
|
----------------------------------------------- */
|
||||||
|
|
||||||
|
|
Reference in New Issue