Ticket #29982: 29982.diff
File 29982.diff, 7.8 KB (added by , 10 years ago) |
---|
-
wp-content/themes/twentyfifteen/inc/customizer.php
27 27 'sanitize_callback' => 'twentyfifteen_sanitize_color_scheme', 28 28 ) ); 29 29 30 $wp_customize->add_control( new Twentyfifteen_Customize_Color_Scheme_Control( $wp_customize,'color_scheme', array(30 $wp_customize->add_control( 'color_scheme', array( 31 31 'label' => esc_html__( 'Color Scheme', 'twentyfifteen' ), 32 32 'section' => 'colors', 33 'type' => 'select', 33 34 'choices' => twentyfifteen_get_color_scheme_choices(), 34 35 'priority' => 1, 35 ) ) );36 ) ); 36 37 37 38 // Add custom sidebar text color setting and control. 38 39 $wp_customize->add_setting( 'sidebar_textcolor', array( … … 59 60 add_action( 'customize_register', 'twentyfifteen_customize_register', 11 ); 60 61 61 62 /** 62 * Custom control for Color Schemes63 *64 * @since Twenty Fifteen 1.065 */66 function twentyfifteen_customize_color_scheme_control() {67 class Twentyfifteen_Customize_Color_Scheme_Control extends WP_Customize_Control {68 public $type = 'colorScheme';69 70 function enqueue() {71 wp_enqueue_script( 'color-scheme-control', get_template_directory_uri() . '/js/color-scheme-control.js', array( 'customize-controls' ), '', true );72 wp_localize_script( 'color-scheme-control', 'colorScheme', twentyfifteen_get_color_schemes() );73 }74 75 public function render_content() {76 if ( empty( $this->choices ) )77 return;78 79 ?>80 <label>81 <?php if ( ! empty( $this->label ) ) : ?>82 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>83 <?php endif;84 if ( ! empty( $this->description ) ) : ?>85 <span class="description customize-control-description"><?php echo $this->description; ?></span>86 <?php endif; ?>87 88 <select <?php $this->link(); ?>>89 <?php90 foreach ( $this->choices as $value => $label )91 echo '<option value="' . esc_attr( $value ) . '"' . selected( $this->value(), $value, false ) . '>' . $label . '</option>';92 ?>93 </select>94 </label>95 <?php96 }97 }98 }99 add_action( 'customize_register', 'twentyfifteen_customize_color_scheme_control', 10 );100 101 /**102 63 * Register color schemes for Twenty Fifteen. 103 64 * Can be filtered with twentyfifteen_color_schemes. 104 65 * … … 650 611 add_action( 'wp_enqueue_scripts', 'twentyfifteen_color_scheme_css' ); 651 612 652 613 /** 614 * Binds JS listener to make Theme Customizer color_scheme control. 615 * Passes color scheme data as colorScheme global 616 * 617 * @since Twenty Fifteen 1.0 618 */ 619 function twentyfifteen_customize_control_js() { 620 wp_enqueue_script( 'color-scheme-control', get_template_directory_uri() . '/js/color-scheme-control.js', array( 'customize-controls' ), '', true ); 621 wp_localize_script( 'color-scheme-control', 'colorScheme', twentyfifteen_get_color_schemes() ); 622 } 623 add_action( 'customize_controls_enqueue_scripts', 'twentyfifteen_customize_control_js' ); 624 625 /** 653 626 * Binds JS handlers to make Theme Customizer preview reload changes asynchronously. 654 627 * 655 628 * @since Twenty Fifteen 1.0 -
wp-content/themes/twentyfifteen/js/color-scheme-control.js
6 6 */ 7 7 8 8 ( function( wp ) { 9 wp.customize.controlConstructor. colorScheme= wp.customize.Control.extend( {9 wp.customize.controlConstructor.select = wp.customize.Control.extend( { 10 10 ready: function() { 11 var parentSection = this.container.closest( '.control-section' ), 12 headerTextColor = parentSection.find( '#customize-control-header_textcolor .color-picker-hex' ), 13 backgroundColor = parentSection.find( '#customize-control-background_color .color-picker-hex' ), 14 sidebarColor = parentSection.find( '#customize-control-header_background_color .color-picker-hex' ), 15 sidebarTextColor = parentSection.find( '#customize-control-sidebar_textcolor .color-picker-hex' ); 11 if ( 'color_scheme' === this.id ) { 12 var parentSection = this.container.closest( '.control-section' ), 13 headerTextColor = parentSection.find( '#customize-control-header_textcolor .color-picker-hex' ), 14 backgroundColor = parentSection.find( '#customize-control-background_color .color-picker-hex' ), 15 sidebarColor = parentSection.find( '#customize-control-header_background_color .color-picker-hex' ), 16 sidebarTextColor = parentSection.find( '#customize-control-sidebar_textcolor .color-picker-hex' ); 16 17 17 this.setting.bind( 'change', function( value ) { 18 // if Header Text is not hidden, update value 19 if ( 'blank' !== wp.customize( 'header_textcolor' ).get() ) { 20 wp.customize( 'header_textcolor' ).set( colorScheme[value].colors[4] ); 21 headerTextColor.val( colorScheme[value].colors[4] ) 18 this.setting.bind( 'change', function( value ) { 19 // if Header Text is not hidden, update value 20 if ( 'blank' !== wp.customize( 'header_textcolor' ).get() ) { 21 wp.customize( 'header_textcolor' ).set( colorScheme[value].colors[4] ); 22 headerTextColor.val( colorScheme[value].colors[4] ) 23 .data( 'data-default-color', colorScheme[value].colors[4] ) 24 .wpColorPicker( 'color', colorScheme[value].colors[4] ) 25 .wpColorPicker( 'defaultColor', colorScheme[value].colors[4] ); 26 } 27 28 // update Background Color 29 wp.customize( 'background_color' ).set( colorScheme[value].colors[0] ); 30 backgroundColor.val( colorScheme[value].colors[0] ) 31 .data( 'data-default-color', colorScheme[value].colors[0] ) 32 .wpColorPicker( 'color', colorScheme[value].colors[0] ) 33 .wpColorPicker( 'defaultColor', colorScheme[value].colors[0] ); 34 35 // update Header/Sidebar Background Color 36 wp.customize( 'header_background_color' ).set( colorScheme[value].colors[1] ); 37 sidebarColor.val( colorScheme[value].colors[1] ) 38 .data( 'data-default-color', colorScheme[value].colors[1] ) 39 .wpColorPicker( 'color', colorScheme[value].colors[1] ) 40 .wpColorPicker( 'defaultColor', colorScheme[value].colors[1] ); 41 42 // update Sidebar Text Color 43 wp.customize( 'sidebar_textcolor' ).set( colorScheme[value].colors[4] ); 44 sidebarTextColor.val( colorScheme[value].colors[4] ) 22 45 .data( 'data-default-color', colorScheme[value].colors[4] ) 23 46 .wpColorPicker( 'color', colorScheme[value].colors[4] ) 24 47 .wpColorPicker( 'defaultColor', colorScheme[value].colors[4] ); 25 } 26 27 // update Background Color 28 wp.customize( 'background_color' ).set( colorScheme[value].colors[0] ); 29 backgroundColor.val( colorScheme[value].colors[0] ) 30 .data( 'data-default-color', colorScheme[value].colors[0] ) 31 .wpColorPicker( 'color', colorScheme[value].colors[0] ) 32 .wpColorPicker( 'defaultColor', colorScheme[value].colors[0] ); 33 34 // update Header/Sidebar Background Color 35 wp.customize( 'header_background_color' ).set( colorScheme[value].colors[1] ); 36 sidebarColor.val( colorScheme[value].colors[1] ) 37 .data( 'data-default-color', colorScheme[value].colors[1] ) 38 .wpColorPicker( 'color', colorScheme[value].colors[1] ) 39 .wpColorPicker( 'defaultColor', colorScheme[value].colors[1] ); 40 41 // update Sidebar Text Color 42 wp.customize( 'sidebar_textcolor' ).set( colorScheme[value].colors[4] ); 43 sidebarTextColor.val( colorScheme[value].colors[4] ) 44 .data( 'data-default-color', colorScheme[value].colors[4] ) 45 .wpColorPicker( 'color', colorScheme[value].colors[4] ) 46 .wpColorPicker( 'defaultColor', colorScheme[value].colors[4] ); 47 } ); 48 } ); 49 } 48 50 } 49 51 } ); 50 52 } )( this.wp ); 53 No newline at end of file