From f23be16bd24e18b82fa5955baacc49d107372d7f Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Thu, 5 Oct 2017 02:55:11 +0000 Subject: [PATCH] Customize: Add default control template for standard input types. Re-use default template instead of introducing custom one for the Discard Changes button. See #30738. git-svn-id: https://develop.svn.wordpress.org/trunk@41771 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/css/customize-controls.css | 4 +- src/wp-admin/js/customize-controls.js | 39 ++++- .../class-wp-customize-control.php | 5 +- .../class-wp-customize-manager.php | 141 +++++++++++++++++- src/wp-includes/script-loader.php | 1 + 5 files changed, 178 insertions(+), 12 deletions(-) diff --git a/src/wp-admin/css/customize-controls.css b/src/wp-admin/css/customize-controls.css index 767d092049..048befdcbb 100644 --- a/src/wp-admin/css/customize-controls.css +++ b/src/wp-admin/css/customize-controls.css @@ -152,12 +152,12 @@ body.trashing #publish-settings { #customize-control-trash_changeset { margin-top: 20px; } -#customize-control-trash_changeset button { +#customize-control-trash_changeset .button-link { position: relative; padding-left: 24px; display: inline-block; } -#customize-control-trash_changeset button:before { +#customize-control-trash_changeset .button-link:before { content: "\f182"; font: normal 22px dashicons; text-decoration: none; diff --git a/src/wp-admin/js/customize-controls.js b/src/wp-admin/js/customize-controls.js index 1656c4565d..19acd4def8 100644 --- a/src/wp-admin/js/customize-controls.js +++ b/src/wp-admin/js/customize-controls.js @@ -3141,7 +3141,7 @@ }, initialize: function( id, options ) { - var control = this, deferredSettingIds = [], settings, gatherSettings; + var control = this, deferredSettingIds = [], settings, gatherSettings, standardTypes; control.params = _.extend( {}, control.defaults ); @@ -3174,13 +3174,41 @@ control.id = id; control.selector = '#customize-control-' + id.replace( /\]/g, '' ).replace( /\[/g, '-' ); // Deprecated, likely dead code from time before #28709. - control.templateSelector = control.params.templateId || 'customize-control-' + control.params.type + '-content'; if ( control.params.content ) { control.container = $( control.params.content ); } else { control.container = $( control.selector ); // Likely dead, per above. See #28709. } + standardTypes = [ + 'button', + 'checkbox', + 'color', + 'date', + 'datetime-local', + 'email', + 'month', + 'number', + 'password', + 'radio', + 'range', + 'search', + 'select', + 'tel', + 'time', + 'text', + 'textarea', + 'week', + 'url' + ]; + if ( control.params.templateId ) { + control.templateSelector = control.params.templateId; + } else if ( _.contains( standardTypes, control.params.type ) && control.container.is( ':empty' ) ) { + control.templateSelector = 'customize-control-default-content'; + } else { + control.templateSelector = 'customize-control-' + control.params.type + '-content'; + } + control.deferred = { embedded: new $.Deferred() }; @@ -6446,11 +6474,14 @@ type: 'button', section: section.id, priority: 30, - templateId: 'customize-trash-changeset-control' + inputAttrs: { + 'class': 'button-link button-link-delete', + value: api.l10n.discardChanges + } } ); api.control.add( trashControl ); trashControl.deferred.embedded.done( function() { - trashControl.container.find( 'button' ).on( 'click', function() { + trashControl.container.find( '.button-link' ).on( 'click', function() { if ( confirm( api.l10n.trashConfirm ) ) { wp.customize.previewer.trash(); } diff --git a/src/wp-includes/class-wp-customize-control.php b/src/wp-includes/class-wp-customize-control.php index 5f60b81c04..777dec72e3 100644 --- a/src/wp-includes/class-wp-customize-control.php +++ b/src/wp-includes/class-wp-customize-control.php @@ -482,7 +482,7 @@ class WP_Customize_Control { protected function render_content() { $input_id = '_customize-input-' . $this->id; $description_id = '_customize-description-' . $this->id; - $describedby_attr = ( ! empty( $this->description ) ) ? 'aria-describedby="' . esc_attr( $description_id ) . '"' : ''; + $describedby_attr = ( ! empty( $this->description ) ) ? ' aria-describedby="' . esc_attr( $description_id ) . '" ' : ''; switch ( $this->type ) { case 'checkbox': ?> @@ -520,7 +520,8 @@ class WP_Customize_Control { + type="radio" + value="" name="" link(); ?> diff --git a/src/wp-includes/class-wp-customize-manager.php b/src/wp-includes/class-wp-customize-manager.php index 1f9847f4ad..955d59eee6 100644 --- a/src/wp-includes/class-wp-customize-manager.php +++ b/src/wp-includes/class-wp-customize-manager.php @@ -3600,8 +3600,143 @@ final class WP_Customize_Manager { ) ); $control->print_template(); } - ?> + + + + -