<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[13574] trunk: Background color selection.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/13574">13574</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2010-03-03 17:10:43 +0000 (Wed, 03 Mar 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>Background color selection. Props lancewillett. see <a href="http://trac.wordpress.org/ticket/12186">#12186</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadmincustombackgroundphp">trunk/wp-admin/custom-background.php</a></li>
<li><a href="#trunkwpincludesthemephp">trunk/wp-includes/theme.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadmincustombackgroundphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/custom-background.php (13573 => 13574)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/custom-background.php        2010-03-03 16:45:40 UTC (rev 13573)
+++ trunk/wp-admin/custom-background.php        2010-03-03 17:10:43 UTC (rev 13574)
</span><span class="lines">@@ -57,7 +57,10 @@
</span><span class="cx">
</span><span class="cx">                 $page = add_theme_page(__('Background'), __('Background'), 'switch_themes', 'custom-background', array(&$this, 'admin_page'));
</span><span class="cx">
</span><del>-                add_action("admin_head-$page", array(&$this, 'take_action'), 50);
</del><ins>+                add_action("admin_print_scripts-$page", array(&$this, 'js_includes'));
+                add_action("admin_print_styles-$page", array(&$this, 'css_includes'));
+                add_action("admin_head-$page", array(&$this, 'js'), 50);
+                add_action("admin_head-$page", array(&$this, 'take_action'), 49);
</ins><span class="cx">                 if ( $this->admin_header_callback )
</span><span class="cx">                         add_action("admin_head-$page", $this->admin_header_callback, 51);
</span><span class="cx">         }
</span><span class="lines">@@ -81,6 +84,30 @@
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         /**
</span><ins>+         * Setup the enqueue for the JavaScript files.
+         *
+         * @since unknown
+         */
+        function js_includes() {
+                $step = $this->step();
+
+                if ( 1 == $step )
+                        wp_enqueue_script('farbtastic');
+        }
+
+        /**
+         * Setup the enqueue for the CSS files
+         *
+         * @since unknown
+         */
+        function css_includes() {
+                $step = $this->step();
+
+                if ( 1 == $step )
+                        wp_enqueue_style('farbtastic');
+        }
+
+        /**
</ins><span class="cx">          * Execute custom background modification.
</span><span class="cx">          *
</span><span class="cx">          * @since unknown
</span><span class="lines">@@ -119,9 +146,73 @@
</span><span class="cx">                 }
</span><span class="cx">                 if ( isset($_POST['remove-background']) )
</span><span class="cx">                         set_theme_mod('background_image', '');
</span><ins>+                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);
+                        else
+                                set_theme_mod('background_color', '');
+                }
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         /**
</span><ins>+         * Execute Javascript depending on step.
+         *
+         * @since unknown
+         */
+        function js() {
+                $step = $this->step();
+                if ( 1 == $step )
+                        $this->js_1();
+        }
+
+        /**
+         * Display Javascript based on Step 1.
+         *
+         * @since unknown
+         */
+        function js_1() { ?>
+<script type="text/javascript">
+        var buttons = ['#pickcolor'],
+                farbtastic;
+
+        function pickColor(color) {
+                jQuery('#background-color').val(color);
+                farbtastic.setColor(color);
+        }
+
+        jQuery(document).ready(function() {
+                jQuery('#pickcolor').click(function() {
+                        jQuery('#colorPickerDiv').show();
+                });
+
+                farbtastic = jQuery.farbtastic('#colorPickerDiv', function(color) { pickColor(color); });
+                pickColor('#<?php background_color(); ?>');
+        });
+
+        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);
+                        }
+                });
+        }
+
+</script>
+<?php
+        }
+
+        /**
</ins><span class="cx">          * Display first step of custom background image page.
</span><span class="cx">          *
</span><span class="cx">          * @since unknown
</span><span class="lines">@@ -143,7 +234,7 @@
</span><span class="cx">                 call_user_func($this->admin_image_div_callback);
</span><span class="cx">         } else {
</span><span class="cx"> ?>
</span><del>-<div id="custom-background-image">
</del><ins>+<div id="custom-background-image" style="background-color: #<?php background_color(); ?>;">
</ins><span class="cx"> <img class="custom-background-image" src="<?php background_image(); ?>" />
</span><span class="cx"> </div>
</span><span class="cx"> <?php }
</span><span class="lines">@@ -161,6 +252,7 @@
</span><span class="cx"> <th scope="col"><?php _e( 'Position' ); ?></th>
</span><span class="cx"> <th scope="col"><?php _e( 'Repeat' ); ?></th>
</span><span class="cx"> <th scope="col"><?php _e( 'Attachment' ); ?></th>
</span><ins>+<th scope="col"><?php _e( 'Color' ); ?></th>
</ins><span class="cx"> </tr>
</span><span class="cx">
</span><span class="cx"> <tbody>
</span><span class="lines">@@ -201,6 +293,13 @@
</span><span class="cx"> <?php _e('Fixed') ?>
</span><span class="cx"> </label>
</span><span class="cx"> </fieldset></td>
</span><ins>+
+<td><fieldset><legend class="screen-reader-text"><span><?php _e( '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>
</ins><span class="cx"> </tr>
</span><span class="cx"> </tbody>
</span><span class="cx"> </table>
</span></span></pre></div>
<a id="trunkwpincludesthemephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/theme.php (13573 => 13574)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/theme.php        2010-03-03 16:45:40 UTC (rev 13573)
+++ trunk/wp-includes/theme.php        2010-03-03 17:10:43 UTC (rev 13574)
</span><span class="lines">@@ -1357,7 +1357,7 @@
</span><span class="cx"> * @return string
</span><span class="cx"> */
</span><span class="cx"> function get_background_image() {
</span><del>-        $default = defined('BACKGROUND_IMAGE') ? BACKGROUND_IMAGE : '';
</del><ins>+        $default = defined('BACKGROUND_IMAGE') ? BACKGROUND_IMAGE : '';
</ins><span class="cx">
</span><span class="cx">         return get_theme_mod('background_image', $default);
</span><span class="cx"> }
</span><span class="lines">@@ -1372,6 +1372,29 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><ins>+ * Retrieve value for custom background color.
+ *
+ * @since 3.0.0
+ * @uses BACKGROUND_COLOR
+ *
+ * @return string
+ */
+function get_background_color() {
+        $default = defined('BACKGROUND_COLOR') ? BACKGROUND_COLOR : '';
+
+        return get_theme_mod('background_color', $default);
+}
+
+/**
+ * Display background color value.
+ *
+ * @since 3.0.0
+ */
+function background_color() {
+        echo get_background_color();
+}
+
+/**
</ins><span class="cx"> * Add callbacks for background image display.
</span><span class="cx"> *
</span><span class="cx"> * The parameter $header_callback callback will be required to display the
</span><span class="lines">@@ -1437,7 +1460,8 @@
</span><span class="cx"> ?>
</span><span class="cx"> <style type="text/css">
</span><span class="cx"> body {
</span><del>-        background-image:url('<?php background_image(); ?>');
</del><ins>+        background-color: #<?php background_color(); ?>;
+        background-image: url('<?php background_image(); ?>');
</ins><span class="cx">         <?php echo $repeat; ?>
</span><span class="cx">         <?php echo $position; ?>
</span><span class="cx">         <?php echo $attachment; ?>
</span></span></pre>
</div>
</div>
</body>
</html>