color-scheme-control.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* global colorScheme */
  2. /**
  3. * Theme Customizer enhancements for a better user experience.
  4. *
  5. * Adds listener to Color Scheme control to update other color controls with new values/defaults
  6. */
  7. ( function( wp ) {
  8. wp.customize.controlConstructor.colorScheme = wp.customize.Control.extend( {
  9. ready: function() {
  10. var parentSection = this.container.closest( '.control-section' ),
  11. headerTextColor = parentSection.find( '#customize-control-header_textcolor .color-picker-hex' ),
  12. backgroundColor = parentSection.find( '#customize-control-background_color .color-picker-hex' ),
  13. sidebarColor = parentSection.find( '#customize-control-header_background_color .color-picker-hex' ),
  14. sidebarTextColor = parentSection.find( '#customize-control-sidebar_textcolor .color-picker-hex' );
  15. this.setting.bind( 'change', function( value ) {
  16. // if Header Text is not hidden, update value
  17. if ( 'blank' !== wp.customize( 'header_textcolor' ).get() ) {
  18. wp.customize( 'header_textcolor' ).set( colorScheme[value].colors[4] );
  19. headerTextColor.val( colorScheme[value].colors[4] )
  20. .data( 'data-default-color', colorScheme[value].colors[4] )
  21. .wpColorPicker( 'color', colorScheme[value].colors[4] )
  22. .wpColorPicker( 'defaultColor', colorScheme[value].colors[4] );
  23. }
  24. // update Background Color
  25. wp.customize( 'background_color' ).set( colorScheme[value].colors[0] );
  26. backgroundColor.val( colorScheme[value].colors[0] )
  27. .data( 'data-default-color', colorScheme[value].colors[0] )
  28. .wpColorPicker( 'color', colorScheme[value].colors[0] )
  29. .wpColorPicker( 'defaultColor', colorScheme[value].colors[0] );
  30. // update Header/Sidebar Background Color
  31. wp.customize( 'header_background_color' ).set( colorScheme[value].colors[1] );
  32. sidebarColor.val( colorScheme[value].colors[1] )
  33. .data( 'data-default-color', colorScheme[value].colors[1] )
  34. .wpColorPicker( 'color', colorScheme[value].colors[1] )
  35. .wpColorPicker( 'defaultColor', colorScheme[value].colors[1] );
  36. // update Sidebar Text Color
  37. wp.customize( 'sidebar_textcolor' ).set( colorScheme[value].colors[4] );
  38. sidebarTextColor.val( colorScheme[value].colors[4] )
  39. .data( 'data-default-color', colorScheme[value].colors[4] )
  40. .wpColorPicker( 'color', colorScheme[value].colors[4] )
  41. .wpColorPicker( 'defaultColor', colorScheme[value].colors[4] );
  42. } );
  43. }
  44. } );
  45. } )( this.wp );