Customize: Rely on selective refresh exclusively for previewing custom logo changes.

Eliminates JS logic (from [36698]) which attempted to do pure JS update while waiting for the selective refresh response to return. The duplicate JS logic lacked a re-implementation of the `image_downsize()` functionality available in PHP, and so the JS preview logic would fail to properly preview images that didn't have the exact theme image size generated. To keep the code DRY and to eliminate the momentary display of an improperly-sized image, the duplicated JS logic is now removed.

See #27355.
See #33755.
Fixes #36096.


git-svn-id: https://develop.svn.wordpress.org/trunk@36990 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Weston Ruter 2016-03-14 19:16:09 +00:00
parent 9f05bf8ed9
commit a0148962a2
1 changed files with 4 additions and 46 deletions

View File

@ -226,57 +226,15 @@
/**
* Custom Logo
*
* The custom logo setting only contains the attachment ID. To avoid having to send an AJAX request to get more
* data, we send a separate message with the attachment data we get from the Customizer's media modal.
* Therefore first callback handles only the event of a new logo being selected.
*
* We don't need any information about a removed logo, so the second callback only handles that.
* Toggle the wp-custom-logo body class when a logo is added or removed.
*
* @since 4.5.0
*/
api.preview.bind( 'custom_logo-attachment-data', function( attachment ) {
var $logo = $( '.custom-logo' ),
size = $logo.data( 'size' ),
srcset = [];
// If the source was smaller than the size required by the theme, give the biggest we've got.
if ( ! attachment.sizes[ size ] ) {
size = 'full';
}
_.each( attachment.sizes, function( size ) {
srcset.push( size.url + ' ' + size.width + 'w' );
} );
$logo.attr( {
height: attachment.sizes[ size ].height,
width: attachment.sizes[ size ].width,
src: attachment.sizes[ size ].url,
srcset: srcset
} );
$( '.custom-logo-link' ).show();
$( 'body' ).addClass( 'wp-custom-logo' );
} );
api( 'custom_logo', function( setting ) {
setting.bind( function( newValue ) {
if ( ! newValue ) {
$( '.custom-logo-link' ).hide();
$( 'body' ).removeClass( 'wp-custom-logo' );
}
$( 'body' ).toggleClass( 'wp-custom-logo', !! setting.get() );
setting.bind( function( attachmentId ) {
$( 'body' ).toggleClass( 'wp-custom-logo', !! attachmentId );
} );
// Focus on the control when the logo is clicked, if there is no custom_logo partial.
if ( ! api.selectiveRefresh || ! api.selectiveRefresh.partial.has( 'custom_logo' ) ) {
$( document.body ).on( 'click', '.custom-logo-link', function( e ) {
if ( ! e.shiftKey ) {
return;
}
api.preview.send( 'focus-control-for-setting', 'custom_logo' );
} );
$( '.custom-logo-link' ).attr( 'title', api.settings.l10n.shiftClickToEdit );
}
} );
api.trigger( 'preview-ready' );