<!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(&amp;$this, 'admin_page'));
</span><span class="cx"> 
</span><del>-                add_action(&quot;admin_head-$page&quot;, array(&amp;$this, 'take_action'), 50);
</del><ins>+                add_action(&quot;admin_print_scripts-$page&quot;, array(&amp;$this, 'js_includes'));
+                add_action(&quot;admin_print_styles-$page&quot;, array(&amp;$this, 'css_includes'));
+                add_action(&quot;admin_head-$page&quot;, array(&amp;$this, 'js'), 50);
+                add_action(&quot;admin_head-$page&quot;, array(&amp;$this, 'take_action'), 49);
</ins><span class="cx">                 if ( $this-&gt;admin_header_callback )
</span><span class="cx">                         add_action(&quot;admin_head-$page&quot;, $this-&gt;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-&gt;step();
+
+                if ( 1 == $step )
+                        wp_enqueue_script('farbtastic');
+        }
+
+        /**
+         * Setup the enqueue for the CSS files
+         *
+         * @since unknown
+         */
+        function css_includes() {
+                $step = $this-&gt;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-&gt;step();
+                if ( 1 == $step )
+                        $this-&gt;js_1();
+        }
+
+        /**
+         * Display Javascript based on Step 1.
+         *
+         * @since unknown
+         */
+        function js_1() { ?&gt;
+&lt;script type=&quot;text/javascript&quot;&gt;
+        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('#&lt;?php background_color(); ?&gt;');
+        });
+
+        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);
+                        }
+                });
+        }
+
+&lt;/script&gt;
+&lt;?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-&gt;admin_image_div_callback);
</span><span class="cx">         } else {
</span><span class="cx"> ?&gt;
</span><del>-&lt;div id=&quot;custom-background-image&quot;&gt;
</del><ins>+&lt;div id=&quot;custom-background-image&quot; style=&quot;background-color: #&lt;?php background_color(); ?&gt;;&quot;&gt;
</ins><span class="cx"> &lt;img class=&quot;custom-background-image&quot; src=&quot;&lt;?php background_image(); ?&gt;&quot; /&gt;
</span><span class="cx"> &lt;/div&gt;
</span><span class="cx"> &lt;?php }
</span><span class="lines">@@ -161,6 +252,7 @@
</span><span class="cx"> &lt;th scope=&quot;col&quot;&gt;&lt;?php _e( 'Position' ); ?&gt;&lt;/th&gt;
</span><span class="cx"> &lt;th scope=&quot;col&quot;&gt;&lt;?php _e( 'Repeat' ); ?&gt;&lt;/th&gt;
</span><span class="cx"> &lt;th scope=&quot;col&quot;&gt;&lt;?php _e( 'Attachment' ); ?&gt;&lt;/th&gt;
</span><ins>+&lt;th scope=&quot;col&quot;&gt;&lt;?php _e( 'Color' ); ?&gt;&lt;/th&gt;
</ins><span class="cx"> &lt;/tr&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;tbody&gt;
</span><span class="lines">@@ -201,6 +293,13 @@
</span><span class="cx"> &lt;?php _e('Fixed') ?&gt;
</span><span class="cx"> &lt;/label&gt;
</span><span class="cx"> &lt;/fieldset&gt;&lt;/td&gt;
</span><ins>+
+&lt;td&gt;&lt;fieldset&gt;&lt;legend class=&quot;screen-reader-text&quot;&gt;&lt;span&gt;&lt;?php _e( 'Color' ); ?&gt;&lt;/span&gt;&lt;/legend&gt;
+&lt;input type=&quot;text&quot; name=&quot;background-color&quot; id=&quot;background-color&quot; value=&quot;#&lt;?php echo esc_attr(get_background_color()) ?&gt;&quot; /&gt;
+&lt;input type=&quot;button&quot; class=&quot;button&quot; value=&quot;&lt;?php esc_attr_e('Select a Color'); ?&gt;&quot; id=&quot;pickcolor&quot; /&gt;
+
+&lt;div id=&quot;colorPickerDiv&quot; style=&quot;z-index: 100; background:#eee; border:1px solid #ccc; position:absolute; display:none;&quot;&gt;&lt;/div&gt;
+&lt;/fieldset&gt;&lt;/td&gt;
</ins><span class="cx"> &lt;/tr&gt;
</span><span class="cx"> &lt;/tbody&gt;
</span><span class="cx"> &lt;/table&gt;
</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"> ?&gt;
</span><span class="cx"> &lt;style type=&quot;text/css&quot;&gt;
</span><span class="cx"> body {
</span><del>-        background-image:url('&lt;?php background_image(); ?&gt;');
</del><ins>+        background-color: #&lt;?php background_color(); ?&gt;;
+        background-image: url('&lt;?php background_image(); ?&gt;');
</ins><span class="cx">         &lt;?php echo $repeat; ?&gt;
</span><span class="cx">         &lt;?php echo $position; ?&gt;
</span><span class="cx">         &lt;?php echo $attachment; ?&gt;
</span></span></pre>
</div>
</div>

</body>
</html>