2012-08-20 20:35:33 +02:00
|
|
|
/**
|
|
|
|
* navigation.js
|
|
|
|
*
|
|
|
|
* Handles toggling the navigation menu for small screens.
|
|
|
|
*/
|
2012-08-24 23:07:19 +02:00
|
|
|
( function() {
|
2012-11-14 21:21:01 +01: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 20:35:33 +02:00
|
|
|
|
2012-09-20 18:28:27 +02:00
|
|
|
// Hide button if menu is missing or empty.
|
2012-11-14 21:21:01 +01:00
|
|
|
if ( ! menu || ! menu.childNodes.length ) {
|
2012-09-20 18:28:27 +02:00
|
|
|
button.style.display = 'none';
|
2012-11-14 21:21:01 +01:00
|
|
|
return;
|
2012-09-20 18:28:27 +02:00
|
|
|
}
|
|
|
|
|
2012-08-25 18:50:05 +02:00
|
|
|
button.onclick = function() {
|
|
|
|
if ( -1 == menu.className.indexOf( 'nav-menu' ) )
|
|
|
|
menu.className = 'nav-menu';
|
2012-08-24 23:07:19 +02:00
|
|
|
|
2012-08-25 18:50:05 +02: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 23:07:19 +02:00
|
|
|
} )();
|