diff --git a/wp-admin/custom-background.php b/wp-admin/custom-background.php index fc231c4c3..77cd50900 100644 --- a/wp-admin/custom-background.php +++ b/wp-admin/custom-background.php @@ -1,15 +1,15 @@ admin_header_callback ) add_action("admin_head-$page", $this->admin_header_callback, 51); } /** - * Get the current step. + * Set up the enqueue for the CSS & JavaScript files. * - * @since unknown - * - * @return int Current step + * @since 3.0 */ - function step() { - if ( ! isset( $_GET['step'] ) ) - return 1; - - $step = (int) $_GET['step']; - if ( $step < 1 || 3 < $step ) - $step = 1; - - return $step; - } - - /** - * Set up the enqueue for the JavaScript files. - * - * @since unknown - */ - function js_includes() { - wp_enqueue_script('farbtastic'); - } - - /** - * Set up the enqueue for the CSS files - * - * @since unknown - */ - function css_includes() { + function admin_load() { + wp_enqueue_script('custom-background'); wp_enqueue_style('farbtastic'); } /** * Execute custom background modification. * - * @since unknown + * @since 3.0 */ function take_action() { - if ( ! current_user_can('switch_themes') ) - return; if ( empty($_POST) ) return; check_admin_referer('custom-background'); - if ( isset($_POST['reset-background']) ) + // @TODO: No UI entry point for this: + if ( isset($_POST['reset-background']) ) { remove_theme_mods(); + return; + } + if ( isset($_POST['remove-background']) ) { + // @TODO: Uploaded files are not removed here. + set_theme_mod('background_image', ''); + } + if ( isset($_POST['background-repeat']) ) { if ( in_array($_POST['background-repeat'], array('repeat', 'no-repeat')) ) $repeat = $_POST['background-repeat']; @@ -138,9 +118,7 @@ class Custom_Background { $attachment = 'fixed'; set_theme_mod('background_attachment', $attachment); } - if ( isset($_POST['remove-background']) ) - set_theme_mod('background_image', ''); - if ( isset( $_POST['background-color'] ) ) { + if ( isset($_POST['background-color']) ) { $color = preg_replace('/[^0-9a-fA-F]/', '', $_POST['background-color']); if ( strlen($color) == 6 || strlen($color) == 3 ) set_theme_mod('background_color', $color); @@ -152,78 +130,11 @@ class Custom_Background { } /** - * Execute Javascript depending on step. + * Display the custom background page. * - * @since unknown + * @since 3.0 */ - function js() { - $this->js_1(); - } - - /** - * Display Javascript based on Step 1. - * - * @since unknown - */ - function js_1() { ?> - -
@@ -239,18 +150,20 @@ class Custom_Background { call_user_func($this->admin_image_div_callback); } else { if ( $bgcolor = get_background_color() ) - $bgcolor = ' style="background-color: #' . $bgcolor . ';"'; - else - $bgcolor = ''; + $bgcolor = 'background-color: #' . $bgcolor . ';'; + + if ( $align = get_theme_mod('background_position', 'left') ) + $align = "text-align: $align;"; ?> -
> +
+

-
+ @@ -314,7 +227,7 @@ class Custom_Background {

- +
@@ -326,22 +239,26 @@ class Custom_Background {

- + - + false); $file = wp_handle_upload($_FILES['import'], $overrides); @@ -371,31 +288,6 @@ class Custom_Background { set_theme_mod('background_image', esc_url($url)); do_action('wp_create_file_in_uploads', $file, $id); // For replication $this->updated = true; - return $this->finished(); - } - - /** - * Display last step of custom header image page. - * - * @since unknown - */ - function finished() { - $this->step_1(); - } - - /** - * Display the page based on the current step. - * - * @since unknown - */ - function admin_page() { - if ( ! current_user_can('switch_themes') ) - wp_die(__('You do not have permission to customize the background.')); - $step = $this->step(); - if ( 1 == $step ) - $this->step_1(); - elseif ( 2 == $step ) - $this->step_2(); } } diff --git a/wp-admin/js/custom-background.dev.js b/wp-admin/js/custom-background.dev.js new file mode 100644 index 000000000..568a2a2b8 --- /dev/null +++ b/wp-admin/js/custom-background.dev.js @@ -0,0 +1,49 @@ +var buttons = ['#pickcolor'], farbtastic; + +function pickColor(color) { + jQuery('#background-color').val(color); + farbtastic.setColor(color); + jQuery('#custom-background-image').css('background-color', color); +} + +jQuery(document).ready(function() { + jQuery('#pickcolor').click(function() { + jQuery('#colorPickerDiv').show(); + }); + jQuery('#background-color').keyup(function() { + var _hex = jQuery('#background-color').val(); + var hex = _hex; + if ( hex[0] != '#' ) + hex = '#' + hex; + hex = hex.replace(/[^#a-fA-F0-9]+/, ''); + if ( hex != _hex ) + jQuery('#background-color').val(hex); + if ( hex.length == 4 || hex.length == 7 ) + pickColor( hex ); + }); + jQuery('input[name="background-position"]').change(function() { + jQuery('#custom-background-image img').attr('align', jQuery(this).val() ); + }); + + farbtastic = jQuery.farbtastic('#colorPickerDiv', function(color) { + pickColor(color); + }); + pickColor(customBackgroundL10n.backgroundcolor); +}); + +jQuery(document).mousedown(function(){ + hide_picker(); // Make the picker disappear if you click outside its div element +}); + +function hide_picker(what) { + var update = false; + jQuery('#colorPickerDiv').each(function(){ + var id = jQuery(this).attr('id'); + if ( id == what ) + return; + + var display = jQuery(this).css('display'); + if ( display == 'block' ) + jQuery(this).fadeOut(2); + }); +} \ No newline at end of file diff --git a/wp-admin/js/custom-background.js b/wp-admin/js/custom-background.js new file mode 100644 index 000000000..9873fef92 --- /dev/null +++ b/wp-admin/js/custom-background.js @@ -0,0 +1 @@ +var buttons=["#pickcolor"],farbtastic;function pickColor(color){jQuery("#background-color").val(color);farbtastic.setColor(color);jQuery("#custom-background-image").css("background-color",color)}jQuery(document).ready(function(){jQuery("#pickcolor").click(function(){jQuery("#colorPickerDiv").show()});jQuery("#background-color").keyup(function(){var _hex=jQuery("#background-color").val();var hex=_hex;if(hex[0]!="#"){hex="#"+hex}hex=hex.replace(/[^#a-fA-F0-9]+/,"");if(hex!=_hex){jQuery("#background-color").val(hex)}if(hex.length==4||hex.length==7){pickColor(hex)}});jQuery('input[name="background-position"]').change(function(){jQuery("#custom-background-image img").attr("align",jQuery(this).val())});farbtastic=jQuery.farbtastic("#colorPickerDiv",function(color){pickColor(color)});pickColor(customBackgroundL10n.backgroundcolor)});jQuery(document).mousedown(function(){hide_picker()});function hide_picker(what){var update=false;jQuery("#colorPickerDiv").each(function(){var id=jQuery(this).attr("id");if(id==what){return}var display=jQuery(this).css("display");if(display=="block"){jQuery(this).fadeOut(2)}})}; \ No newline at end of file diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index c215b010f..9adbb5149 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -406,6 +406,11 @@ function wp_default_scripts( &$scripts ) { 'edit' => _x('Edit', 'menu item edit text'), 'warnDelete' => __( "You are about to permanently delete this menu. \n 'Cancel' to stop, 'OK' to delete." ), ) ); + + $scripts->add( 'custom-background', "/wp-admin/js/custom-background$suffix.js", array('farbtastic'), '20100321' ); + $scripts->add_data( 'custom-background', 'group', 1 ); + // See wp_just_in_time_script_localization() for translation data for this object + } } @@ -509,7 +514,7 @@ function wp_prototype_before_jquery( $js_array ) { } /** - * Load localized script just in time for MCE. + * Load localized data on print rather than initialization. * * These localizations require information that may not be loaded even by init. * @@ -526,6 +531,10 @@ function wp_just_in_time_script_localization() { 'saveAlert' => __('The changes you made will be lost if you navigate away from this page.'), 'l10n_print_after' => 'try{convertEntities(autosaveL10n);}catch(e){};' ) ); + + wp_localize_script( 'custom-background', 'customBackgroundL10n', array( + 'backgroundcolor' => '#' . get_background_color(), + ) ); } /**