WordPress/wp-content/themes/twentytwelve/js/theme.js
lancewillett 1d9662043e Twenty Twelve: CSS and markup improvements for better child theme support, part 3. See #21379.
* Add classes like `.site` and `.site-content` in addition to the set of IDs already present, making things much better for child themes to have more than one generic element like `nav` inside the content container.
 * Bump JS version after selector change.
 * Move `image-attachment` to `post_class()` output

More exhaustive notes in the ticket on each id and class change.


git-svn-id: http://core.svn.wordpress.org/trunk@21404 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2012-08-02 19:12:11 +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( '.main-navigation' ).removeClass( 'main-navigation' ).addClass( 'main-small-navigation' );
masthead.find( '.main-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( '.main-navigation' ).removeClass( 'main-small-navigation' ).addClass( 'main-navigation' );
masthead.find( '.main-navigation h3' ).removeClass( 'menu-toggle' ).addClass( 'assistive-text' );
masthead.find( '.menu' ).removeAttr( 'style' );
}
}, 200 );
} );
} );