Changeset 29944
- Timestamp:
- 10/17/2014 08:51:46 PM (10 years ago)
- Location:
- trunk/src/wp-content/themes/twentyfifteen
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-content/themes/twentyfifteen/inc/customizer.php
r29942 r29944 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. … … 58 59 } 59 60 add_action( 'customize_register', 'twentyfifteen_customize_register', 11 ); 60 61 /**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 61 101 62 /** … … 662 623 663 624 /** 625 * Binds JS listener to make Customizer color_scheme control. 626 * Passes color scheme data as colorScheme global 627 * 628 * @since Twenty Fifteen 1.0 629 */ 630 function twentyfifteen_customize_control_js() { 631 wp_enqueue_script( 'color-scheme-control', get_template_directory_uri() . '/js/color-scheme-control.js', array( 'customize-controls' ), '', true ); 632 wp_localize_script( 'color-scheme-control', 'colorScheme', twentyfifteen_get_color_schemes() ); 633 } 634 add_action( 'customize_controls_enqueue_scripts', 'twentyfifteen_customize_control_js' ); 635 636 /** 664 637 * Binds JS handlers to make Customizer preview reload changes asynchronously. 665 638 * -
trunk/src/wp-content/themes/twentyfifteen/js/color-scheme-control.js
r29903 r29944 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 } );
Note: See TracChangeset
for help on using the changeset viewer.