Changeset 29051
- Timestamp:
- 07/09/2014 11:57:29 PM (10 years ago)
- Location:
- trunk/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/js/customize-controls.js
r29048 r29051 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 ) { … … 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() {}, 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 }, 85 106 86 107 dropdownInit: function() { … … 563 584 564 585 this.bind( 'ready', this._ready ); 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 } ); 565 606 566 607 this.request = $.ajax( this.previewUrl(), { -
trunk/src/wp-admin/js/customize-widgets.js
r29048 r29051 752 752 } ); 753 753 754 // Update widget control to indicate whether it is currently rendered755 api.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 ) { … … 767 760 } ); 768 761 } 762 }, 763 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 ); 769 773 }, 770 774 … … 1419 1423 1420 1424 // Update the model with whether or not the sidebar is rendered 1421 api.previewer.bind( 'rendered-sidebars', function( renderedSidebars ) { 1422 var isRendered = !! renderedSidebars[self.params.sidebar_id]; 1423 1424 registeredSidebar.set( 'is_rendered', isRendered ); 1425 } ); 1426 1427 // Show the sidebar section when it becomes visible 1428 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 overflow 1435 } ); 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 public 1441 $section.find( '.accordion-section-title' ).trigger( 'click' ); 1442 } 1443 1444 $section.stop().slideUp(); 1445 } 1446 } ); 1425 self.active.bind( function ( active ) { 1426 registeredSidebar.set( 'is_rendered', active ); 1427 } ); 1428 }, 1429 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 1440 sectionSelector = '#accordion-section-sidebar-widgets-' + this.params.sidebar_id; 1441 $section = $( sectionSelector ); 1442 1443 if ( active ) { 1444 $section.stop().slideDown( function() { 1445 $( this ).css( 'height', 'auto' ); // so that the .accordion-section-content won't overflow 1446 } ); 1447 1448 } else { 1449 // Make sure that hidden sections get closed first 1450 if ( $section.hasClass( 'open' ) ) { 1451 // it would be nice if accordionSwitch() in accordion.js was public 1452 $section.find( '.accordion-section-title' ).trigger( 'click' ); 1453 } 1454 1455 $section.stop().slideUp(); 1456 } 1447 1457 }, 1448 1458 -
trunk/src/wp-includes/class-wp-customize-control.php
r28980 r29051 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 /** … … 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(); … … 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 /** … … 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 … … 160 214 161 215 $this->json['type'] = $this->type; 216 $this->json['active'] = $this->active(); 162 217 } 163 218 … … 257 312 } 258 313 259 314 /** 260 315 * Render the custom attributes for the control's input element. 261 316 * … … 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 … … 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 -
trunk/src/wp-includes/class-wp-customize-manager.php
r28970 r29051 476 476 $settings = array( 477 477 'values' => array(), 478 'channel' => esc_js( $_POST['customize_messenger_channel'] ), 478 'channel' => wp_unslash( $_POST['customize_messenger_channel'] ), 479 'activeControls' => array(), 479 480 ); 480 481 … … 488 489 foreach ( $this->settings as $id => $setting ) { 489 490 $settings['values'][ $id ] = $setting->js_value(); 491 } 492 foreach ( $this->controls as $id => $control ) { 493 $settings['activeControls'][ $id ] = $control->active(); 490 494 } 491 495 -
trunk/src/wp-includes/class-wp-customize-widgets.php
r29028 r29051 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 -
trunk/src/wp-includes/js/customize-preview-widgets.js
r28100 r29051 23 23 this.buildWidgetSelectors(); 24 24 this.highlightControls(); 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 25 31 26 this.preview.bind( 'highlight-widget', self.highlightWidget ); -
trunk/src/wp-includes/js/customize-preview.js
r27704 r29051 96 96 }); 97 97 98 preview.send( 'ready' ); 98 preview.send( 'ready', { 99 activeControls: api.settings.activeControls 100 } ); 99 101 100 102 /* Custom Backgrounds */
Note: See TracChangeset
for help on using the changeset viewer.