navigation.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * navigation.js
  3. *
  4. * Handles toggling the navigation menu for small screens.
  5. */
  6. ( function( $ ) {
  7. var windowWidth = $( window ).width();
  8. /* Drop menu down from top of screen */
  9. $( '.menu-toggle' ).on( 'click', function() {
  10. var menu = $( this ).parent().find( '.menu-wrapper' );
  11. menu.toggleClass( 'menu-visible' );
  12. $( this ).find( '#menu-icon' ).toggleClass( 'open' );
  13. });
  14. /* Open sub-menus if we're using the teeny menu */
  15. if ( $( '.menu-toggle' ).is( ':visible' ) ) {
  16. $( '.menu-item-has-children > a' ).on( 'click', function() {
  17. $( this ).parent().children( '.sub-menu' ).toggleClass( 'menu-visible' );
  18. return false;
  19. });
  20. }
  21. /* Make sure to show the sub-menu on page resize */
  22. $( window ).resize( function() {
  23. // Prevent the following code from getting triggered when scrolling on mobile devices
  24. if ( windowWidth !== $( window ).width() ) {
  25. var menu = $( '.menu-toggle' ).parent().find( '.menu-wrapper' );
  26. menu.removeClass( 'menu-visible' );
  27. $( '#menu-icon' ).removeClass( 'open' );
  28. }
  29. windowWidth = $( window ).width();
  30. });
  31. } )( jQuery );