Ticket #12186: custom-background.3.diff
File custom-background.3.diff, 4.0 KB (added by , 15 years ago) |
---|
-
Applications/MAMP/htdocs/wordpress/wp/wp-admin/custom-background.php
57 57 58 58 $page = add_theme_page(__('Custom Background'), __('Custom Background'), 'switch_themes', 'custom-background', array(&$this, 'admin_page')); 59 59 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); 60 63 add_action("admin_head-$page", array(&$this, 'take_action'), 50); 61 64 if ( $this->admin_header_callback ) 62 65 add_action("admin_head-$page", $this->admin_header_callback, 51); … … 81 84 } 82 85 83 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'); 108 } 109 110 /** 84 111 * Execute custom background modification. 85 112 * 86 113 * @since unknown … … 119 146 } 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 } 122 154 } 123 155 124 156 /** 157 * Execute Javascript depending on step. 158 * 159 * @since unknown 160 */ 161 function js() { 162 $step = $this->step(); 163 if ( 1 == $step ) 164 $this->js_1(); 165 } 166 167 /** 168 * Display Javascript based on Step 1. 169 * 170 * @since unknown 171 */ 172 function js_1() { ?> 173 <script type="text/javascript"> 174 var buttons = ['#pickcolor'], 175 farbtastic; 176 177 function pickColor(color) { 178 jQuery('#background-color').val(color); 179 farbtastic.setColor(color); 180 } 181 182 jQuery(document).ready(function() { 183 jQuery('#pickcolor').click(function() { 184 jQuery('#colorPickerDiv').show(); 185 }); 186 187 farbtastic = jQuery.farbtastic('#colorPickerDiv', function(color) { pickColor(color); }); 188 pickColor('#<?php background_color(); ?>'); 189 }); 190 191 jQuery(document).mousedown(function(){ 192 hide_picker(); // Make the picker disappear if you click outside its div element 193 }); 194 195 function hide_picker(what) { 196 var update = false; 197 jQuery('#colorPickerDiv').each(function(){ 198 var id = jQuery(this).attr('id'); 199 if (id == what) { 200 return; 201 } 202 var display = jQuery(this).css('display'); 203 if (display == 'block') { 204 jQuery(this).fadeOut(2); 205 } 206 }); 207 } 208 209 </script> 210 <?php 211 } 212 213 /** 125 214 * Display first step of custom background image page. 126 215 * 127 216 * @since unknown … … 143 232 call_user_func($this->admin_image_div_callback); 144 233 } else { 145 234 ?> 146 <div id="custom-background-image" >235 <div id="custom-background-image" style="background-color: #<?php background_color(); ?>;"> 147 236 <img class="custom-background-image" src="<?php background_image(); ?>" /> 148 237 </div> 149 238 <?php } … … 161 250 <th scope="col"><?php _e( 'Position' ); ?></th> 162 251 <th scope="col"><?php _e( 'Repeat' ); ?></th> 163 252 <th scope="col"><?php _e( 'Attachment' ); ?></th> 253 <th scope="col"><?php _e( 'Background Color' ); ?></th> 164 254 </tr> 165 255 166 256 <tbody> … … 201 291 <?php _e('Fixed') ?> 202 292 </label> 203 293 </fieldset></td> 294 295 <td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Color' ); ?></span></legend> 296 <input type="text" name="background-color" id="background-color" value="#<?php esc_attr(background_color()) ?>" /> 297 <input type="button" class="button" value="<?php esc_attr_e('Select a Color'); ?>" id="pickcolor" /> 298 299 <div id="colorPickerDiv" style="z-index: 100; background:#eee; border:1px solid #ccc; position:absolute; display:none;"></div> 300 </fieldset></td> 204 301 </tr> 205 302 </tbody> 206 303 </table>