From 3ba7b7e56af96ec1ec3dc982f585527d42f6dc7a Mon Sep 17 00:00:00 2001 From: Lance Willett Date: Fri, 1 Mar 2013 17:14:59 +0000 Subject: [PATCH] Twenty Twelve: better handling for cases where a background color is set to white or an empty value (like first run with no `theme_mods` set) and a background image is enabled, which resulted previously in a broken layout. Fixes #23586, props obenland. git-svn-id: https://develop.svn.wordpress.org/trunk@23568 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-content/themes/twentytwelve/functions.php | 13 +++++---- .../twentytwelve/js/theme-customizer.js | 28 ++++++++++++++----- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/wp-content/themes/twentytwelve/functions.php b/wp-content/themes/twentytwelve/functions.php index 580d038f9e..7f050f1a3e 100644 --- a/wp-content/themes/twentytwelve/functions.php +++ b/wp-content/themes/twentytwelve/functions.php @@ -383,6 +383,7 @@ endif; */ function twentytwelve_body_class( $classes ) { $background_color = get_background_color(); + $background_image = get_background_image(); if ( ! is_active_sidebar( 'sidebar-1' ) || is_page_template( 'page-templates/full-width.php' ) ) $classes[] = 'full-width'; @@ -395,10 +396,12 @@ function twentytwelve_body_class( $classes ) { $classes[] = 'two-sidebars'; } - if ( empty( $background_color ) ) - $classes[] = 'custom-background-empty'; - elseif ( in_array( $background_color, array( 'fff', 'ffffff' ) ) ) - $classes[] = 'custom-background-white'; + if ( empty( $background_image ) ) { + if ( empty( $background_color ) ) + $classes[] = 'custom-background-empty'; + elseif ( in_array( $background_color, array( 'fff', 'ffffff' ) ) ) + $classes[] = 'custom-background-white'; + } // Enable custom font class only if the font CSS is queued to load. if ( wp_style_is( 'twentytwelve-fonts', 'queue' ) ) @@ -445,6 +448,6 @@ add_action( 'customize_register', 'twentytwelve_customize_register' ); * @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' ), '20120827', true ); + wp_enqueue_script( 'twentytwelve-customizer', get_template_directory_uri() . '/js/theme-customizer.js', array( 'customize-preview' ), '20130301', true ); } add_action( 'customize_preview_init', 'twentytwelve_customize_preview_js' ); diff --git a/wp-content/themes/twentytwelve/js/theme-customizer.js b/wp-content/themes/twentytwelve/js/theme-customizer.js index 607ea883ee..1275d494be 100644 --- a/wp-content/themes/twentytwelve/js/theme-customizer.js +++ b/wp-content/themes/twentytwelve/js/theme-customizer.js @@ -18,15 +18,29 @@ } ); } ); - // Hook into background color change and adjust body class value as needed. + // Hook into background color/image change and adjust body class value as needed. wp.customize( 'background_color', function( value ) { value.bind( function( to ) { - if ( '#ffffff' == to || '#fff' == to ) - $( 'body' ).addClass( 'custom-background-white' ); - else if ( '' == to ) - $( 'body' ).addClass( 'custom-background-empty' ); + var body = $( 'body' ); + + if ( ( '#ffffff' == to || '#fff' == to ) && 'none' == body.css( 'background-image' ) ) + body.addClass( 'custom-background-white' ); + else if ( '' == to && 'none' == body.css( 'background-image' ) ) + body.addClass( 'custom-background-empty' ); else - $( 'body' ).removeClass( 'custom-background-empty custom-background-white' ); + body.removeClass( 'custom-background-empty custom-background-white' ); } ); } ); -} )( jQuery ); \ No newline at end of file + wp.customize( 'background_image', function( value ) { + value.bind( function( to ) { + var body = $( 'body' ); + + if ( '' != to ) + body.removeClass( 'custom-background-empty custom-background-white' ); + else if ( 'rgb(255, 255, 255)' == body.css( 'background-color' ) ) + body.addClass( 'custom-background-white' ); + else if ( 'rgb(230, 230, 230)' == body.css( 'background-color' ) && '' == _wpCustomizeSettings.values.background_color ) + body.addClass( 'custom-background-empty' ); + } ); + } ); +} )( jQuery );