themes-wordpress/varia/js/customize-preview.js
Allan Cole de4366ebd0 Varia: Improvements to custom colors
- Add a11y color note to customizer
- Remove image filter function.
- Improve selection colors
- Code tidying
2020-05-12 17:48:38 -04:00

49 lines
1.4 KiB
JavaScript
Executable file

/**
* File customizer.js.
*
* Theme Customizer enhancements for a better user experience.
*
* Contains handlers to make Theme Customizer preview reload changes asynchronously.
*/
(function( $ ) {
// Primary color.
wp.customize( 'primary_color', function( value ) {
value.bind( function( to ) {
// Update custom color CSS.
var style = $( '#custom-theme-colors' ),
hue = style.data( 'hue' ),
css = style.html(),
color;
if( 'custom' === to ){
// If a custom primary color is selected, use the currently set primary_color_hue
color = wp.customize.get().primary_color_hue;
} else {
// If the "default" option is selected, get the default primary_color_hue
color = VariaPreviewData.default_hue;
}
// Equivalent to css.replaceAll, with hue followed by comma to prevent values with units from being changed.
css = css.split( hue + ',' ).join( color + ',' );
style.html( css ).data( 'hue', color );
});
});
// Primary color hue.
wp.customize( 'primary_color_hue', function( value ) {
value.bind( function( to ) {
// Update custom color CSS.
var style = $( '#custom-theme-colors' ),
hue = style.data( 'hue' ),
css = style.html();
// Equivalent to css.replaceAll, with hue followed by comma to prevent values with units from being changed.
css = css.split( hue + ',' ).join( to + ',' );
style.html( css ).data( 'hue', to );
});
});
})( jQuery );