From 4a3034daf176a0cf0b71cb9c60d13e27a6b799ce Mon Sep 17 00:00:00 2001 From: Nima Date: Mon, 25 Dec 2017 15:14:48 +0545 Subject: [PATCH 1/5] Code enhanement --- inc/customizer.php | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/inc/customizer.php b/inc/customizer.php index 97b7c2c..d4d07bc 100644 --- a/inc/customizer.php +++ b/inc/customizer.php @@ -7,29 +7,11 @@ * @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' ); - -/*****************************************************************************************/ -function radiate_register_theme_customizer( $wp_customize ) { // remove control $wp_customize->remove_control('blogdescription'); @@ -359,6 +341,14 @@ 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' ), '20130508', true ); +} +add_action( 'customize_preview_init', 'radiate_customize_preview_js' ); + if ( ! function_exists( 'radiate_darkcolor' ) ) : /** * Generate darker color From 85205db0bdb2d31742a173f6cb3e6a3bdf478f55 Mon Sep 17 00:00:00 2001 From: Nima Date: Mon, 25 Dec 2017 15:24:30 +0545 Subject: [PATCH 2/5] Selective refresh for site title and description --- inc/customizer.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/inc/customizer.php b/inc/customizer.php index d4d07bc..cb0740d 100644 --- a/inc/customizer.php +++ b/inc/customizer.php @@ -12,6 +12,18 @@ function radiate_register_theme_customizer( $wp_customize ) { $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage'; + 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', + ) ); + } + // remove control $wp_customize->remove_control('blogdescription'); @@ -349,6 +361,25 @@ function radiate_customize_preview_js() { } 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 From b95a72f41345fe626fec8e899ba79ecdd868b061 Mon Sep 17 00:00:00 2001 From: Nima Date: Mon, 25 Dec 2017 16:14:29 +0545 Subject: [PATCH 3/5] Live js for primary color --- inc/customizer.php | 9 +++++---- js/customizer.js | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/inc/customizer.php b/inc/customizer.php index cb0740d..ed0e6a6 100644 --- a/inc/customizer.php +++ b/inc/customizer.php @@ -96,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' ) ); @@ -357,7 +358,7 @@ function radiate_sanitize_important_links() { * 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 ); + 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' ); diff --git a/js/customizer.js b/js/customizer.js index a83540d..07f4f13 100644 --- a/js/customizer.js +++ b/js/customizer.js @@ -33,4 +33,42 @@ } } ); } ); + + // Primary color option + wp.customize( 'radiate_color_scheme', function ( value ) { + console.log( 'chalyo' ); + 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 ); From eaf780c7f0301ef68d2a2e45a82ebfbe61d5b5fe Mon Sep 17 00:00:00 2001 From: Nima Date: Mon, 25 Dec 2017 16:16:07 +0545 Subject: [PATCH 4/5] Updated readme file --- readme.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 From 273eb4c0168249b0f40b2f74ba8e1702bcba8e8a Mon Sep 17 00:00:00 2001 From: Nima Date: Mon, 25 Dec 2017 16:52:50 +0545 Subject: [PATCH 5/5] Code correction --- js/customizer.js | 1 - 1 file changed, 1 deletion(-) diff --git a/js/customizer.js b/js/customizer.js index 07f4f13..58e8da2 100644 --- a/js/customizer.js +++ b/js/customizer.js @@ -36,7 +36,6 @@ // Primary color option wp.customize( 'radiate_color_scheme', function ( value ) { - console.log( 'chalyo' ); value.bind( function ( primaryColor ) { // Store internal style for primary color var primaryColorStyle = '