2012-02-29 18:53:02 +00:00
|
|
|
/**
|
|
|
|
* Handles toggling the main navigation menu for small screens.
|
|
|
|
*/
|
2012-02-06 16:40:54 +00:00
|
|
|
jQuery( document ).ready( function( $ ) {
|
2012-02-29 18:53:02 +00:00
|
|
|
var $masthead = $( '#masthead' ),
|
|
|
|
timeout = false;
|
2012-02-06 16:40:54 +00:00
|
|
|
|
|
|
|
$.fn.smallMenu = function() {
|
2012-02-29 18:53:02 +00:00
|
|
|
$masthead.find( '.site-navigation' ).removeClass( 'main-navigation' ).addClass( 'main-small-navigation' );
|
|
|
|
$masthead.find( '.site-navigation h1' ).removeClass( 'assistive-text' ).addClass( 'menu-toggle' );
|
2012-02-06 16:40:54 +00:00
|
|
|
|
2012-03-28 05:17:50 +00:00
|
|
|
$( '.menu-toggle' ).unbind( 'click' ).click( function() {
|
2012-02-29 18:53:02 +00:00
|
|
|
$masthead.find( '.menu' ).toggle();
|
2012-02-07 03:20:46 +00:00
|
|
|
$( this ).toggleClass( 'toggled-on' );
|
2012-02-29 18:53:02 +00:00
|
|
|
} );
|
|
|
|
};
|
2012-02-06 16:40:54 +00:00
|
|
|
|
2012-02-29 18:53:02 +00:00
|
|
|
// Check viewport width on first load.
|
|
|
|
if ( $( window ).width() < 600 )
|
|
|
|
$.fn.smallMenu();
|
2012-02-06 16:40:54 +00:00
|
|
|
|
2012-02-29 18:53:02 +00:00
|
|
|
// Check viewport width when user resizes the browser window.
|
|
|
|
$( window ).resize( function() {
|
|
|
|
var browserWidth = $( window ).width();
|
2012-02-06 16:40:54 +00:00
|
|
|
|
2012-02-29 18:53:02 +00:00
|
|
|
if ( false !== timeout )
|
|
|
|
clearTimeout( timeout );
|
2012-02-06 16:40:54 +00:00
|
|
|
|
2012-02-29 18:53:02 +00:00
|
|
|
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 );
|
|
|
|
} );
|
2012-02-06 16:40:54 +00:00
|
|
|
} );
|