navigation.js 831 B

12345678910111213141516171819202122232425262728293031323334
  1. /**
  2. * navigation.js
  3. *
  4. * Handles toggling the navigation menu for small screens.
  5. */
  6. ( function() {
  7. var container, button, menu;
  8. container = document.getElementById( 'site-navigation' );
  9. if ( ! container )
  10. return;
  11. button = container.getElementsByTagName( 'button' )[0];
  12. if ( 'undefined' === typeof button )
  13. return;
  14. menu = container.getElementsByTagName( 'ul' )[0];
  15. // Hide menu toggle button if menu is empty and return early.
  16. if ( 'undefined' === typeof menu ) {
  17. button.style.display = 'none';
  18. return;
  19. }
  20. if ( -1 === menu.className.indexOf( 'nav-menu' ) )
  21. menu.className += ' nav-menu';
  22. button.onclick = function() {
  23. if ( -1 !== container.className.indexOf( 'toggled' ) )
  24. container.className = container.className.replace( ' toggled', '' );
  25. else
  26. container.className += ' toggled';
  27. };
  28. } )();