Replace small-menu.js with navigation.js inspired by Twenty Twelve.
Doesn't use jQuery, slightly easier to understand, uses a media query for max-width, rather than JS events making it faster to respond.
This commit is contained in:
parent
7fef5cd2ec
commit
22e1613bde
5 changed files with 48 additions and 43 deletions
32
js/navigation.js
Normal file
32
js/navigation.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
/**
|
||||
* navigation.js
|
||||
*
|
||||
* Handles toggling the navigation menu for small screens.
|
||||
*/
|
||||
( function() {
|
||||
var button = document.getElementById( 'site-navigation' ).getElementsByTagName( 'h1' )[0],
|
||||
menu = document.getElementById( 'site-navigation' ).getElementsByTagName( 'ul' )[0];
|
||||
container = document.getElementById( 'site-navigation' );
|
||||
|
||||
if ( undefined == button || undefined == menu )
|
||||
return false;
|
||||
|
||||
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', ' main-navigation' );
|
||||
} else {
|
||||
button.className += ' toggled-on';
|
||||
menu.className += ' toggled-on';
|
||||
container.className = container.className.replace( ' main-navigation', ' main-small-navigation' );
|
||||
}
|
||||
};
|
||||
|
||||
// Hide menu toggle button if menu is empty.
|
||||
if ( ! menu.childNodes.length )
|
||||
button.style.display = 'none';
|
||||
} )();
|
Loading…
Add table
Add a link
Reference in a new issue