Changeset 13574
- Timestamp:
- 03/03/2010 05:10:43 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/custom-background.php
r13339 r13574 58 58 $page = add_theme_page(__('Background'), __('Background'), 'switch_themes', 'custom-background', array(&$this, 'admin_page')); 59 59 60 add_action("admin_head-$page", array(&$this, 'take_action'), 50); 60 add_action("admin_print_scripts-$page", array(&$this, 'js_includes')); 61 add_action("admin_print_styles-$page", array(&$this, 'css_includes')); 62 add_action("admin_head-$page", array(&$this, 'js'), 50); 63 add_action("admin_head-$page", array(&$this, 'take_action'), 49); 61 64 if ( $this->admin_header_callback ) 62 65 add_action("admin_head-$page", $this->admin_header_callback, 51); … … 79 82 80 83 return $step; 84 } 85 86 /** 87 * Setup the enqueue for the JavaScript files. 88 * 89 * @since unknown 90 */ 91 function js_includes() { 92 $step = $this->step(); 93 94 if ( 1 == $step ) 95 wp_enqueue_script('farbtastic'); 96 } 97 98 /** 99 * Setup the enqueue for the CSS files 100 * 101 * @since unknown 102 */ 103 function css_includes() { 104 $step = $this->step(); 105 106 if ( 1 == $step ) 107 wp_enqueue_style('farbtastic'); 81 108 } 82 109 … … 120 147 if ( isset($_POST['remove-background']) ) 121 148 set_theme_mod('background_image', ''); 149 if ( isset( $_POST['background-color'] ) ) { 150 $color = preg_replace('/[^0-9a-fA-F]/', '', $_POST['background-color']); 151 if ( strlen($color) == 6 || strlen($color) == 3 ) 152 set_theme_mod('background_color', $color); 153 else 154 set_theme_mod('background_color', ''); 155 } 156 } 157 158 /** 159 * Execute Javascript depending on step. 160 * 161 * @since unknown 162 */ 163 function js() { 164 $step = $this->step(); 165 if ( 1 == $step ) 166 $this->js_1(); 167 } 168 169 /** 170 * Display Javascript based on Step 1. 171 * 172 * @since unknown 173 */ 174 function js_1() { ?> 175 <script type="text/javascript"> 176 var buttons = ['#pickcolor'], 177 farbtastic; 178 179 function pickColor(color) { 180 jQuery('#background-color').val(color); 181 farbtastic.setColor(color); 182 } 183 184 jQuery(document).ready(function() { 185 jQuery('#pickcolor').click(function() { 186 jQuery('#colorPickerDiv').show(); 187 }); 188 189 farbtastic = jQuery.farbtastic('#colorPickerDiv', function(color) { pickColor(color); }); 190 pickColor('#<?php background_color(); ?>'); 191 }); 192 193 jQuery(document).mousedown(function(){ 194 hide_picker(); // Make the picker disappear if you click outside its div element 195 }); 196 197 function hide_picker(what) { 198 var update = false; 199 jQuery('#colorPickerDiv').each(function(){ 200 var id = jQuery(this).attr('id'); 201 if (id == what) { 202 return; 203 } 204 var display = jQuery(this).css('display'); 205 if (display == 'block') { 206 jQuery(this).fadeOut(2); 207 } 208 }); 209 } 210 211 </script> 212 <?php 122 213 } 123 214 … … 144 235 } else { 145 236 ?> 146 <div id="custom-background-image" >237 <div id="custom-background-image" style="background-color: #<?php background_color(); ?>;"> 147 238 <img class="custom-background-image" src="<?php background_image(); ?>" /> 148 239 </div> … … 162 253 <th scope="col"><?php _e( 'Repeat' ); ?></th> 163 254 <th scope="col"><?php _e( 'Attachment' ); ?></th> 255 <th scope="col"><?php _e( 'Color' ); ?></th> 164 256 </tr> 165 257 … … 201 293 <?php _e('Fixed') ?> 202 294 </label> 295 </fieldset></td> 296 297 <td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Color' ); ?></span></legend> 298 <input type="text" name="background-color" id="background-color" value="#<?php echo esc_attr(get_background_color()) ?>" /> 299 <input type="button" class="button" value="<?php esc_attr_e('Select a Color'); ?>" id="pickcolor" /> 300 301 <div id="colorPickerDiv" style="z-index: 100; background:#eee; border:1px solid #ccc; position:absolute; display:none;"></div> 203 302 </fieldset></td> 204 303 </tr> -
trunk/wp-includes/theme.php
r13469 r13574 1358 1358 */ 1359 1359 function get_background_image() { 1360 $default = 1360 $default = defined('BACKGROUND_IMAGE') ? BACKGROUND_IMAGE : ''; 1361 1361 1362 1362 return get_theme_mod('background_image', $default); … … 1370 1370 function background_image() { 1371 1371 echo get_background_image(); 1372 } 1373 1374 /** 1375 * Retrieve value for custom background color. 1376 * 1377 * @since 3.0.0 1378 * @uses BACKGROUND_COLOR 1379 * 1380 * @return string 1381 */ 1382 function get_background_color() { 1383 $default = defined('BACKGROUND_COLOR') ? BACKGROUND_COLOR : ''; 1384 1385 return get_theme_mod('background_color', $default); 1386 } 1387 1388 /** 1389 * Display background color value. 1390 * 1391 * @since 3.0.0 1392 */ 1393 function background_color() { 1394 echo get_background_color(); 1372 1395 } 1373 1396 … … 1438 1461 <style type="text/css"> 1439 1462 body { 1440 background-image:url('<?php background_image(); ?>'); 1463 background-color: #<?php background_color(); ?>; 1464 background-image: url('<?php background_image(); ?>'); 1441 1465 <?php echo $repeat; ?> 1442 1466 <?php echo $position; ?>
Note: See TracChangeset
for help on using the changeset viewer.