Twenty Fifteen: Removing unused custom color controls.

Props cainm, fixes #29982 and #29959.



git-svn-id: https://develop.svn.wordpress.org/trunk@29944 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ian Stewart 2014-10-17 20:51:46 +00:00
parent b5c0834bcb
commit 297f2c78c5
2 changed files with 51 additions and 76 deletions

View File

@ -27,12 +27,13 @@ function twentyfifteen_customize_register( $wp_customize ) {
'sanitize_callback' => 'twentyfifteen_sanitize_color_scheme', 'sanitize_callback' => 'twentyfifteen_sanitize_color_scheme',
) ); ) );
$wp_customize->add_control( new Twentyfifteen_Customize_Color_Scheme_Control( $wp_customize, 'color_scheme', array( $wp_customize->add_control( 'color_scheme', array(
'label' => esc_html__( 'Color Scheme', 'twentyfifteen' ), 'label' => esc_html__( 'Color Scheme', 'twentyfifteen' ),
'section' => 'colors', 'section' => 'colors',
'type' => 'select',
'choices' => twentyfifteen_get_color_scheme_choices(), 'choices' => twentyfifteen_get_color_scheme_choices(),
'priority' => 1, 'priority' => 1,
) ) ); ) );
// Add custom sidebar text color setting and control. // Add custom sidebar text color setting and control.
$wp_customize->add_setting( 'sidebar_textcolor', array( $wp_customize->add_setting( 'sidebar_textcolor', array(
@ -58,46 +59,6 @@ function twentyfifteen_customize_register( $wp_customize ) {
} }
add_action( 'customize_register', 'twentyfifteen_customize_register', 11 ); add_action( 'customize_register', 'twentyfifteen_customize_register', 11 );
/**
* Custom control for Color Schemes
*
* @since Twenty Fifteen 1.0
*/
function twentyfifteen_customize_color_scheme_control() {
class Twentyfifteen_Customize_Color_Scheme_Control extends WP_Customize_Control {
public $type = 'colorScheme';
function enqueue() {
wp_enqueue_script( 'color-scheme-control', get_template_directory_uri() . '/js/color-scheme-control.js', array( 'customize-controls' ), '', true );
wp_localize_script( 'color-scheme-control', 'colorScheme', twentyfifteen_get_color_schemes() );
}
public function render_content() {
if ( empty( $this->choices ) )
return;
?>
<label>
<?php if ( ! empty( $this->label ) ) : ?>
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<?php endif;
if ( ! empty( $this->description ) ) : ?>
<span class="description customize-control-description"><?php echo $this->description; ?></span>
<?php endif; ?>
<select <?php $this->link(); ?>>
<?php
foreach ( $this->choices as $value => $label )
echo '<option value="' . esc_attr( $value ) . '"' . selected( $this->value(), $value, false ) . '>' . $label . '</option>';
?>
</select>
</label>
<?php
}
}
}
add_action( 'customize_register', 'twentyfifteen_customize_color_scheme_control', 10 );
/** /**
* Register color schemes for Twenty Fifteen. * Register color schemes for Twenty Fifteen.
* Can be filtered with twentyfifteen_color_schemes. * Can be filtered with twentyfifteen_color_schemes.
@ -660,6 +621,18 @@ function twentyfifteen_color_scheme_css() {
} }
add_action( 'wp_enqueue_scripts', 'twentyfifteen_color_scheme_css' ); add_action( 'wp_enqueue_scripts', 'twentyfifteen_color_scheme_css' );
/**
* Binds JS listener to make Customizer color_scheme control.
* Passes color scheme data as colorScheme global
*
* @since Twenty Fifteen 1.0
*/
function twentyfifteen_customize_control_js() {
wp_enqueue_script( 'color-scheme-control', get_template_directory_uri() . '/js/color-scheme-control.js', array( 'customize-controls' ), '', true );
wp_localize_script( 'color-scheme-control', 'colorScheme', twentyfifteen_get_color_schemes() );
}
add_action( 'customize_controls_enqueue_scripts', 'twentyfifteen_customize_control_js' );
/** /**
* Binds JS handlers to make Customizer preview reload changes asynchronously. * Binds JS handlers to make Customizer preview reload changes asynchronously.
* *

View File

@ -6,45 +6,47 @@
*/ */
( function( wp ) { ( function( wp ) {
wp.customize.controlConstructor.colorScheme = wp.customize.Control.extend( { wp.customize.controlConstructor.select = wp.customize.Control.extend( {
ready: function() { ready: function() {
var parentSection = this.container.closest( '.control-section' ), if ( 'color_scheme' === this.id ) {
headerTextColor = parentSection.find( '#customize-control-header_textcolor .color-picker-hex' ), var parentSection = this.container.closest( '.control-section' ),
backgroundColor = parentSection.find( '#customize-control-background_color .color-picker-hex' ), headerTextColor = parentSection.find( '#customize-control-header_textcolor .color-picker-hex' ),
sidebarColor = parentSection.find( '#customize-control-header_background_color .color-picker-hex' ), backgroundColor = parentSection.find( '#customize-control-background_color .color-picker-hex' ),
sidebarTextColor = parentSection.find( '#customize-control-sidebar_textcolor .color-picker-hex' ); sidebarColor = parentSection.find( '#customize-control-header_background_color .color-picker-hex' ),
sidebarTextColor = parentSection.find( '#customize-control-sidebar_textcolor .color-picker-hex' );
this.setting.bind( 'change', function( value ) { this.setting.bind( 'change', function( value ) {
// if Header Text is not hidden, update value // if Header Text is not hidden, update value
if ( 'blank' !== wp.customize( 'header_textcolor' ).get() ) { if ( 'blank' !== wp.customize( 'header_textcolor' ).get() ) {
wp.customize( 'header_textcolor' ).set( colorScheme[value].colors[4] ); wp.customize( 'header_textcolor' ).set( colorScheme[value].colors[4] );
headerTextColor.val( colorScheme[value].colors[4] ) headerTextColor.val( colorScheme[value].colors[4] )
.data( 'data-default-color', colorScheme[value].colors[4] )
.wpColorPicker( 'color', colorScheme[value].colors[4] )
.wpColorPicker( 'defaultColor', colorScheme[value].colors[4] );
}
// update Background Color
wp.customize( 'background_color' ).set( colorScheme[value].colors[0] );
backgroundColor.val( colorScheme[value].colors[0] )
.data( 'data-default-color', colorScheme[value].colors[0] )
.wpColorPicker( 'color', colorScheme[value].colors[0] )
.wpColorPicker( 'defaultColor', colorScheme[value].colors[0] );
// update Header/Sidebar Background Color
wp.customize( 'header_background_color' ).set( colorScheme[value].colors[1] );
sidebarColor.val( colorScheme[value].colors[1] )
.data( 'data-default-color', colorScheme[value].colors[1] )
.wpColorPicker( 'color', colorScheme[value].colors[1] )
.wpColorPicker( 'defaultColor', colorScheme[value].colors[1] );
// update Sidebar Text Color
wp.customize( 'sidebar_textcolor' ).set( colorScheme[value].colors[4] );
sidebarTextColor.val( colorScheme[value].colors[4] )
.data( 'data-default-color', colorScheme[value].colors[4] ) .data( 'data-default-color', colorScheme[value].colors[4] )
.wpColorPicker( 'color', colorScheme[value].colors[4] ) .wpColorPicker( 'color', colorScheme[value].colors[4] )
.wpColorPicker( 'defaultColor', colorScheme[value].colors[4] ); .wpColorPicker( 'defaultColor', colorScheme[value].colors[4] );
} } );
}
// update Background Color
wp.customize( 'background_color' ).set( colorScheme[value].colors[0] );
backgroundColor.val( colorScheme[value].colors[0] )
.data( 'data-default-color', colorScheme[value].colors[0] )
.wpColorPicker( 'color', colorScheme[value].colors[0] )
.wpColorPicker( 'defaultColor', colorScheme[value].colors[0] );
// update Header/Sidebar Background Color
wp.customize( 'header_background_color' ).set( colorScheme[value].colors[1] );
sidebarColor.val( colorScheme[value].colors[1] )
.data( 'data-default-color', colorScheme[value].colors[1] )
.wpColorPicker( 'color', colorScheme[value].colors[1] )
.wpColorPicker( 'defaultColor', colorScheme[value].colors[1] );
// update Sidebar Text Color
wp.customize( 'sidebar_textcolor' ).set( colorScheme[value].colors[4] );
sidebarTextColor.val( colorScheme[value].colors[4] )
.data( 'data-default-color', colorScheme[value].colors[4] )
.wpColorPicker( 'color', colorScheme[value].colors[4] )
.wpColorPicker( 'defaultColor', colorScheme[value].colors[4] );
} );
} }
} ); } );
} )( this.wp ); } )( this.wp );