Ticket #27993: 27993.diff
File 27993.diff, 11.8 KB (added by , 10 years ago) |
---|
-
src/wp-admin/js/customize-controls.js
diff --git src/wp-admin/js/customize-controls.js src/wp-admin/js/customize-controls.js index 4bfc252..bff2a92 100644
37 37 this.id = id; 38 38 this.selector = '#customize-control-' + id.replace( /\]/g, '' ).replace( /\[/g, '-' ); 39 39 this.container = $( this.selector ); 40 this.active = new api.Value( this.params.active ); 40 41 41 42 settings = $.map( this.params.settings, function( value ) { 42 43 return value; … … 79 80 element.set( setting() ); 80 81 }); 81 82 }); 83 84 control.active.bind( function ( active ) { 85 control.toggle( active ); 86 } ); 87 control.toggle( control.active() ); 82 88 }, 83 89 84 90 ready: function() {}, 85 91 92 /** 93 * Callback for change to the control's active state. 94 * 95 * Override function for custom behavior for the control being active/inactive. 96 * 97 * @param {Boolean} active 98 */ 99 toggle: function ( active ) { 100 if ( active ) { 101 this.container.slideDown(); 102 } else { 103 this.container.slideUp(); 104 } 105 }, 106 86 107 dropdownInit: function() { 87 108 var control = this, 88 109 statuses = this.container.find('.dropdown-status'), … … 563 584 564 585 this.bind( 'ready', this._ready ); 565 586 587 this.bind( 'ready', function ( data ) { 588 if ( ! data || ! data.activeControls ) { 589 return; 590 } 591 592 // Any controls not even registered on the previewed URL are not active either 593 api.control.each( function ( control ) { 594 if ( typeof data.activeControls[ control.id ] === 'undefined' ) { 595 data.activeControls[ control.id ] = false; 596 } 597 } ); 598 599 $.each( data.activeControls, function ( id, active ) { 600 var control = api.control( id ); 601 if ( control ) { 602 control.active( active ); 603 } 604 } ); 605 } ); 606 566 607 this.request = $.ajax( this.previewUrl(), { 567 608 type: 'POST', 568 609 data: this.query, -
src/wp-admin/js/customize-widgets.js
diff --git src/wp-admin/js/customize-widgets.js src/wp-admin/js/customize-widgets.js index 47505dd..00d1c2c 100644
751 751 } 752 752 } ); 753 753 754 // Update widget control to indicate whether it is currently rendered755 api.Widgets.Previewer.bind( 'rendered-widgets', function( renderedWidgets ) {756 var isRendered = !! renderedWidgets[self.params.widget_id];757 758 self.container.toggleClass( 'widget-rendered', isRendered );759 } );760 761 754 formSyncHandler = api.Widgets.formSyncHandlers[ this.params.widget_id_base ]; 762 755 if ( formSyncHandler ) { 763 756 $( document ).on( 'widget-synced', function( e, widget ) { … … 769 762 }, 770 763 771 764 /** 765 * Update widget control to indicate whether it is currently rendered. 766 * 767 * Overrides api.Control.toggle() 768 * 769 * @param {Boolean} active 770 */ 771 toggle: function ( active ) { 772 this.container.toggleClass( 'widget-rendered', active ); 773 }, 774 775 /** 772 776 * Set up event handlers for widget removal 773 777 */ 774 778 _setupRemoveUI: function() { … … 1418 1422 } ); 1419 1423 1420 1424 // Update the model with whether or not the sidebar is rendered 1421 api.Widgets.Previewer.bind( 'rendered-sidebars', function( renderedSidebars ) { 1422 var isRendered = !! renderedSidebars[self.params.sidebar_id]; 1423 1424 registeredSidebar.set( 'is_rendered', isRendered ); 1425 self.active.bind( function ( active ) { 1426 registeredSidebar.set( 'is_rendered', active ); 1425 1427 } ); 1428 }, 1426 1429 1427 // Show the sidebar section when it becomes visible1428 registeredSidebar.on( 'change:is_rendered', function( ) {1429 var sectionSelector = '#accordion-section-sidebar-widgets-' + this.get( 'id' ), $section;1430 1431 $section = $( sectionSelector );1432 if ( this.get( 'is_rendered' ) ) {1433 $section.stop().slideDown( function() {1434 $( this ).css( 'height', 'auto' ); // so that the .accordion-section-content won't overflow1435 } );1436 1437 } else {1438 // Make sure that hidden sections get closed first 1439 if ( $section.hasClass( 'open' )) {1440 // it would be nice if accordionSwitch() in accordion.js was public1441 $section.find( '.accordion-section-title' ).trigger( 'click' );1442 }1430 /** 1431 * Show the sidebar section when it becomes visible. 1432 * 1433 * Overrides api.Control.toggle() 1434 * 1435 * @param {Boolean} active 1436 */ 1437 toggle: function ( active ) { 1438 var $section, sectionSelector; 1439 sectionSelector = '#accordion-section-sidebar-widgets-' + this.params.sidebar_id; 1440 $section = $( sectionSelector ); 1441 1442 if ( active ) { 1443 $section.stop().slideDown( function() { 1444 $( this ).css( 'height', 'auto' ); // so that the .accordion-section-content won't overflow 1445 } ); 1443 1446 1444 $section.stop().slideUp(); 1447 } else { 1448 // Make sure that hidden sections get closed first 1449 if ( $section.hasClass( 'open' ) ) { 1450 // it would be nice if accordionSwitch() in accordion.js was public 1451 $section.find( '.accordion-section-title' ).trigger( 'click' ); 1445 1452 } 1446 } ); 1453 1454 $section.stop().slideUp(); 1455 } 1447 1456 }, 1448 1457 1449 1458 /** -
src/wp-includes/class-wp-customize-control.php
diff --git src/wp-includes/class-wp-customize-control.php src/wp-includes/class-wp-customize-control.php index e52f5cf..9817fac 100644
class WP_Customize_Control { 85 85 */ 86 86 public $type = 'text'; 87 87 88 /** 89 * Callback 90 * 91 * @since 4.0.0 92 * 93 * @access public 94 * @see WP_Customize_Control::active() 95 * @var callable Callback is called with one argument, the instance of 96 * WP_Customize_Control, and returns bool to indicate whether 97 * the control is active (such as it relates to the URL 98 * currently being previewed). 99 */ 100 public $active_callback = ''; 88 101 89 102 /** 90 103 * Constructor. … … class WP_Customize_Control { 102 115 public function __construct( $manager, $id, $args = array() ) { 103 116 $keys = array_keys( get_object_vars( $this ) ); 104 117 foreach ( $keys as $key ) { 105 if ( isset( $args[ $key ] ) ) 118 if ( isset( $args[ $key ] ) ) { 106 119 $this->$key = $args[ $key ]; 120 } 107 121 } 108 122 109 123 $this->manager = $manager; 110 124 $this->id = $id; 125 if ( empty( $this->active_callback ) ) { 126 $this->active_callback = array( $this, 'active_callback' ); 127 } 111 128 112 129 // Process settings. 113 if ( empty( $this->settings ) ) 130 if ( empty( $this->settings ) ) { 114 131 $this->settings = $id; 132 } 115 133 116 134 $settings = array(); 117 135 if ( is_array( $this->settings ) ) { … … class WP_Customize_Control { 132 150 */ 133 151 public function enqueue() {} 134 152 153 /** 154 * Check whether control is active to current customizer preview. 155 * 156 * @since 4.0.0 157 * 158 * @return bool 159 */ 160 public final function active() { 161 $control = $this; 162 $active = call_user_func( $this->active_callback, $this ); 163 164 /** 165 * Filter response of WP_Customize_Control::active(). 166 * 167 * @since 4.0.0 168 * 169 * @param bool $active 170 * @param WP_Customize_Control $control 171 */ 172 $active = apply_filters( 'customize_control_active', $active, $control ); 173 174 return $active; 175 } 176 177 /** 178 * Default callback used when invoking WP_Customize_Control::active(). 179 * 180 * Subclasses can override this with their specific logic, or they may 181 * provide an 'active_callback' argument to the constructor. 182 * 183 * @return bool 184 */ 185 public function active_callback() { 186 return true; 187 } 135 188 136 189 /** 137 190 * Fetch a setting's value. … … class WP_Customize_Control { 143 196 * @return mixed The requested setting's value, if the setting exists. 144 197 */ 145 198 public final function value( $setting_key = 'default' ) { 146 if ( isset( $this->settings[ $setting_key ] ) ) 199 if ( isset( $this->settings[ $setting_key ] ) ) { 147 200 return $this->settings[ $setting_key ]->value(); 201 } 148 202 } 149 203 150 204 /** … … class WP_Customize_Control { 159 213 } 160 214 161 215 $this->json['type'] = $this->type; 216 $this->json['active'] = $this->active(); 162 217 } 163 218 164 219 /** … … class WP_Customize_Control { 256 311 echo $this->get_link( $setting_key ); 257 312 } 258 313 259 314 /** 260 315 * Render the custom attributes for the control's input element. 261 316 * 262 317 * @since 4.0.0 … … class WP_Widget_Area_Customize_Control extends WP_Customize_Control { 995 1050 </span> 996 1051 <?php 997 1052 } 1053 1054 /** 1055 * @return bool 1056 */ 1057 function active_callback() { 1058 return $this->manager->widgets->is_sidebar_rendered( $this->sidebar_id ); 1059 } 998 1060 } 999 1061 1000 1062 /** … … class WP_Widget_Form_Customize_Control extends WP_Customize_Control { 1035 1097 $args = wp_list_widget_controls_dynamic_sidebar( array( 0 => $args, 1 => $widget['params'][0] ) ); 1036 1098 echo $this->manager->widgets->get_widget_control( $args ); 1037 1099 } 1100 1101 /** 1102 * @return bool 1103 */ 1104 function active_callback() { 1105 return $this->manager->widgets->is_widget_rendered( $this->widget_id ); 1106 } 1038 1107 } 1039 1108 -
src/wp-includes/class-wp-customize-manager.php
diff --git src/wp-includes/class-wp-customize-manager.php src/wp-includes/class-wp-customize-manager.php index 7ec89ee..14f0199 100644
final class WP_Customize_Manager { 462 462 public function customize_preview_settings() { 463 463 $settings = array( 464 464 'values' => array(), 465 'channel' => esc_js( $_POST['customize_messenger_channel'] ), 465 'channel' => wp_unslash( $_POST['customize_messenger_channel'] ), 466 'activeControls' => array(), 466 467 ); 467 468 468 469 if ( 2 == $this->nonce_tick ) { … … final class WP_Customize_Manager { 475 476 foreach ( $this->settings as $id => $setting ) { 476 477 $settings['values'][ $id ] = $setting->js_value(); 477 478 } 479 foreach ( $this->controls as $id => $control ) { 480 $settings['activeControls'][ $id ] = $control->active(); 481 } 478 482 479 483 ?> 480 484 <script type="text/javascript"> -
src/wp-includes/class-wp-customize-widgets.php
diff --git src/wp-includes/class-wp-customize-widgets.php src/wp-includes/class-wp-customize-widgets.php index 73e2a78..131fba2 100644
final class WP_Customize_Widgets { 1068 1068 * @param array $widget Rendered widget to tally. 1069 1069 */ 1070 1070 public function tally_rendered_widgets( $widget ) { 1071 $this->rendered_widgets[$widget['id']] = true; 1071 $this->rendered_widgets[ $widget['id'] ] = true; 1072 } 1073 1074 /** 1075 * Determine if a widget is rendered on the page. 1076 * 1077 * @since 4.0.0 1078 * @access public 1079 * 1080 * @param string $widget_id 1081 * @return bool 1082 */ 1083 public function is_widget_rendered( $widget_id ) { 1084 return in_array( $widget_id, $this->rendered_widgets ); 1085 } 1086 1087 /** 1088 * Determine if a sidebar is rendered on the page. 1089 * 1090 * @since 4.0.0 1091 * @access public 1092 * 1093 * @param string $sidebar_id 1094 * @return bool 1095 */ 1096 public function is_sidebar_rendered( $sidebar_id ) { 1097 return in_array( $sidebar_id, $this->rendered_sidebars ); 1072 1098 } 1073 1099 1074 1100 /** -
src/wp-includes/js/customize-preview-widgets.js
diff --git src/wp-includes/js/customize-preview-widgets.js src/wp-includes/js/customize-preview-widgets.js index cccc596..92267e8 100644
23 23 this.buildWidgetSelectors(); 24 24 this.highlightControls(); 25 25 26 this.preview.bind( 'active', function() {27 self.preview.send( 'rendered-sidebars', self.renderedSidebars ); // @todo Only send array of IDs28 self.preview.send( 'rendered-widgets', self.renderedWidgets ); // @todo Only send array of IDs29 } );30 31 26 this.preview.bind( 'highlight-widget', self.highlightWidget ); 32 27 }, 33 28 -
src/wp-includes/js/customize-preview.js
diff --git src/wp-includes/js/customize-preview.js src/wp-includes/js/customize-preview.js index 1d274f9..99643fb 100644
95 95 preview.send( 'nonce', api.settings.nonce ); 96 96 }); 97 97 98 preview.send( 'ready' ); 98 preview.send( 'ready', { 99 activeControls: api.settings.activeControls 100 } ); 99 101 100 102 /* Custom Backgrounds */ 101 103 bg = $.map(['color', 'image', 'position_x', 'repeat', 'attachment'], function( prop ) {