2012-08-20 14:35:33 -04:00
|
|
|
/**
|
|
|
|
* navigation.js
|
|
|
|
*
|
|
|
|
* Handles toggling the navigation menu for small screens.
|
|
|
|
*/
|
2012-08-24 17:07:19 -04:00
|
|
|
( function() {
|
2012-11-14 15:21:01 -05:00
|
|
|
var nav = document.getElementById( 'site-navigation' ), button, menu;
|
|
|
|
if ( ! nav )
|
|
|
|
return;
|
|
|
|
button = nav.getElementsByTagName( 'h3' )[0];
|
|
|
|
menu = nav.getElementsByTagName( 'ul' )[0];
|
|
|
|
if ( ! button )
|
|
|
|
return;
|
2012-08-20 14:35:33 -04:00
|
|
|
|
2012-09-20 12:28:27 -04:00
|
|
|
// Hide button if menu is missing or empty.
|
2012-11-14 15:21:01 -05:00
|
|
|
if ( ! menu || ! menu.childNodes.length ) {
|
2012-09-20 12:28:27 -04:00
|
|
|
button.style.display = 'none';
|
2012-11-14 15:21:01 -05:00
|
|
|
return;
|
2012-09-20 12:28:27 -04:00
|
|
|
}
|
|
|
|
|
2012-08-25 12:50:05 -04:00
|
|
|
button.onclick = function() {
|
|
|
|
if ( -1 == menu.className.indexOf( 'nav-menu' ) )
|
|
|
|
menu.className = 'nav-menu';
|
2012-08-24 17:07:19 -04:00
|
|
|
|
2012-08-25 12:50:05 -04:00
|
|
|
if ( -1 != button.className.indexOf( 'toggled-on' ) ) {
|
|
|
|
button.className = button.className.replace( ' toggled-on', '' );
|
|
|
|
menu.className = menu.className.replace( ' toggled-on', '' );
|
|
|
|
} else {
|
|
|
|
button.className += ' toggled-on';
|
|
|
|
menu.className += ' toggled-on';
|
|
|
|
}
|
|
|
|
};
|
2012-08-24 17:07:19 -04:00
|
|
|
} )();
|