Make WordPress Core

Ticket #12186: background-repeat2.diff

File background-repeat2.diff, 6.2 KB (added by jshreve, 15 years ago)

background-repeat with preview

  • wp-includes/theme.php

     
    14401440        if ( !$background && !$color )
    14411441                return;
    14421442
    1443         $repeat = get_theme_mod('background_repeat', 'repeat');
    1444         if ( 'no-repeat' == $repeat )
    1445                 $repeat = 'background-repeat: no-repeat;';
    1446         else
    1447                 $repeat = 'background-repeat: repeat;';
    1448         $position = get_theme_mod('background_position', 'left');
    1449         if  ( 'center' == $position )
    1450                 $position = 'background-position: top center;';
    1451         elseif ( 'right' == $position )
    1452                 $position = 'background-position: top right;';
    1453         else
    1454                 $position = 'background-position: top left;';
    1455         $attachment = get_theme_mod('background_attachment', 'fixed');
    1456         if ( 'scroll' == $attachment )
     1443        switch( get_theme_mod('background_repeat', 'repeat') ) {
     1444       
     1445                case 'no-repeat':
     1446                        $repeat = 'background-repeat: no-repeat;';
     1447                        break;
     1448                case 'repeat-x';
     1449                        $repeat = 'background-repeat: repeat-x;';
     1450                        break;         
     1451                case 'repeat-y':
     1452                        $repeat = 'background-repeat: repeat-y;';               
     1453                        break;
     1454                default:
     1455                        $repeat = 'background-repeat: repeat;';
     1456        }
     1457
     1458        switch ( get_theme_mod('background_position', 'left') ) {
     1459                case 'center':
     1460                        $position = 'background-position: top center;';
     1461                        break;
     1462                case 'right':
     1463                        $position = 'background-position: top right;';
     1464                        break;
     1465                default:
     1466                        $position = 'background-position: top left;';
     1467        }
     1468
     1469        if ( 'scroll' == get_theme_mod('background_attachment', 'fixed') )
    14571470                $attachment = 'background-attachment: scroll;';
    14581471        else
    14591472                $attachment = 'background-attachment: fixed;';
     
    14631476        else
    14641477                $image = '';
    14651478
    1466         if ( !empty($background ) )
    1467                 $image = "background-image: url('$background');";
    1468         else
    1469                 $image = '';
    1470 
    14711479        if ( !empty($color) )
    14721480                $color = "background-color: #$color;";
    14731481        else
  • wp-admin/js/custom-background.dev.js

     
    2222                        pickColor( hex );
    2323        });
    2424        jQuery('input[name="background-position"]').change(function() {
    25                 jQuery('#custom-background-image').css('text-align', jQuery(this).val());
     25                jQuery('#custom-background-image').css('background-position', 'top '+jQuery(this).val());
    2626        });
    27 
     27        jQuery('select[name="background-repeat"]').change(function() {
     28                jQuery('#custom-background-image').css('background-repeat', jQuery(this).val());
     29        });
     30       
    2831        farbtastic = jQuery.farbtastic('#colorPickerDiv', function(color) {
    2932                pickColor(color);
    3033        });
  • wp-admin/css/wp-admin.dev.css

     
    36623662
    36633663div#custom-background-image img {
    36643664        max-width: 400px;
    3665         max-height: 200px;
     3665        max-height: 300px;
    36663666}
    36673667
    36683668/* Custom Header */
  • wp-admin/custom-background.php

     
    9898                }
    9999
    100100                if ( isset($_POST['background-repeat']) ) {
    101                         if ( in_array($_POST['background-repeat'], array('repeat', 'no-repeat')) )
     101                        if ( in_array($_POST['background-repeat'], array('repeat', 'no-repeat', 'repeat-x', 'repeat-y')) )
    102102                                $repeat = $_POST['background-repeat'];
    103103                        else
    104104                                $repeat = 'repeat';
     
    149149        if ( $this->admin_image_div_callback ) {
    150150                call_user_func($this->admin_image_div_callback);
    151151        } else {
    152                 if ( $bgcolor = get_background_color() )
    153                         $bgcolor = 'background-color: #' . $bgcolor . ';';
     152?>
    154153
    155                 if ( $align = get_theme_mod('background_position', 'left') )
    156                         $align = "text-align: $align;";         
    157 ?>
    158 <div id="custom-background-image"  style="<?php echo $bgcolor, $align ?>">
     154<style type="text/css">
     155#custom-background-image {
     156        background-color: #<?=get_background_color()?>;
     157        <?php if ( get_background_image() ) { ?>
     158        background: url(<?=get_theme_mod('background_image_thumb', '')?>);
     159        background-repeat: <?=get_theme_mod('background_repeat', 'no-repeat')?>;
     160        background-position: top <?=get_theme_mod('background_position', 'left')?>;
     161        background-attachment: <?=get_theme_mod('background_position', 'fixed')?>;
     162        <?php } ?>
     163}
     164</style>
     165<div id="custom-background-image">
    159166<?php if ( get_background_image() ) { ?>
    160 <img class="custom-background-image" src="<?php background_image(); ?>" />
     167<img class="custom-background-image" src="<?=get_theme_mod('background_image_thumb', '')?>" style="visibility:hidden;" />
    161168<?php } ?>
    162169<br class="clear" />
    163170</div>
     
    192199
    193200<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Repeat' ); ?></span></legend>
    194201<label>
    195 <input name="background-repeat" type="radio" value="no-repeat" <?php checked('no-repeat', get_theme_mod('background_repeat', 'repeat')); ?> />
    196 <?php _e('No repeat') ?>
     202<select name="background-repeat">
     203        <option value="no-repeat" <?php selected('no-repeat', get_theme_mod('background_repeat', 'repeat')); ?> ><?php _e('No repeat') ?></option>
     204        <option value="repeat" <?php selected('repeat', get_theme_mod('background_repeat', 'repeat')); ?>><?php _e('Tile') ?></option>
     205        <option value="repeat-x" <?php selected('repeat-x', get_theme_mod('background_repeat', 'repeat')); ?>><?php _e('Tile Horizontally') ?></option>
     206        <option value="repeat-y" <?php selected('repeat-y', get_theme_mod('background_repeat', 'repeat')); ?>><?php _e('Tile Vertically') ?></option>
     207</select>
    197208</label>
    198 <label>
    199 <input name="background-repeat" type="radio" value="repeat" <?php checked('repeat', get_theme_mod('background_repeat', 'repeat')); ?> />
    200 <?php _e('Tile') ?>
    201 </label>
    202209</fieldset></td>
    203210
    204211<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Attachment' ); ?></span></legend>
     
    286293                wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
    287294
    288295                set_theme_mod('background_image', esc_url($url));
     296               
     297                $thumbnail = wp_get_attachment_image_src( $id, 'thumbnail' );
     298                set_theme_mod('background_image_thumb', esc_url( $thumbnail[0] ) );
     299               
    289300                do_action('wp_create_file_in_uploads', $file, $id); // For replication
    290301                $this->updated = true;
    291302        }