Displays JavaScript based on Step 1 and 3.
Source
public function js_1() {
$default_color = '';
if ( current_theme_supports( 'custom-header', 'default-text-color' ) ) {
$default_color = get_theme_support( 'custom-header', 'default-text-color' );
if ( $default_color && ! str_contains( $default_color, '#' ) ) {
$default_color = '#' . $default_color;
}
}
?>
<script type="text/javascript">
(function($){
var default_color = '<?php echo esc_js( $default_color ); ?>',
header_text_fields;
function pickColor(color) {
$('#name').css('color', color);
$('#desc').css('color', color);
$('#text-color').val(color);
}
function toggle_text() {
var checked = $('#display-header-text').prop('checked'),
text_color;
header_text_fields.toggle( checked );
if ( ! checked )
return;
text_color = $('#text-color');
if ( '' === text_color.val().replace('#', '') ) {
text_color.val( default_color );
pickColor( default_color );
} else {
pickColor( text_color.val() );
}
}
$( function() {
var text_color = $('#text-color');
header_text_fields = $('.displaying-header-text');
text_color.wpColorPicker({
change: function( event, ui ) {
pickColor( text_color.wpColorPicker('color') );
},
clear: function() {
pickColor( '' );
}
});
$('#display-header-text').click( toggle_text );
<?php if ( ! display_header_text() ) : ?>
toggle_text();
<?php endif; ?>
} );
})(jQuery);
</script>
<?php
}
Changelog
Version | Description |
---|---|
2.6.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.