Remove 'visibility' parameter from WP_Customize_Control. Handle control visibility in JS instead. see #19910.

* Have the header text color picker display only when header_textcolor != 'blank'



git-svn-id: http://svn.automattic.com/wordpress/trunk@20506 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
koopersmith 2012-04-18 17:13:31 +00:00
parent 1085d4ecb7
commit 1d73aae054
3 changed files with 31 additions and 52 deletions

View File

@ -22,8 +22,6 @@ class WP_Customize_Control {
public $json = array(); public $json = array();
public $visibility;
public $type = 'text'; public $type = 'text';
@ -102,21 +100,6 @@ class WP_Customize_Control {
} }
$this->json['type'] = $this->type; $this->json['type'] = $this->type;
if ( $this->visibility ) {
if ( is_string( $this->visibility ) ) {
$this->json['visibility'] = array(
'id' => $this->visibility,
'value' => true,
);
} else {
$this->json['visibility'] = array(
'id' => $this->visibility[0],
'value' => $this->visibility[1],
);
}
}
} }
/** /**
@ -163,22 +146,7 @@ class WP_Customize_Control {
$id = 'customize-control-' . str_replace( '[', '-', str_replace( ']', '', $this->id ) ); $id = 'customize-control-' . str_replace( '[', '-', str_replace( ']', '', $this->id ) );
$class = 'customize-control customize-control-' . $this->type; $class = 'customize-control customize-control-' . $this->type;
$style = ''; ?><li id="<?php echo esc_attr( $id ); ?>" class="<?php echo esc_attr( $class ); ?>">
if ( $this->visibility ) {
if ( is_string( $this->visibility ) ) {
$visibility_id = $this->visibility;
$visibility_value = true;
} else {
$visibility_id = $this->visibility[0];
$visibility_value = $this->visibility[1];
}
$visibility_setting = $this->manager->get_setting( $visibility_id );
if ( $visibility_setting && $visibility_value != $visibility_setting->value() )
$style = 'style="display:none;"';
}
?><li id="<?php echo esc_attr( $id ); ?>" class="<?php echo esc_attr( $class ); ?>" <?php echo $style; ?>>
<?php $this->render_content(); ?> <?php $this->render_content(); ?>
</li><?php </li><?php
} }

View File

@ -591,7 +591,6 @@ final class WP_Customize {
$this->add_control( 'background_repeat', array( $this->add_control( 'background_repeat', array(
'label' => __( 'Background Repeat' ), 'label' => __( 'Background Repeat' ),
'section' => 'background', 'section' => 'background',
'visibility' => 'background_image',
'type' => 'radio', 'type' => 'radio',
'choices' => array( 'choices' => array(
'no-repeat' => __('No Repeat'), 'no-repeat' => __('No Repeat'),
@ -609,7 +608,6 @@ final class WP_Customize {
$this->add_control( 'background_position_x', array( $this->add_control( 'background_position_x', array(
'label' => __( 'Background Position' ), 'label' => __( 'Background Position' ),
'section' => 'background', 'section' => 'background',
'visibility' => 'background_image',
'type' => 'radio', 'type' => 'radio',
'choices' => array( 'choices' => array(
'left' => __('Left'), 'left' => __('Left'),
@ -626,7 +624,6 @@ final class WP_Customize {
$this->add_control( 'background_attachment', array( $this->add_control( 'background_attachment', array(
'label' => __( 'Background Attachment' ), 'label' => __( 'Background Attachment' ),
'section' => 'background', 'section' => 'background',
'visibility' => 'background_image',
'type' => 'radio', 'type' => 'radio',
'choices' => array( 'choices' => array(
'fixed' => __('Fixed'), 'fixed' => __('Fixed'),
@ -708,7 +705,6 @@ final class WP_Customize {
'label' => __( 'Front page' ), 'label' => __( 'Front page' ),
'section' => 'static_front_page', 'section' => 'static_front_page',
'type' => 'dropdown-pages', 'type' => 'dropdown-pages',
'visibility' => array( 'show_on_front', 'page' ),
) ); ) );
$this->add_setting( 'page_for_posts', array( $this->add_setting( 'page_for_posts', array(
@ -721,7 +717,6 @@ final class WP_Customize {
'label' => __( 'Posts page' ), 'label' => __( 'Posts page' ),
'section' => 'static_front_page', 'section' => 'static_front_page',
'type' => 'dropdown-pages', 'type' => 'dropdown-pages',
'visibility' => array( 'show_on_front', 'page' ),
) ); ) );
/* Site Title & Tagline */ /* Site Title & Tagline */

View File

@ -377,20 +377,6 @@
params: data, params: data,
previewer: previewer previewer: previewer
} ) ); } ) );
if ( data.visibility ) {
api( data.visibility.id, function( other ) {
if ( 'boolean' === typeof data.visibility.value ) {
other.bind( function( to ) {
control.container.toggle( !! to == data.visibility.value );
});
} else {
other.bind( function( to ) {
control.container.toggle( to == data.visibility.value );
});
}
});
}
}); });
// Temporary accordion code. // Temporary accordion code.
@ -415,6 +401,36 @@
setting.method = 'postMessage'; setting.method = 'postMessage';
}); });
// Control visibility for default controls
$.each({
'background_image': {
controls: [ 'background_repeat', 'background_position_x', 'background_attachment' ],
callback: function( to ) { return !! to }
},
'show_on_front': {
controls: [ 'page_on_front', 'page_for_posts' ],
callback: function( to ) { return 'page' === to }
},
'header_textcolor': {
controls: [ 'header_textcolor' ],
callback: function( to ) { return 'blank' !== to }
}
}, function( settingId, o ) {
api( settingId, function( setting ) {
$.each( o.controls, function( i, controlId ) {
api.control( controlId, function( control ) {
var visibility = function( to ) {
control.container.toggle( o.callback( to ) );
};
visibility( setting.get() );
setting.bind( visibility );
});
});
});
});
// Juggle the two controls that use header_textcolor
api.control( 'display_header_text', function( control ) { api.control( 'display_header_text', function( control ) {
var last = ''; var last = '';