Twenty Twelve: enable async body class value changes for custom background color changes in Theme Customizer. See #21226.

git-svn-id: https://develop.svn.wordpress.org/trunk@21343 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Lance Willett 2012-07-25 19:42:55 +00:00
parent 280d1d249c
commit 6d9357444c
2 changed files with 25 additions and 0 deletions

View File

@ -365,3 +365,14 @@ function twentytwelve_content_width() {
}
}
add_action( 'template_redirect', 'twentytwelve_content_width' );
/**
* Bind JS handler to make Theme Customizer preview reload
* custom background `body_class` value changes asynchronously.
*
* @since Twenty Twelve 1.0
*/
function twentytwelve_customize_preview_js() {
wp_enqueue_script( 'twentytwelve-customizer', get_template_directory_uri() . '/js/theme-customizer.js', array( 'customize-preview' ), '20120725', true );
}
add_action( 'customize_preview_init', 'twentytwelve_customize_preview_js' );

View File

@ -0,0 +1,14 @@
( function( $ ){
// Hook into background color change and adjust body class value as needed.
wp.customize( 'background_color', function( value ) {
var body = $( 'body' );
value.bind( function( to ) {
if ( '#ffffff' == to || '#fff' == to || '' == to )
body.addClass( 'custom-background-white' );
else if ( '' == to )
body.addClass( 'custom-background-empty' );
else
body.removeClass( 'custom-background-empty custom-background-white' );
} );
} );
} )( jQuery );