Wordpress/wp-content/themes/twentytwelve/js/theme.js
Andrew Nacin 4cc47e2034 The Twenty Twelve for WordPress.
props drewstrojny, lancewillett.

also props corvannoorloos, jeffsebring, kobenland, iandstewart, mfields,
mtdesign, op12no2, philiparthurmoore, sixhours, mamaduka.

see #19978.



git-svn-id: https://develop.svn.wordpress.org/trunk@21261 602fd350-edb4-49c9-b593-d223f7449a82
2012-07-12 04:20:46 +00:00

41 lines
1.3 KiB
JavaScript

/**
* navigation.js
*
* Handles toggling the navigation menu for small screens.
*/
jQuery( document ).ready( function( $ ) {
var masthead = $( '#masthead' ),
largeWindow = window.matchMedia( 'screen and (min-width: 600px)' ),
timeout = false;
$.fn.smallMenu = function() {
masthead.find( '.site-navigation' ).removeClass( 'main-navigation' ).addClass( 'main-small-navigation' );
masthead.find( '.site-navigation h3' ).removeClass( 'assistive-text' ).addClass( 'menu-toggle' );
$( '.menu-toggle' ).off( 'click' ).click( function() {
masthead.find( '.menu' ).slideToggle();
$( this ).toggleClass( 'toggled-on' );
} );
};
// Check viewport width on first load.
if ( ! largeWindow.matches )
$.fn.smallMenu();
// Check viewport width when user resizes the browser window.
$( window ).resize( function() {
if ( false !== timeout )
clearTimeout( timeout );
timeout = setTimeout( function() {
if ( ! largeWindow.matches ) {
$.fn.smallMenu();
} else {
masthead.find( '.site-navigation' ).removeClass( 'main-small-navigation' ).addClass( 'main-navigation' );
masthead.find( '.site-navigation h3' ).removeClass( 'menu-toggle' ).addClass( 'assistive-text' );
masthead.find( '.menu' ).removeAttr( 'style' );
}
}, 200 );
} );
} );