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

git-svn-id: http://core.svn.wordpress.org/trunk@21343 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
lancewillett 2012-07-25 19:42:55 +00:00
parent c163a3a642
commit 0a22b3a88f
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' );

14
js/theme-customizer.js Normal file
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 );