Preview by default the registered default image for custom backgrounds. props mfields, billerickson.

If there is a default color registered, show a 'Default' action rather than a 'Clear' action, as clearing the value would simply return to the default.

Make current_theme_supports() accept a second argument for 'custom-background' requests, the same as get_theme_support(). Missed in earlier changes, see #20249.

fixes #20734, fixes #18041.



git-svn-id: http://core.svn.wordpress.org/trunk@20901 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
nacin 2012-05-25 17:58:57 +00:00
parent f58b088cfd
commit afad27974e
3 changed files with 66 additions and 56 deletions

View File

@ -207,15 +207,15 @@ if ( $bgcolor = get_background_color() )
if ( get_background_image() ) { if ( get_background_image() ) {
// background-image URL must be single quote, see below // background-image URL must be single quote, see below
$background_styles .= ' background-image: url(\'' . set_url_scheme( get_theme_mod('background_image_thumb', '') ) . '\');' $background_styles .= ' background-image: url(\'' . set_url_scheme( get_theme_mod( 'background_image_thumb', get_background_image() ) ) . '\');'
. ' background-repeat: ' . get_theme_mod('background_repeat', 'repeat') . ';' . ' background-repeat: ' . get_theme_mod('background_repeat', 'repeat') . ';'
. ' background-position: top ' . get_theme_mod('background_position_x', 'left'); . ' background-position: top ' . get_theme_mod('background_position_x', 'left');
} }
?> ?>
<div id="custom-background-image" style="<?php echo $background_styles; ?>"><?php // must be double quote, see above ?> <div id="custom-background-image" style="<?php echo $background_styles; ?>"><?php // must be double quote, see above ?>
<?php if ( get_background_image() ) { ?> <?php if ( get_background_image() ) { ?>
<img class="custom-background-image" src="<?php echo set_url_scheme( get_theme_mod('background_image_thumb', '') ); ?>" style="visibility:hidden;" alt="" /><br /> <img class="custom-background-image" src="<?php echo set_url_scheme( get_theme_mod( 'background_image_thumb', get_background_image() ) ); ?>" style="visibility:hidden;" alt="" /><br />
<img class="custom-background-image" src="<?php echo set_url_scheme( get_theme_mod('background_image_thumb', '') ); ?>" style="visibility:hidden;" alt="" /> <img class="custom-background-image" src="<?php echo set_url_scheme( get_theme_mod( 'background_image_thumb', get_background_image() ) ); ?>" style="visibility:hidden;" alt="" />
<?php } ?> <?php } ?>
</div> </div>
<?php } ?> <?php } ?>
@ -322,9 +322,10 @@ if ( get_background_image() ) {
<tr valign="top"> <tr valign="top">
<th scope="row"><?php _e( 'Background Color' ); ?></th> <th scope="row"><?php _e( 'Background Color' ); ?></th>
<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Color' ); ?></span></legend> <td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Color' ); ?></span></legend>
<?php $show_clear = get_background_color() ? '' : ' style="display:none"'; ?> <?php $show_clear = get_theme_mod('background_color') ? '' : ' style="display:none"'; ?>
<input type="text" name="background-color" id="background-color" value="#<?php echo esc_attr(get_background_color()) ?>" /> <input type="text" name="background-color" id="background-color" value="#<?php echo esc_attr(get_background_color()) ?>" />
<a class="hide-if-no-js" href="#" id="pickcolor"><?php _e('Select a Color'); ?></a> <span<?php echo $show_clear; ?> class="hide-if-no-js" id="clearcolor"> (<a href="#"><?php _e( 'Clear' ); ?></a>)</span> <a class="hide-if-no-js" href="#" id="pickcolor"><?php _e('Select a Color'); ?></a> <span<?php echo $show_clear; ?> class="hide-if-no-js" id="clearcolor"> (<a href="#"><?php current_theme_supports( 'custom-background', 'default-color' ) ? _e( 'Default' ) : _e( 'Clear' ); ?></a>)</span>
<input type="hidden" id="defaultcolor" value="<?php if ( current_theme_supports( 'custom-background', 'default-color' ) ) echo '#' . esc_attr( get_theme_support( 'custom-background', 'default-color' ) ); ?>" />
<div id="colorPickerDiv" style="z-index: 100; background:#eee; border:1px solid #ccc; position:absolute; display:none;"></div> <div id="colorPickerDiv" style="z-index: 100; background:#eee; border:1px solid #ccc; position:absolute; display:none;"></div>
</fieldset></td> </fieldset></td>
</tr> </tr>

View File

@ -1,55 +1,63 @@
var farbtastic; var farbtastic, pickColor;
function pickColor(color) { (function($) {
farbtastic.setColor(color);
jQuery('#background-color').val(color);
jQuery('#custom-background-image').css('background-color', color);
if ( color && color !== '#' )
jQuery('#clearcolor').show();
else
jQuery('#clearcolor').hide();
}
jQuery(document).ready(function() { pickColor = function(color, cleared) {
jQuery('#pickcolor').click(function() { farbtastic.setColor(color);
jQuery('#colorPickerDiv').show(); $('#background-color').val(color);
return false; $('#custom-background-image').css('background-color', color);
}); console.log( color );
if ( typeof cleared === 'undefined' )
cleared = ! color || color === '#';
if ( cleared )
$('#clearcolor').hide();
else
$('#clearcolor').show();
}
jQuery('#clearcolor a').click( function(e) { $(document).ready(function() {
pickColor('');
e.preventDefault(); $('#pickcolor').click(function() {
}); $('#colorPickerDiv').show();
return false;
jQuery('#background-color').keyup(function() { });
var _hex = jQuery('#background-color').val(), hex = _hex;
if ( hex.charAt(0) != '#' ) $('#clearcolor a').click( function(e) {
hex = '#' + hex; pickColor( $('#defaultcolor').val(), true );
hex = hex.replace(/[^#a-fA-F0-9]+/, ''); e.preventDefault();
if ( hex != _hex ) });
jQuery('#background-color').val(hex);
if ( hex.length == 4 || hex.length == 7 ) $('#background-color').keyup(function() {
pickColor( hex ); var _hex = $('#background-color').val(), hex = _hex;
}); if ( hex.charAt(0) != '#' )
hex = '#' + hex;
jQuery('input[name="background-position-x"]').change(function() { hex = hex.replace(/[^#a-fA-F0-9]+/, '');
jQuery('#custom-background-image').css('background-position', jQuery(this).val() + ' top'); if ( hex != _hex )
}); $('#background-color').val(hex);
if ( hex.length == 4 || hex.length == 7 )
jQuery('input[name="background-repeat"]').change(function() { pickColor( hex );
jQuery('#custom-background-image').css('background-repeat', jQuery(this).val()); });
});
$('input[name="background-position-x"]').change(function() {
farbtastic = jQuery.farbtastic('#colorPickerDiv', function(color) { $('#custom-background-image').css('background-position', $(this).val() + ' top');
pickColor(color); });
});
pickColor(jQuery('#background-color').val()); $('input[name="background-repeat"]').change(function() {
$('#custom-background-image').css('background-repeat', $(this).val());
jQuery(document).mousedown(function(){ });
jQuery('#colorPickerDiv').each(function(){
var display = jQuery(this).css('display'); farbtastic = $.farbtastic('#colorPickerDiv', function(color) {
if ( display == 'block' ) pickColor(color);
jQuery(this).fadeOut(2); });
pickColor($('#background-color').val());
$(document).mousedown(function(){
$('#colorPickerDiv').each(function(){
var display = $(this).css('display');
if ( display == 'block' )
$(this).fadeOut(2);
});
}); });
}); });
});
})(jQuery);

View File

@ -1501,7 +1501,8 @@ function current_theme_supports( $feature ) {
break; break;
case 'custom-header': case 'custom-header':
// specific custom header capabilities can be registered by passing case 'custom-background' :
// specific custom header and background capabilities can be registered by passing
// an array to add_theme_support() // an array to add_theme_support()
$header_support = $args[0]; $header_support = $args[0];
return ( isset( $_wp_theme_features[$feature][0][$header_support] ) && $_wp_theme_features[$feature][0][$header_support] ); return ( isset( $_wp_theme_features[$feature][0][$header_support] ) && $_wp_theme_features[$feature][0][$header_support] );