Ticket #29572: 29572.diff
| File 29572.diff, 7.0 KB (added by , 11 years ago) |
|---|
-
src/wp-admin/customize.php
180 180 <div id="customize-preview" class="wp-full-overlay-main"></div> 181 181 <?php 182 182 183 // Render control templates. 184 $wp_customize->render_control_templates(); 185 183 186 /** 184 187 * Print Customizer control scripts in the footer. 185 188 * -
src/wp-admin/js/customize-controls.js
60 60 } 61 61 62 62 control.setting = control.settings['default'] || null; 63 control.ready(); 63 control.renderContent( function() { 64 // Don't call ready() until the content has rendered. 65 control.ready(); 66 } ); 64 67 }) ); 65 68 66 69 control.elements = []; … … 149 152 150 153 this.setting.bind( update ); 151 154 update( this.setting() ); 155 }, 156 157 /** 158 * Render the control from its JS template, if it exists. 159 * 160 * The control's container must alreasy exist in the DOM. 161 */ 162 renderContent: function( callback ) { 163 var template, 164 selector = 'customize-control-' + this.params.type + '-content', 165 callback = callback || function(){}; 166 if ( 0 !== $( '#tmpl-' + selector ).length ) { 167 template = wp.template( selector ); 168 if ( template && this.container ) { 169 this.container.append( template( this.params ) ); 170 } 171 } 172 callback(); 152 173 } 153 174 }); 154 175 -
src/wp-includes/class-wp-customize-control.php
217 217 $this->json['settings'][ $key ] = $setting->id; 218 218 } 219 219 220 $this->json['type'] = $this->type; 221 $this->json['active'] = $this->active(); 220 $this->json['type'] = $this->type; 221 $this->json['label'] = $this->label; 222 $this->json['description'] = $this->description; 223 $this->json['active'] = $this->active(); 222 224 } 223 225 224 226 /** … … 336 338 * Supports basic input types `text`, `checkbox`, `textarea`, `radio`, `select` and `dropdown-pages`. 337 339 * Additional input types such as `email`, `url`, `number`, `hidden` and `date` are supported implicitly. 338 340 * 341 * Control content can alternately be rendered in JS. See WP_Customize_Control::print_template(). 342 * 339 343 * @since 3.4.0 340 344 */ 341 345 protected function render_content() { … … 443 447 break; 444 448 } 445 449 } 450 451 /** 452 * Render the control's JS template. 453 * 454 * This function is only run for control types that have been registered with $wp_customize->register_control_type. 455 * 456 * In the future, this will also print the template for the control's container element. 457 * 458 * @since 4.1.0 459 */ 460 public function print_template() { 461 ?> 462 <script type="text/html" id="tmpl-customize-control-<?php echo $this->type; ?>-content"> 463 <?php $this->content_template(); ?> 464 </script> 465 <?php 466 } 467 468 /** 469 * A JavaScript template for this control's content (but not its container). 470 * 471 * All class variables for this control class are available in the `data` JS object. 472 * 473 * @see WP_Customize_Control::print_template() 474 * 475 * @todo link to docs on what formatting to use. 476 * 477 * @since 4.1.0 478 */ 479 protected function content_template() {} 446 480 } 447 481 448 482 /** … … 499 533 public function to_json() { 500 534 parent::to_json(); 501 535 $this->json['statuses'] = $this->statuses; 536 $this->json['defaultValue'] = $this->setting->default; 502 537 } 503 538 504 539 /** 505 * Render the control's content.540 * Don't render the control content from PHP, as it's rendered via JS on load. 506 541 * 507 * @since 3.4.0542 * @since 4.1.0 508 543 */ 509 public function render_content() { 510 $this_default = $this->setting->default; 511 $default_attr = ''; 512 if ( $this_default ) { 513 if ( false === strpos( $this_default, '#' ) ) 514 $this_default = '#' . $this_default; 515 $default_attr = ' data-default-color="' . esc_attr( $this_default ) . '"'; 516 } 517 // The input's value gets set by JS. Don't fill it. 544 public function render_content() {} 545 546 /** 547 * Render a JS template for the control's content. 548 * 549 * @since 4.1.0 550 */ 551 public function content_template() { 518 552 ?> 553 <# var defaultValue = ''; 554 if ( data.defaultValue ) { 555 if ( '#' !== data.defaultValue.substring( 0, 1 ) ) { 556 defaultValue = '#' + data.defaultValue; 557 } 558 defaultValue = ' data-default-color=' + defaultValue; // Quotes added automatically. 559 } #> 519 560 <label> 520 < ?php if ( ! empty( $this->label ) ) : ?>521 <span class="customize-control-title"> <?php echo esc_html( $this->label ); ?></span>522 < ?php endif;523 if ( ! empty( $this->description ) ) : ?>524 <span class="description customize-control-description"> <?php echo $this->description; ?></span>525 < ?php endif; ?>561 <# if ( data.label ) { #> 562 <span class="customize-control-title">{{ data.label }}</span> 563 <# } #> 564 <# if ( data.description ) { #> 565 <span class="description customize-control-description">{{ data.description }}</span> 566 <# } #> 526 567 527 568 <div class="customize-control-content"> 528 <input class="color-picker-hex" type="text" maxlength="7" placeholder="<?php esc_attr_e( 'Hex Value' ); ?>" <?php echo $default_attr; ?>/>569 <input class="color-picker-hex" type="text" maxlength="7" placeholder="<?php esc_attr_e( 'Hex Value' ); ?>" {{ defaultValue }} /> 529 570 </div> 530 571 </label> 531 572 <?php -
src/wp-includes/class-wp-customize-manager.php
54 54 protected $customized; 55 55 56 56 /** 57 * Controls that may be rendered from JS templates. 58 * 59 * @since 4.1.0 60 */ 61 protected $registered_control_types = array(); 62 63 /** 57 64 * $_POST values for Customize Settings. 58 65 * 59 66 * @var array … … 822 829 } 823 830 824 831 /** 832 * Register a customize control type. 833 * 834 * Registered types are eligible to be rendered 835 * via JS and created dynamically. 836 * 837 * @since 4.1.0 838 * 839 * @param string $control Custom control class. 840 */ 841 public function register_control_type( $control ) { 842 $this->registered_control_types[] = $control; 843 } 844 845 /** 846 * Render JS templates for all registered control types. 847 * 848 * @since 4.1.0 849 */ 850 public function render_control_templates() { 851 foreach( $this->registered_control_types as $control_type ) { 852 $control = new $control_type( $this, 'temp', array() ); 853 $control->print_template(); 854 } 855 } 856 857 /** 825 858 * Helper function to compare two objects by priority. 826 859 * 827 860 * @since 3.4.0 … … 927 960 */ 928 961 public function register_controls() { 929 962 963 /* Control Types (custom control classes) */ 964 $this->register_control_type( 'WP_Customize_Color_Control' ); 965 930 966 /* Site Title & Tagline */ 931 967 932 968 $this->add_section( 'title_tagline', array(