Created
August 30, 2013 04:34
-
-
Save krogsgard/6386343 to your computer and use it in GitHub Desktop.
This is a toggle method previously used by the _s theme that utilizes jQuery and a specific browserWidth trigger.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Handles toggling the main navigation menu for small screens. | |
*/ | |
jQuery( document ).ready( function( $ ) { | |
var $masthead = $( '#masthead' ), | |
timeout = false; | |
$.fn.smallMenu = function() { | |
$masthead.find( '.site-navigation' ).removeClass( 'main-navigation' ).addClass( 'main-small-navigation' ); | |
$masthead.find( '.site-navigation h1' ).removeClass( 'assistive-text' ).addClass( 'menu-toggle' ); | |
$( '.menu-toggle' ).click( function() { | |
$masthead.find( '.menu' ).toggle(); | |
$( this ).toggleClass( 'toggled-on' ); | |
} ); | |
}; | |
// Check viewport width on first load. | |
if ( $( window ).width() < 600 ) | |
$.fn.smallMenu(); | |
// Check viewport width when user resizes the browser window. | |
$( window ).resize( function() { | |
var browserWidth = $( window ).width(); | |
if ( false !== timeout ) | |
clearTimeout( timeout ); | |
timeout = setTimeout( function() { | |
if ( browserWidth < 600 ) { | |
$.fn.smallMenu(); | |
} else { | |
$masthead.find( '.site-navigation' ).removeClass( 'main-small-navigation' ).addClass( 'main-navigation' ); | |
$masthead.find( '.site-navigation h1' ).removeClass( 'menu-toggle' ).addClass( 'assistive-text' ); | |
$masthead.find( '.menu' ).removeAttr( 'style' ); | |
} | |
}, 200 ); | |
} ); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment