Custom background UI updates. props ocean90 for initial patch, see #12186.

git-svn-id: http://svn.automattic.com/wordpress/trunk@14684 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
nacin 2010-05-16 05:17:57 +00:00
parent fa29e51128
commit d6e2ef4dbf
5 changed files with 42 additions and 51 deletions

View File

@ -91,6 +91,7 @@ class Custom_Background {
remove_theme_mod('background_image_thumb');
return;
}
if ( isset($_POST['remove-background']) ) {
// @TODO: Uploaded files are not removed here.
check_admin_referer('custom-background-remove', '_wpnonce-custom-background-remove');
@ -107,14 +108,16 @@ class Custom_Background {
$repeat = 'repeat';
set_theme_mod('background_repeat', $repeat);
}
if ( isset($_POST['background-position']) ) {
if ( isset($_POST['background-position-x']) ) {
check_admin_referer('custom-background');
if ( in_array($_POST['background-position'], array('center', 'right', 'left')) )
$position = $_POST['background-position'];
if ( in_array($_POST['background-position-x'], array('center', 'right', 'left')) )
$position = $_POST['background-position-x'];
else
$position = 'left';
set_theme_mod('background_position', $position);
set_theme_mod('background_position_x', $position);
}
if ( isset($_POST['background-attachment']) ) {
check_admin_referer('custom-background');
if ( in_array($_POST['background-attachment'], array('fixed', 'scroll')) )
@ -123,6 +126,7 @@ class Custom_Background {
$attachment = 'fixed';
set_theme_mod('background_attachment', $attachment);
}
if ( isset($_POST['background-color']) ) {
check_admin_referer('custom-background');
$color = preg_replace('/[^0-9a-fA-F]/', '', $_POST['background-color']);
@ -155,33 +159,29 @@ class Custom_Background {
call_user_func($this->admin_image_div_callback);
} else {
?>
<h3><?php _e('Background Preview'); ?></h3>
<h3><?php _e('Background Image'); ?></h3>
<table class="form-table">
<tbody>
<tr valign="top">
<th scope="row"><?php _e('Current Background'); ?></th>
<th scope="row"><?php _e('Preview'); ?></th>
<td>
<?php
$background_styles = '';
if ( $bgcolor = get_background_color() ) {
$background_styles .= "background-color: #{$bgcolor};";
}
if ( $bgcolor = get_background_color() )
$background_styles .= 'background-color: #' . $bgcolor . ';';
if ( get_background_image() ) {
$background_styles .= "
background-image: url(" . get_theme_mod('background_image_thumb', '') . ");
background-repeat: ". get_theme_mod('background_repeat', 'repeat') . ";
background-position: ". get_theme_mod('background_position', 'left') . " top;
background-attachment: " . get_theme_mod('background_attachment', 'fixed') . ";
";
if ( get_background_image() ) {
// background-image URL must be single quote, see below
$background_styles .= ' background-image: url(\'' . get_theme_mod('background_image_thumb', '') . '\');'
. ' background-repeat: ' . get_theme_mod('background_repeat', 'repeat') . ';'
. ' background-position: top ' . get_theme_mod('background_position_x', 'left');
}
?>
<div id="custom-background-image" style="<?php echo $background_styles; ?>">
<div id="custom-background-image" style="<?php echo $background_styles; ?>"><?php // must be double quote, see above ?>
<?php if ( get_background_image() ) { ?>
<img class="custom-background-image" src="<?php echo get_theme_mod('background_image_thumb', ''); ?>" style="visibility:hidden;" alt="" /><br />
<img class="custom-background-image" src="<?php echo get_theme_mod('background_image_thumb', ''); ?>" style="visibility:hidden;" alt="" />
<?php } ?>
<br class="clear" />
</div>
<?php } ?>
</td>
@ -189,10 +189,11 @@ if ( get_background_image() ) {
<?php if ( get_background_image() ) : ?>
<tr valign="top">
<th scope="row"><?php _e('Remove Image'); ?></th>
<td><p><?php _e('This will remove the background image. You will not be able to restore any customizations.') ?></p>
<td>
<form method="post" action="">
<?php wp_nonce_field('custom-background-remove', '_wpnonce-custom-background-remove'); ?>
<input type="submit" class="button" name="remove-background" value="<?php esc_attr_e('Remove Background'); ?>" />
<input type="submit" class="button" name="remove-background" value="<?php esc_attr_e('Remove Background Image'); ?>" /><br/>
<?php _e('This will remove the background image. You will not be able to restore any customizations.') ?>
</form>
</td>
</tr>
@ -201,10 +202,11 @@ if ( get_background_image() ) {
<?php if ( defined( 'BACKGROUND_IMAGE' ) ) : // Show only if a default background image exists ?>
<tr valign="top">
<th scope="row"><?php _e('Restore Original Image'); ?></th>
<td><p><?php _e('This will restore the original background image. You will not be able to restore any customizations.') ?></p>
<td>
<form method="post" action="">
<?php wp_nonce_field('custom-background-reset', '_wpnonce-custom-background-reset'); ?>
<input type="submit" class="button" name="reset-background" value="<?php esc_attr_e('Restore Original Image'); ?>" />
<input type="submit" class="button" name="reset-background" value="<?php esc_attr_e('Restore Original Image'); ?>" /><br/>
<?php _e('This will restore the original background image. You will not be able to restore any customizations.') ?>
</form>
</td>
</tr>
@ -216,8 +218,7 @@ if ( get_background_image() ) {
<label for="upload"><?php _e('Choose an image from your computer:'); ?></label><br /><input type="file" id="upload" name="import" />
<input type="hidden" name="action" value="save" />
<?php wp_nonce_field('custom-background-upload', '_wpnonce-custom-background-upload') ?>
<p class="submit">
<input type="submit" value="<?php esc_attr_e('Upload'); ?>" />
<input type="submit" class="button" value="<?php esc_attr_e('Upload'); ?>" />
</p>
</form>
</td>
@ -230,28 +231,27 @@ if ( get_background_image() ) {
<table class="form-table">
<tbody>
<tr valign="top">
<th scope="row"><?php _e( 'Background Color' ); ?></th>
<th scope="row"><?php _e( 'Color' ); ?></th>
<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Color' ); ?></span></legend>
<input type="text" name="background-color" id="background-color" value="#<?php echo esc_attr(get_background_color()) ?>" />
<input type="button" class="button" value="<?php esc_attr_e('Select a Color'); ?>" id="pickcolor" />
<div id="colorPickerDiv" style="z-index: 100; background:#eee; border:1px solid #ccc; position:absolute; display:none;"></div>
</fieldset></td>
</tr>
<?php if ( get_background_image() ) : ?>
<tr valign="top">
<th scope="row"><?php _e( 'Background Position' ); ?></th>
<th scope="row"><?php _e( 'Position' ); ?></th>
<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Position' ); ?></span></legend>
<label>
<input name="background-position" type="radio" value="left" <?php checked('left', get_theme_mod('background_position', 'left')); ?> />
<input name="background-position-x" type="radio" value="left"<?php checked('left', get_theme_mod('background_position_x', 'left')); ?> />
<?php _e('Left') ?>
</label>
<label>
<input name="background-position" type="radio" value="center" <?php checked('center', get_theme_mod('background_position', 'left')); ?> />
<input name="background-position-x" type="radio" value="center"<?php checked('center', get_theme_mod('background_position_x', 'left')); ?> />
<?php _e('Center') ?>
</label>
<label>
<input name="background-position" type="radio" value="right" <?php checked('right', get_theme_mod('background_position', 'left')); ?> />
<input name="background-position-x" type="radio" value="right"<?php checked('right', get_theme_mod('background_position_x', 'left')); ?> />
<?php _e('Right') ?>
</label>
</fieldset></td>
@ -262,10 +262,10 @@ if ( get_background_image() ) {
<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Repeat' ); ?></span></legend>
<label>
<select name="background-repeat">
<option value="no-repeat" <?php selected('no-repeat', get_theme_mod('background_repeat', 'repeat')); ?> ><?php _e('No repeat'); ?></option>
<option value="repeat" <?php selected('repeat', get_theme_mod('background_repeat', 'repeat')); ?>><?php _e('Tile'); ?></option>
<option value="repeat-x" <?php selected('repeat-x', get_theme_mod('background_repeat', 'repeat')); ?>><?php _e('Tile Horizontally'); ?></option>
<option value="repeat-y" <?php selected('repeat-y', get_theme_mod('background_repeat', 'repeat')); ?>><?php _e('Tile Vertically'); ?></option>
<option value="no-repeat"<?php selected('no-repeat', get_theme_mod('background_repeat', 'repeat')); ?> ><?php _e('No repeat'); ?></option>
<option value="repeat"<?php selected('repeat', get_theme_mod('background_repeat', 'repeat')); ?>><?php _e('Tile'); ?></option>
<option value="repeat-x"<?php selected('repeat-x', get_theme_mod('background_repeat', 'repeat')); ?>><?php _e('Tile Horizontally'); ?></option>
<option value="repeat-y"<?php selected('repeat-y', get_theme_mod('background_repeat', 'repeat')); ?>><?php _e('Tile Vertically'); ?></option>
</select>
</label>
</fieldset></td>
@ -284,7 +284,7 @@ if ( get_background_image() ) {
</label>
</fieldset></td>
</tr>
<?php endif; // get_background_image() ?>
</tbody>
</table>

View File

@ -12,8 +12,7 @@ jQuery(document).ready(function() {
});
jQuery('#background-color').keyup(function() {
var _hex = jQuery('#background-color').val();
var hex = _hex;
var _hex = jQuery('#background-color').val(), hex = _hex;
if ( hex[0] != '#' )
hex = '#' + hex;
hex = hex.replace(/[^#a-fA-F0-9]+/, '');
@ -23,17 +22,13 @@ jQuery(document).ready(function() {
pickColor( hex );
});
jQuery('input[name="background-position"]').change(function() {
jQuery('#custom-background-image').css('background-position', 'top ' + jQuery(this).val());
jQuery('input[name="background-position-x"]').change(function() {
jQuery('#custom-background-image').css('background-position', jQuery(this).val() + ' top');
});
jQuery('select[name="background-repeat"]').change(function() {
jQuery('#custom-background-image').css('background-repeat', jQuery(this).val());
});
jQuery('input[name="background-attachment"]').change(function() {
jQuery('#custom-background-image').css('background-attachment', jQuery(this).val());
});
farbtastic = jQuery.farbtastic('#colorPickerDiv', function(color) {
pickColor(color);

View File

@ -1 +1 @@
var farbtastic;function pickColor(a){farbtastic.setColor(a);jQuery("#background-color").val(a);jQuery("#custom-background-image").css("background-color",a)}jQuery(document).ready(function(){jQuery("#pickcolor").click(function(){jQuery("#colorPickerDiv").show()});jQuery("#background-color").keyup(function(){var b=jQuery("#background-color").val();var a=b;if(a[0]!="#"){a="#"+a}a=a.replace(/[^#a-fA-F0-9]+/,"");if(a!=b){jQuery("#background-color").val(a)}if(a.length==4||a.length==7){pickColor(a)}});jQuery('input[name="background-position"]').change(function(){jQuery("#custom-background-image").css("background-position","top "+jQuery(this).val())});jQuery('select[name="background-repeat"]').change(function(){jQuery("#custom-background-image").css("background-repeat",jQuery(this).val())});jQuery('input[name="background-attachment"]').change(function(){jQuery("#custom-background-image").css("background-attachment",jQuery(this).val())});farbtastic=jQuery.farbtastic("#colorPickerDiv",function(a){pickColor(a)});pickColor(jQuery("#background-color").val());jQuery(document).mousedown(function(){jQuery("#colorPickerDiv").each(function(){var a=jQuery(this).css("display");if(a=="block"){jQuery(this).fadeOut(2)}})})});
var farbtastic;function pickColor(a){farbtastic.setColor(a);jQuery("#background-color").val(a);jQuery("#custom-background-image").css("background-color",a)}jQuery(document).ready(function(){jQuery("#pickcolor").click(function(){jQuery("#colorPickerDiv").show()});jQuery("#background-color").keyup(function(){var b=jQuery("#background-color").val(),a=b;if(a[0]!="#"){a="#"+a}a=a.replace(/[^#a-fA-F0-9]+/,"");if(a!=b){jQuery("#background-color").val(a)}if(a.length==4||a.length==7){pickColor(a)}});jQuery('input[name="background-position-x"]').change(function(){jQuery("#custom-background-image").css("background-position",jQuery(this).val()+" top")});jQuery('select[name="background-repeat"]').change(function(){jQuery("#custom-background-image").css("background-repeat",jQuery(this).val())});farbtastic=jQuery.farbtastic("#colorPickerDiv",function(a){pickColor(a)});pickColor(jQuery("#background-color").val());jQuery(document).mousedown(function(){jQuery("#colorPickerDiv").each(function(){var a=jQuery(this).css("display");if(a=="block"){jQuery(this).fadeOut(2)}})})});

View File

@ -405,9 +405,8 @@ function wp_default_scripts( &$scripts ) {
'warnDeleteMenuItem' => __( "You are about to permanently delete this menu item. \n 'Cancel' to stop, 'OK' to delete." ),
) );
$scripts->add( 'custom-background', "/wp-admin/js/custom-background$suffix.js", array('farbtastic'), '20100321' );
$scripts->add( 'custom-background', "/wp-admin/js/custom-background$suffix.js", array('farbtastic'), '20100516' );
$scripts->add_data( 'custom-background', 'group', 1 );
// See wp_just_in_time_script_localization() for translation data for this object
}
}
@ -529,9 +528,6 @@ function wp_just_in_time_script_localization() {
'l10n_print_after' => 'try{convertEntities(autosaveL10n);}catch(e){};'
) );
wp_localize_script( 'custom-background', 'customBackgroundL10n', array(
'backgroundcolor' => '#' . get_background_color(),
) );
}
/**

View File

@ -1553,7 +1553,7 @@ function _custom_background_cb() {
$repeat = 'background-repeat: repeat;';
}
switch ( get_theme_mod('background_position', 'left') ) {
switch ( get_theme_mod('background_position_x', 'left') ) {
case 'center':
$position = 'background-position: top center;';
break;