Make WordPress Core


Ignore:
Timestamp:
04/25/2012 09:03:29 PM (14 years ago)
Author:
koopersmith
Message:

Theme Customizer: Add statuses to the color and image controls. see #19910.

Move the color control from the switch statement to WP_Customize_Color_Control.
Markup improvements.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/class-wp-customize-control.php

    r20545 r20598  
    6565     * @since 3.4.0
    6666     */
    67     public function enqueue() {
    68         switch( $this->type ) {
    69             case 'color':
    70                 wp_enqueue_script( 'farbtastic' );
    71                 wp_enqueue_style( 'farbtastic' );
    72                 break;
    73         }
    74     }
     67    public function enqueue() {}
    7568
    7669
     
    177170                <?php
    178171                break;
    179             case 'color':
    180                 ?>
    181                 <label>
    182                     <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
    183                     <div class="dropdown color-picker-toggle">
    184                         <div class="dropdown-content color-picker-spot"></div>
    185                         <div class="dropdown-arrow"></div>
    186                     </div>
    187                     <div class="color-picker-control color-picker-hex">
    188                         <span>#</span>
    189                         <input type="text" <?php $this->link(); ?> />
    190                     </div>
    191                     <div class="color-picker-control farbtastic-placeholder"></div>
    192                 </label>
    193                 <?php
    194                 break;
    195172            case 'checkbox':
    196173                ?>
    197174                <label>
    198175                    <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
    199                     <input type="checkbox" value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); checked( $this->value() ); ?> class="customize-control-content" />
     176                    <input type="checkbox" value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); checked( $this->value() ); ?> />
    200177                </label>
    201178                <?php
     
    226203                <label>
    227204                    <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
    228                     <select <?php $this->link(); ?> class="customize-control-content">
     205                    <select <?php $this->link(); ?>>
    229206                        <?php
    230207                        foreach ( $this->choices as $value => $label )
     
    259236}
    260237
     238class WP_Customize_Color_Control extends WP_Customize_Control {
     239    public $type = 'color';
     240    public $statuses;
     241
     242    public function __construct( $manager, $id, $args = array() ) {
     243        $this->statuses = array( '' => __('Default') );
     244        parent::__construct( $manager, $id, $args );
     245    }
     246
     247    public function enqueue() {
     248        wp_enqueue_script( 'farbtastic' );
     249        wp_enqueue_style( 'farbtastic' );
     250    }
     251
     252    public function to_json() {
     253        parent::to_json();
     254        $this->json['statuses'] = $this->statuses;
     255    }
     256
     257    public function render_content() {
     258        ?>
     259        <label>
     260            <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
     261            <div class="customize-control-content">
     262                <div class="dropdown">
     263                    <div class="dropdown-content">
     264                        <div class="dropdown-status"></div>
     265                    </div>
     266                    <div class="dropdown-arrow"></div>
     267                </div>
     268                <div class="color-picker-hex">
     269                    <span>#</span>
     270                    <input type="text" <?php $this->link(); ?> />
     271                </div>
     272            </div>
     273            <div class="farbtastic-placeholder"></div>
     274        </label>
     275        <?php
     276    }
     277}
     278
    261279class WP_Customize_Upload_Control extends WP_Customize_Control {
    262280    public $type    = 'upload';
     
    293311    public $type = 'image';
    294312    public $get_url;
     313    public $statuses;
    295314
    296315    protected $tabs = array();
    297316
    298317    public function __construct( $manager, $id, $args ) {
     318        $this->statuses = array( '' => __('No Image') );
     319
    299320        parent::__construct( $manager, $id, $args );
    300321
    301322        $this->add_tab( 'upload-new', __('Upload New'), array( $this, 'tab_upload_new' ) );
    302323        $this->add_tab( 'uploaded',   __('Uploaded'),   array( $this, 'tab_uploaded' ) );
     324    }
     325
     326    public function to_json() {
     327        parent::to_json();
     328        $this->json['statuses'] = $this->statuses;
    303329    }
    304330
     
    312338            <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
    313339
    314 
    315             <div class="dropdown preview-thumbnail">
    316                 <div class="dropdown-content">
    317                     <?php if ( empty( $src ) ): ?>
    318                         <img style="display:none;" />
    319                     <?php else: ?>
    320                         <img src="<?php echo esc_url( $src ); ?>" />
    321                     <?php endif; ?>
     340            <div class="customize-control-content">
     341                <div class="dropdown preview-thumbnail">
     342                    <div class="dropdown-content">
     343                        <?php if ( empty( $src ) ): ?>
     344                            <img style="display:none;" />
     345                        <?php else: ?>
     346                            <img src="<?php echo esc_url( $src ); ?>" />
     347                        <?php endif; ?>
     348                        <div class="dropdown-status"></div>
     349                    </div>
     350                    <div class="dropdown-arrow"></div>
    322351                </div>
    323                 <div class="dropdown-arrow"></div>
    324352            </div>
    325353
     
    375403    public function __construct( $manager ) {
    376404        parent::__construct( $manager, 'header_image', array(
    377             'label'   => __( 'Header Image' ),
    378             'section' => 'header',
    379             'context' => 'custom-header',
    380             'removed' => 'remove-header',
    381             'get_url' => 'get_header_image',
     405            'label'    => __( 'Header Image' ),
     406            'section'  => 'header',
     407            'context'  => 'custom-header',
     408            'removed'  => 'remove-header',
     409            'get_url'  => 'get_header_image',
     410            'statuses' => array(
     411                ''                      => __('Default'),
     412                'remove-header'         => __('No Image'),
     413                'random-default-image'  => __('Random Default Image'),
     414                'random-uploaded-image' => __('Random Uploaded Image'),
     415            )
    382416        ) );
    383417
Note: See TracChangeset for help on using the changeset viewer.