Ticket #30737: 30737.2.diff
File 30737.2.diff, 15.3 KB (added by , 10 years ago) |
---|
-
src/wp-admin/customize.php
184 184 <div id="customize-preview" class="wp-full-overlay-main"></div> 185 185 <?php 186 186 187 // Render control templates. 187 // Render Panel, Section, and Control templates. 188 $wp_customize->render_panel_templates(); 189 $wp_customize->render_section_templates(); 188 190 $wp_customize->render_control_templates(); 189 191 190 192 /** -
src/wp-admin/js/customize-controls.js
149 149 Container = api.Class.extend({ 150 150 defaultActiveArguments: { duration: 'fast', completeCallback: $.noop }, 151 151 defaultExpandedArguments: { duration: 'fast', completeCallback: $.noop }, 152 containerType: 'container', 152 153 153 154 /** 154 155 * @since 4.1.0 … … 161 162 container.id = id; 162 163 container.params = {}; 163 164 $.extend( container, options || {} ); 165 container.templateSelector = 'customize-' + container.containerType + '-' + container.params.type; 164 166 container.container = $( container.params.content ); 167 if ( 0 === container.container.length ) { 168 container.container = $( container.getContainer() ); 169 } 165 170 166 171 container.deferred = { 167 172 embedded: new $.Deferred() … … 348 353 * Bring the container into view and then expand this and bring it into view 349 354 * @param {Object} [params] 350 355 */ 351 focus: focus 356 focus: focus, 357 358 /** 359 * Return the container html, generated from its JS template, if it exists. 360 * 361 * @since 4.2.0 362 */ 363 getContainer: function () { 364 var template, 365 container = this; 366 367 if ( 0 !== $( '#tmpl-' + container.templateSelector ).length ) { 368 template = wp.template( container.templateSelector ); 369 if ( template && container.container ) { 370 return template( container.params ); 371 } 372 } 373 374 return '<li></li>'; 375 } 352 376 }); 353 377 354 378 /** … … 358 382 * @augments wp.customize.Class 359 383 */ 360 384 api.Section = Container.extend({ 385 containerType: 'section', 361 386 362 387 /** 363 388 * @since 4.1.0 … … 527 552 * @augments wp.customize.Class 528 553 */ 529 554 api.Panel = Container.extend({ 555 containerType: 'panel', 556 530 557 /** 531 558 * @since 4.1.0 532 559 * … … 553 580 554 581 if ( ! panel.container.parent().is( parentContainer ) ) { 555 582 parentContainer.append( panel.container ); 583 panel.renderContent(); 556 584 } 557 585 panel.deferred.embedded.resolve(); 558 586 }, … … 575 603 } 576 604 }); 577 605 578 meta = panel.container.find( '.panel-meta:first' ); 579 580 meta.find( '> .accordion-section-title' ).on( 'click keydown', function( event ) { 606 panel.container.on( 'click keydown', '.panel-meta > .accordion-section-title', function( event ) { 581 607 if ( api.utils.isKeydownButNotEnterEvent( event ) ) { 582 608 return; 583 609 } 584 610 event.preventDefault(); // Keep this AFTER the key filter above 585 611 612 meta = panel.container.find( '.panel-meta' ); 586 613 if ( meta.hasClass( 'cannot-expand' ) ) { 587 614 return; 588 615 } … … 704 731 panelTitle.focus(); 705 732 container.scrollTop( 0 ); 706 733 } 734 }, 735 736 /** 737 * Render the panel from its JS template, if it exists. 738 * 739 * The panel's container must already exist in the DOM. 740 * 741 * @since 4.2.0 742 */ 743 renderContent: function () { 744 var template, 745 panel = this; 746 747 // Add the content to the container. 748 if ( 0 !== $( '#tmpl-' + panel.templateSelector + '-content' ).length ) { 749 template = wp.template( panel.templateSelector + '-content' ); 750 if ( template && panel.container ) { 751 panel.container.find( '.accordion-sub-container' ).html( template( panel.params ) ); 752 } 753 } 707 754 } 708 755 }); 709 756 -
src/wp-includes/class-wp-customize-control.php
259 259 * @return array Array of parameters passed to the JavaScript. 260 260 */ 261 261 public function json() { 262 if ( ! $this->check_capabilities() ) { 263 return; 264 } 265 262 266 $this->to_json(); 263 267 return $this->json; 264 268 } … … 515 519 * @since 4.1.0 516 520 */ 517 521 final public function print_template() { 518 519 520 521 522 522 ?> 523 <script type="text/html" id="tmpl-customize-control-<?php echo $this->type; ?>-content"> 524 <?php $this->content_template(); ?> 525 </script> 526 <?php 523 527 } 524 528 525 529 /** -
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.57 * Panel types that may be rendered from JS templates. 58 58 * 59 * @since 4.2.0 60 * @access protected 61 * @var array 62 */ 63 protected $registered_panel_types = array(); 64 65 /** 66 * Section types that may be rendered from JS templates. 67 * 68 * @since 4.2.0 69 * @access protected 70 * @var array 71 */ 72 protected $registered_section_types = array(); 73 74 /** 75 * Control types that may be rendered from JS templates. 76 * 59 77 * @since 4.1.0 60 78 * @access protected 61 79 * @var array … … 774 792 } 775 793 776 794 /** 795 * Register a customize panel type. 796 * 797 * Registered types are eligible to be rendered via JS and created dynamically. 798 * 799 * @since 4.2.0 800 * @access public 801 * 802 * @param string $panel Name of a custom panel which is a subclass of 803 * {@see WP_Customize_Panel}. 804 */ 805 public function register_panel_type( $panel ) { 806 $this->registered_panel_types[] = $panel; 807 } 808 809 /** 810 * Render JS templates for all registered panel types. 811 * 812 * @since 4.2.0 813 * @access public 814 */ 815 public function render_panel_templates() { 816 foreach ( $this->registered_panel_types as $panel_type ) { 817 $panel = new $panel_type( $this, 'temp', array() ); 818 $panel->print_template(); 819 } 820 } 821 822 /** 777 823 * Add a customize section. 778 824 * 779 825 * @since 3.4.0 … … 815 861 } 816 862 817 863 /** 864 * Register a customize section type. 865 * 866 * Registered types are eligible to be rendered via JS and created dynamically. 867 * 868 * @since 4.2.0 869 * @access public 870 * 871 * @param string $section Name of a custom section which is a subclass of 872 * {@see WP_Customize_Section}. 873 */ 874 public function register_section_type( $section ) { 875 $this->registered_section_types[] = $section; 876 } 877 878 /** 879 * Render JS templates for all registered section types. 880 * 881 * @since 4.2.0 882 * @access public 883 */ 884 public function render_section_templates() { 885 foreach ( $this->registered_section_types as $section_type ) { 886 $section = new $section_type( $this, 'temp', array() ); 887 $section->print_template(); 888 } 889 } 890 891 /** 818 892 * Add a customize control. 819 893 * 820 894 * @since 3.4.0 … … 985 1059 */ 986 1060 public function register_controls() { 987 1061 988 /* Control Types (custom control classes) */ 1062 /* Panel, Section, and Control Types */ 1063 $this->register_panel_type( 'WP_Customize_Panel' ); 1064 $this->register_section_type( 'WP_Customize_Section' ); 1065 $this->register_section_type( 'WP_Customize_Sidebar_Section' ); 989 1066 $this->register_control_type( 'WP_Customize_Color_Control' ); 990 1067 $this->register_control_type( 'WP_Customize_Upload_Control' ); 991 1068 $this->register_control_type( 'WP_Customize_Image_Control' ); -
src/wp-includes/class-wp-customize-panel.php
204 204 * @return array The array to be exported to the client as JSON. 205 205 */ 206 206 public function json() { 207 $array = wp_array_slice_assoc( (array) $this, array( 'title', 'description', 'priority', 'type' ) ); 207 if ( ! $this->check_capabilities() ) { 208 return; 209 } 210 211 $array = wp_array_slice_assoc( (array) $this, array( 'id', 'title', 'description', 'priority', 'type' ) ); 208 212 $array['content'] = $this->get_content(); 209 213 $array['active'] = $this->active(); 210 214 $array['instanceNumber'] = $this->instance_number; … … 279 283 } 280 284 281 285 /** 282 * Render the panel container, and then its contents .286 * Render the panel container, and then its contents (via `this->render_content()`) in a subclass. 283 287 * 288 * Panel containers are now rendered in JS by default, see {@see WP_Customize_Panel::print_template()}. 289 * 284 290 * @since 4.0.0 285 291 * @access protected 286 292 */ 287 protected function render() { 288 $classes = 'accordion-section control-section control-panel control-panel-' . $this->type; 293 protected function render() {} 294 295 /** 296 * Render the panel UI in a subclass. 297 * 298 * Panel contents are now rendered in JS by default, see {@see WP_Customize_Panel::print_template()}. 299 * 300 * @since 4.1.0 301 * @access protected 302 */ 303 protected function render_content() {} 304 305 /** 306 * Render the panel's JS templates. 307 * 308 * This function is only run for panel types that have been registered with 309 * {@see WP_Customize_Manager::register_panel_type()}. 310 * 311 * @since 4.2.0 312 */ 313 public function print_template() { 289 314 ?> 290 <li id="accordion-panel-<?php echo esc_attr( $this->id ); ?>" class="<?php echo esc_attr( $classes ); ?>"> 315 <script type="text/html" id="tmpl-customize-panel-<?php echo $this->type; ?>-content"> 316 <?php $this->content_template(); ?> 317 </script> 318 <script type="text/html" id="tmpl-customize-panel-<?php echo $this->type; ?>"> 319 <?php $this->render_template(); ?> 320 </script> 321 <?php 322 } 323 324 /** 325 * An Underscore (JS) template for rendering this panel's container. 326 * 327 * Class variables for this panel class are available in the `data` JS object; 328 * export custom variables by overriding {@see WP_Customize_Panel::json()}. 329 * 330 * @see WP_Customize_Panel::print_template() 331 * 332 * @since 4.2.0 333 */ 334 protected function render_template() { 335 ?> 336 <# var classes = 'accordion-section control-section control-panel control-panel-' + data.type; #> 337 <li id="accordion-panel-{{ data.id }}" class="{{ classes }}"> 291 338 <h3 class="accordion-section-title" tabindex="0"> 292 <?php echo esc_html( $this->title ); ?>339 {{ data.title }} 293 340 <span class="screen-reader-text"><?php _e( 'Press return or enter to open this panel' ); ?></span> 294 341 </h3> 295 <ul class="accordion-sub-container control-panel-content"> 296 <?php $this->render_content(); ?> 297 </ul> 342 <ul class="accordion-sub-container control-panel-content"></ul> 298 343 </li> 299 344 <?php 300 345 } 301 346 302 347 /** 303 * Render the sections that have been added to the panel.348 * An Underscore (JS) template for this panel's content (but not its container). 304 349 * 305 * @since 4.1.0 306 * @access protected 350 * Class variables for this panel class are available in the `data` JS object; 351 * export custom variables by overriding {@see WP_Customize_Panel::json()}. 352 * 353 * @see WP_Customize_Panel::print_template() 354 * 355 * @since 4.2.0 307 356 */ 308 protected function render_content() {357 protected function content_template() { 309 358 ?> 310 <li class="panel-meta accordion-section control-section< ?php if ( empty( $this->description ) ) { echo ' cannot-expand'; } ?>">359 <li class="panel-meta accordion-section control-section<# if ( ! data.description ) { #> cannot-expand<# } #>"> 311 360 <div class="accordion-section-title" tabindex="0"> 312 361 <span class="preview-notice"><?php 313 362 /* translators: %s is the site/panel title in the Customizer */ 314 echo sprintf( __( 'You are customizing %s' ), '<strong class="panel-title"> ' . esc_html( $this->title ) . '</strong>' );363 echo sprintf( __( 'You are customizing %s' ), '<strong class="panel-title">{{ data.title }}</strong>' ); 315 364 ?></span> 316 365 </div> 317 < ?php if ( ! empty( $this->description ) ) : ?>366 <# if ( data.description ) { #> 318 367 <div class="accordion-section-content description"> 319 <?php echo $this->description; ?>368 {{{ data.description }}} 320 369 </div> 321 < ?php endif; ?>370 <# } #> 322 371 </li> 323 372 <?php 324 373 } -
src/wp-includes/class-wp-customize-section.php
213 213 * @return array The array to be exported to the client as JSON. 214 214 */ 215 215 public function json() { 216 $array = wp_array_slice_assoc( (array) $this, array( 'title', 'description', 'priority', 'panel', 'type' ) ); 216 if ( ! $this->check_capabilities() ) { 217 return; 218 } 219 220 $array = wp_array_slice_assoc( (array) $this, array( 'id', 'title', 'description', 'priority', 'panel', 'type' ) ); 217 221 $array['content'] = $this->get_content(); 218 222 $array['active'] = $this->active(); 219 223 $array['instanceNumber'] = $this->instance_number; … … 241 245 } 242 246 243 247 /** 244 * Get the section's content templatefor insertion into the Customizer pane.248 * Get the section's content for insertion into the Customizer pane. 245 249 * 246 250 * @since 4.1.0 247 251 * … … 287 291 } 288 292 289 293 /** 290 * Render the section , and the controls that have been added to it.294 * Render the section UI in a subclass. 291 295 * 296 * Sections are now rendered in JS by default, see {@see WP_Customize_Section::print_template()}. 297 * 292 298 * @since 3.4.0 293 299 */ 294 protected function render() { 295 $classes = 'accordion-section control-section control-section-' . $this->type; 300 protected function render() {} 301 302 /** 303 * Render the section's JS template. 304 * 305 * This function is only run for section types that have been registered with 306 * {@see WP_Customize_Manager::register_section_type()}. 307 * 308 * @since 4.2.0 309 */ 310 public function print_template() { 311 ?> 312 <script type="text/html" id="tmpl-customize-section-<?php echo $this->type; ?>"> 313 <?php $this->render_template(); ?> 314 </script> 315 <?php 316 } 317 318 /** 319 * An Underscore (JS) template for rendering this section. 320 * 321 * Class variables for this section class are available in the `data` JS object; 322 * export custom variables by overriding {@see WP_Customize_Section::json()}. 323 * 324 * @see WP_Customize_Section::print_template() 325 * 326 * @since 4.2.0 327 */ 328 protected function render_template() { 296 329 ?> 297 <li id="accordion-section- <?php echo esc_attr( $this->id ); ?>" class="<?php echo esc_attr( $classes ); ?>">330 <li id="accordion-section-{{ data.id }}" class="accordion-section control-section control-section-{{ data.type }}"> 298 331 <h3 class="accordion-section-title" tabindex="0"> 299 <?php echo esc_html( $this->title ); ?>332 {{ data.title }} 300 333 <span class="screen-reader-text"><?php _e( 'Press return or enter to expand' ); ?></span> 301 334 </h3> 302 335 <ul class="accordion-section-content"> 303 < ?php if ( ! empty( $this->description ) ) : ?>336 <# if ( data.description ) { #> 304 337 <li class="customize-section-description-container"> 305 <p class="description customize-section-description"> <?php echo $this->description; ?></p>338 <p class="description customize-section-description">{{{ data.description }}}</p> 306 339 </li> 307 < ?php endif; ?>340 <# } #> 308 341 </ul> 309 342 </li> 310 343 <?php