2012-09-03 17:45:28 +00:00
|
|
|
/**
|
|
|
|
* navigation.js
|
|
|
|
*
|
|
|
|
* Handles toggling the navigation menu for small screens.
|
|
|
|
*/
|
|
|
|
( function() {
|
2013-06-25 08:45:52 +00:00
|
|
|
var container, button, menu;
|
2012-09-03 17:45:28 +00:00
|
|
|
|
2013-07-14 06:39:03 +00:00
|
|
|
container = document.getElementById( 'site-navigation' );
|
2013-06-17 03:29:17 +00:00
|
|
|
if ( ! container )
|
|
|
|
return;
|
2012-09-03 17:45:28 +00:00
|
|
|
|
2013-06-17 03:29:17 +00:00
|
|
|
button = container.getElementsByTagName( 'h1' )[0];
|
2013-07-14 06:38:08 +00:00
|
|
|
if ( 'undefined' === typeof button )
|
2013-06-17 03:29:17 +00:00
|
|
|
return;
|
2012-09-03 17:45:28 +00:00
|
|
|
|
2013-06-17 03:29:17 +00:00
|
|
|
menu = container.getElementsByTagName( 'ul' )[0];
|
2012-09-03 17:45:28 +00:00
|
|
|
|
2013-06-17 03:29:17 +00:00
|
|
|
// Hide menu toggle button if menu is empty and return early.
|
2013-07-14 06:38:08 +00:00
|
|
|
if ( 'undefined' === typeof menu ) {
|
2012-09-03 17:45:28 +00:00
|
|
|
button.style.display = 'none';
|
2013-06-17 03:29:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-14 06:38:08 +00:00
|
|
|
if ( -1 === menu.className.indexOf( 'nav-menu' ) )
|
2013-06-25 08:45:52 +00:00
|
|
|
menu.className += ' nav-menu';
|
|
|
|
|
2013-06-17 03:29:17 +00:00
|
|
|
button.onclick = function() {
|
2013-07-14 06:38:08 +00:00
|
|
|
if ( -1 !== container.className.indexOf( 'toggled' ) )
|
2013-06-17 03:29:17 +00:00
|
|
|
container.className = container.className.replace( ' toggled', '' );
|
|
|
|
else
|
|
|
|
container.className += ' toggled';
|
|
|
|
};
|
2013-07-14 06:38:08 +00:00
|
|
|
} )();
|