Ticket #30737: 30737.diff
File 30737.diff, 14.1 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
162 162 container.params = {}; 163 163 $.extend( container, options || {} ); 164 164 container.container = $( container.params.content ); 165 if ( 0 === container.container.length ) { 166 container.container = $( container.getContainer() ); 167 } 165 168 166 169 container.deferred = { 167 170 embedded: new $.Deferred() … … 348 351 * Bring the container into view and then expand this and bring it into view 349 352 * @param {Object} [params] 350 353 */ 351 focus: focus 354 focus: focus, 355 356 /** 357 * To override in a subclass, return the container's container element generated from the template. 358 * @abstract 359 */ 360 getContainer: function () { 361 throw new Error( 'Must override with subclass.' ); 362 } 352 363 }); 353 364 354 365 /** … … 517 528 section.container.removeClass( 'open' ); 518 529 content.slideUp( args.duration, args.completeCallback ); 519 530 } 531 }, 532 533 /** 534 * Return the section contents, generated from its JS template, if it exists. 535 * 536 * @since 4.2.0 537 */ 538 getContainer: function () { 539 var template, 540 section = this; 541 542 if ( 0 !== $( '#tmpl-customize-section-' + section.params.type ).length ) { 543 template = wp.template( 'customize-section-' + section.params.type ); 544 if ( template && section.container ) { 545 return template( section.params ); 546 } 547 } 520 548 } 521 549 }); 522 550 … … 553 581 554 582 if ( ! panel.container.parent().is( parentContainer ) ) { 555 583 parentContainer.append( panel.container ); 584 panel.renderContent(); 556 585 } 557 586 panel.deferred.embedded.resolve(); 558 587 }, … … 575 604 } 576 605 }); 577 606 578 meta = panel.container.find( '.panel-meta:first' ); 579 580 meta.find( '> .accordion-section-title' ).on( 'click keydown', function( event ) { 607 panel.container.on( 'click keydown', '.panel-meta > .accordion-section-title', function( event ) { 581 608 if ( api.utils.isKeydownButNotEnterEvent( event ) ) { 582 609 return; 583 610 } 584 611 event.preventDefault(); // Keep this AFTER the key filter above 585 612 613 meta = panel.container.find( '.panel-meta' ); 586 614 if ( meta.hasClass( 'cannot-expand' ) ) { 587 615 return; 588 616 } … … 704 732 panelTitle.focus(); 705 733 container.scrollTop( 0 ); 706 734 } 735 }, 736 737 /** 738 * Return the panel container, generated from its JS template, if it exists. 739 * 740 * @since 4.2.0 741 */ 742 getContainer: function () { 743 /* var template, // @todo dynamic panel containers 744 section = this; 745 746 if ( 0 !== $( '#tmpl-customize-panel-' + section.params.type ).length ) { 747 template = wp.template( 'customize-panel-' + section.params.type ); 748 if ( template && section.container ) { 749 return template( section.params ); 750 } 751 } 752 */ }, 753 754 /** 755 * Render the panel from its JS template, if it exists. 756 * 757 * The panel's container must already exist in the DOM. 758 * 759 * @since 4.2.0 760 */ 761 renderContent: function () { 762 var template, 763 panel = this; 764 765 // Add the content to the container. 766 if ( 0 !== $( '#tmpl-customize-panel-' + panel.params.type + '-content' ).length ) { 767 template = wp.template( 'customize-panel-' + panel.params.type + '-content' ); 768 if ( template && panel.container ) { 769 panel.container.find( '.accordion-sub-container' ).append( template( panel.params ) ); 770 } 771 } 707 772 } 708 773 }); 709 774 -
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 … … 759 777 } 760 778 761 779 /** 780 * Register a customize panel type. 781 * 782 * Registered types are eligible to be rendered via JS and created dynamically. 783 * 784 * @since 4.2.0 785 * @access public 786 * 787 * @param string $panel Name of a custom panel which is a subclass of 788 * {@see WP_Customize_Panel}. 789 */ 790 public function register_panel_type( $panel ) { 791 $this->registered_panel_types[] = $panel; 792 } 793 794 /** 795 * Render JS templates for all registered panel types. 796 * 797 * @since 4.2.0 798 * @access public 799 */ 800 public function render_panel_templates() { 801 foreach ( $this->registered_panel_types as $panel_type ) { 802 $panel = new $panel_type( $this, 'temp', array() ); 803 $panel->print_template(); 804 } 805 } 806 807 /** 762 808 * Add a customize section. 763 809 * 764 810 * @since 3.4.0 … … 800 846 } 801 847 802 848 /** 849 * Register a customize section type. 850 * 851 * Registered types are eligible to be rendered via JS and created dynamically. 852 * 853 * @since 4.2.0 854 * @access public 855 * 856 * @param string $section Name of a custom section which is a subclass of 857 * {@see WP_Customize_Section}. 858 */ 859 public function register_section_type( $section ) { 860 $this->registered_section_types[] = $section; 861 } 862 863 /** 864 * Render JS templates for all registered section types. 865 * 866 * @since 4.2.0 867 * @access public 868 */ 869 public function render_section_templates() { 870 foreach ( $this->registered_section_types as $section_type ) { 871 $section = new $section_type( $this, 'temp', array() ); 872 $section->print_template(); 873 } 874 } 875 876 /** 803 877 * Add a customize control. 804 878 * 805 879 * @since 3.4.0 … … 970 1044 */ 971 1045 public function register_controls() { 972 1046 973 /* Control Types (custom control classes) */ 1047 /* Panel, Section, and Control Types */ 1048 $this->register_panel_type( 'WP_Customize_Panel' ); 1049 $this->register_section_type( 'WP_Customize_Section' ); 1050 $this->register_section_type( 'WP_Customize_Sidebar_Section' ); 974 1051 $this->register_control_type( 'WP_Customize_Color_Control' ); 975 1052 $this->register_control_type( 'WP_Customize_Upload_Control' ); 976 1053 $this->register_control_type( 'WP_Customize_Image_Control' ); -
src/wp-includes/class-wp-customize-panel.php
206 206 * @return array The array to be exported to the client as JSON. 207 207 */ 208 208 public function json() { 209 $array = wp_array_slice_assoc( (array) $this, array( 'title', 'description', 'priority', 'type' ) ); 209 if ( ! $this->check_capabilities() ) { 210 return; 211 } 212 213 $array = wp_array_slice_assoc( (array) $this, array( 'id', 'title', 'description', 'priority', 'type' ) ); 210 214 $array['content'] = $this->get_content(); 211 215 $array['active'] = $this->active(); 212 216 $array['instanceNumber'] = $this->instance_number; … … 302 306 } 303 307 304 308 /** 305 * Render the sections that have been added to the panel.309 * Render the panel UI in a subclass. 306 310 * 311 * Panel contents are now rendered in JS by default, see {@see WP_Customize_Panel::print_template()}. 312 * 307 313 * @since 4.1.0 308 314 * @access protected 309 315 */ 310 protected function render_content() { 316 protected function render_content() {} 317 318 /** 319 * Render the panel's JS template. 320 * 321 * This function is only run for panel types that have been registered with 322 * {@see WP_Customize_Manager::register_panel_type()}. 323 * 324 * In the future, this will also print the template for the panel's container 325 * and be override-able. 326 * 327 * @since 4.2.0 328 */ 329 final public function print_template() { 330 ?> 331 <script type="text/html" id="tmpl-customize-panel-<?php echo $this->type; ?>-content"> 332 <?php $this->content_template(); ?> 333 </script> 334 <?php 335 } 336 337 /** 338 * An Underscore (JS) template for this panel's content (but not its container). 339 * 340 * Class variables for this panel class are available in the `data` JS object; 341 * export custom variables by overriding {@see WP_Customize_Panel::json()}. 342 * 343 * @see WP_Customize_Panel::print_template() 344 * 345 * @since 4.2.0 346 */ 347 protected function content_template() { 311 348 ?> 312 <li class="panel-meta accordion-section control-section< ?php if ( empty( $this->description ) ) { echo ' cannot-expand'; } ?>">349 <li class="panel-meta accordion-section control-section<# if ( ! data.description ) { #> cannot-expand<# } #>"> 313 350 <div class="accordion-section-title" tabindex="0"> 314 351 <span class="preview-notice"><?php 315 352 /* translators: %s is the site/panel title in the Customizer */ 316 echo sprintf( __( 'You are customizing %s' ), '<strong class="panel-title"> ' . esc_html( $this->title ) . '</strong>' );353 echo sprintf( __( 'You are customizing %s' ), '<strong class="panel-title">{{ data.title }}</strong>' ); 317 354 ?></span> 318 355 </div> 319 < ?php if ( ! empty( $this->description ) ) : ?>356 <# if ( data.description ) { #> 320 357 <div class="accordion-section-content description"> 321 <?php echo $this->description; ?>358 {{{ data.description }}} 322 359 </div> 323 < ?php endif; ?>360 <# } #> 324 361 </li> 325 362 <?php 326 363 } -
src/wp-includes/class-wp-customize-section.php
215 215 * @return array The array to be exported to the client as JSON. 216 216 */ 217 217 public function json() { 218 $array = wp_array_slice_assoc( (array) $this, array( 'title', 'description', 'priority', 'panel', 'type' ) ); 218 if ( ! $this->check_capabilities() ) { 219 return; 220 } 221 222 $array = wp_array_slice_assoc( (array) $this, array( 'id', 'title', 'description', 'priority', 'panel', 'type' ) ); 219 223 $array['content'] = $this->get_content(); 220 224 $array['active'] = $this->active(); 221 225 $array['instanceNumber'] = $this->instance_number; … … 243 247 } 244 248 245 249 /** 246 * Get the section's content templatefor insertion into the Customizer pane.250 * Get the section's content for insertion into the Customizer pane. 247 251 * 248 252 * @since 4.1.0 249 253 * … … 289 293 } 290 294 291 295 /** 292 * Render the section , and the controls that have been added to it.296 * Render the section UI in a subclass. 293 297 * 298 * Sections are now rendered in JS by default, see {@see WP_Customize_Section::print_template()}. 299 * 294 300 * @since 3.4.0 295 301 */ 296 protected function render() { 297 $classes = 'accordion-section control-section control-section-' . $this->type; 302 protected function render() {} 303 304 /** 305 * Render the section's JS template. 306 * 307 * This function is only run for section types that have been registered with 308 * {@see WP_Customize_Manager::register_section_type()}. 309 * 310 * In the future, this will also print the template for the control's container 311 * element and be override-able. 312 * 313 * @since 4.2.0 314 */ 315 public function print_template() { 316 ?> 317 <script type="text/html" id="tmpl-customize-section-<?php echo $this->type; ?>"> 318 <?php $this->render_template(); ?> 319 </script> 320 <?php 321 } 322 323 /** 324 * An Underscore (JS) template for rendering this section. 325 * 326 * Class variables for this section class are available in the `data` JS object; 327 * export custom variables by overriding {@see WP_Customize_Section::json()}. 328 * 329 * @see WP_Customize_Section::print_template() 330 * 331 * @since 4.2.0 332 */ 333 protected function render_template() { 298 334 ?> 299 <li id="accordion-section- <?php echo esc_attr( $this->id ); ?>" class="<?php echo esc_attr( $classes ); ?>">335 <li id="accordion-section-{{ data.id }}" class="accordion-section control-section control-section-{{ data.type }}"> 300 336 <h3 class="accordion-section-title" tabindex="0"> 301 <?php echo esc_html( $this->title ); ?>337 {{ data.title }} 302 338 <span class="screen-reader-text"><?php _e( 'Press return or enter to expand' ); ?></span> 303 339 </h3> 304 340 <ul class="accordion-section-content"> 305 < ?php if ( ! empty( $this->description ) ) : ?>341 <# if ( data.description ) { #> 306 342 <li class="customize-section-description-container"> 307 <p class="description customize-section-description"> <?php echo $this->description; ?></p>343 <p class="description customize-section-description">{{{ data.description }}}</p> 308 344 </li> 309 < ?php endif; ?>345 <# } #> 310 346 </ul> 311 347 </li> 312 348 <?php