diff --git a/inc/customizer.php b/inc/customizer.php index 97b7c2c..ed0e6a6 100644 --- a/inc/customizer.php +++ b/inc/customizer.php @@ -7,29 +7,23 @@ * @since Radiate 1.0 */ -/** - * Add postMessage support for site title and description for the Theme Customizer. - * - * @param WP_Customize_Manager $wp_customize Theme Customizer object. - */ -function radiate_customize_register( $wp_customize ) { +function radiate_register_theme_customizer( $wp_customize ) { $wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage'; -} -add_action( 'customize_register', 'radiate_customize_register' ); -/** - * Binds JS handlers to make Theme Customizer preview reload changes asynchronously. - */ -function radiate_customize_preview_js() { - wp_enqueue_script( 'radiate_customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), '20130508', true ); -} -add_action( 'customize_preview_init', 'radiate_customize_preview_js' ); + if ( isset( $wp_customize->selective_refresh ) ) { + $wp_customize->selective_refresh->add_partial( 'blogname', array( + 'selector' => '.site-title a', + 'render_callback' => 'radiate_customize_partial_blogname', + ) ); -/*****************************************************************************************/ + $wp_customize->selective_refresh->add_partial( 'blogdescription', array( + 'selector' => '.site-description', + 'render_callback' => 'radiate_customize_partial_blogdescription', + ) ); + } -function radiate_register_theme_customizer( $wp_customize ) { // remove control $wp_customize->remove_control('blogdescription'); @@ -102,9 +96,10 @@ public function render_content() { $wp_customize->add_setting( 'radiate_color_scheme', array( - 'default' => '#632E9B', - 'capability' => 'edit_theme_options', - 'sanitize_callback' => 'radiate_sanitize_hex_color', + 'default' => '#632E9B', + 'capability' => 'edit_theme_options', + 'transport' => 'postMessage', + 'sanitize_callback' => 'radiate_sanitize_hex_color', 'sanitize_js_callback' => 'radiate_sanitize_escaping' ) ); @@ -359,6 +354,33 @@ function radiate_sanitize_important_links() { } add_action( 'customize_register', 'radiate_register_theme_customizer' ); +/** + * Binds JS handlers to make Theme Customizer preview reload changes asynchronously. + */ +function radiate_customize_preview_js() { + wp_enqueue_script( 'radiate_customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), false, true ); +} +add_action( 'customize_preview_init', 'radiate_customize_preview_js' ); + +/** + * Render the site title for the selective refresh partial. + * + * @return void + */ +function radiate_customize_partial_blogname() { + bloginfo( 'name' ); +} + +/** + * Render the site tagline for the selective refresh partial. + * + * @return void + */ +function radiate_customize_partial_blogdescription() { + bloginfo( 'description' ); +} + + if ( ! function_exists( 'radiate_darkcolor' ) ) : /** * Generate darker color diff --git a/js/customizer.js b/js/customizer.js index a83540d..58e8da2 100644 --- a/js/customizer.js +++ b/js/customizer.js @@ -33,4 +33,41 @@ } } ); } ); + + // Primary color option + wp.customize( 'radiate_color_scheme', function ( value ) { + value.bind( function ( primaryColor ) { + // Store internal style for primary color + var primaryColorStyle = ''; + + // Remove previously create internal style and add new one. + $( 'head #radiate-internal-primary-color' ).remove(); + $( 'head' ).append( primaryColorStyle ); + } + ); + } ); } )( jQuery ); diff --git a/readme.txt b/readme.txt index 14c9c0b..0f8bbac 100644 --- a/readme.txt +++ b/readme.txt @@ -65,9 +65,10 @@ If you want to translate this theme to your language, Please visit:- https://tra == CHANGE LOG == = TBD = -* Tweak - Add theme support for Jetpack Responsive Videos. +* Tweak - Add theme support for Jetpack Responsive Videos. * Tweaks - Added welcome page -* Fix - Submenu issue fixed +* Fix - Submenu issue fixed +* Tweak - Introduce selective refresh and live js for site title, description and customizer option = Version 1.2.6 -2017-05-10 = * Tweaks - Add TGMPA to recommend ThemeGrill Demo Importer plugin