Customize: Ensure `MediaControl` fetches the necessary attachment data for rendering when dynamically added via JS.
Fixes #36521. Props TimothyBlynJacobs, westonruter. Built from https://develop.svn.wordpress.org/trunk@37701 git-svn-id: http://core.svn.wordpress.org/trunk@37667 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
1c2324f834
commit
c7b8333ece
|
@ -1928,16 +1928,54 @@
|
|||
control.pausePlayer();
|
||||
});
|
||||
|
||||
control.setting.bind( function( value ) {
|
||||
/**
|
||||
* Set attachment data and render content.
|
||||
*
|
||||
* Note that BackgroundImage.prototype.ready applies this ready method
|
||||
* to itself. Since BackgroundImage is an UploadControl, the value
|
||||
* is the attachment URL instead of the attachment ID. In this case
|
||||
* we skip fetching the attachment data because we have no ID available,
|
||||
* and it is the responsibility of the UploadControl to set the control's
|
||||
* attachmentData before calling the renderContent method.
|
||||
*
|
||||
* @param {number|string} value Attachment
|
||||
*/
|
||||
function setAttachmentDataAndRenderContent( value ) {
|
||||
var hasAttachmentData = $.Deferred();
|
||||
|
||||
// Send attachment information to the preview for possible use in `postMessage` transport.
|
||||
wp.media.attachment( value ).fetch().done( function() {
|
||||
wp.customize.previewer.send( control.setting.id + '-attachment-data', this.attributes );
|
||||
if ( control.extended( api.UploadControl ) ) {
|
||||
hasAttachmentData.resolve();
|
||||
} else {
|
||||
value = parseInt( value, 10 );
|
||||
if ( _.isNaN( value ) || value <= 0 ) {
|
||||
delete control.params.attachment;
|
||||
hasAttachmentData.resolve();
|
||||
} else if ( control.params.attachment && control.params.attachment.id === value ) {
|
||||
hasAttachmentData.resolve();
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch the attachment data.
|
||||
if ( 'pending' === hasAttachmentData.state() ) {
|
||||
wp.media.attachment( value ).fetch().done( function() {
|
||||
control.params.attachment = this.attributes;
|
||||
hasAttachmentData.resolve();
|
||||
|
||||
// Send attachment information to the preview for possible use in `postMessage` transport.
|
||||
wp.customize.previewer.send( control.setting.id + '-attachment-data', this.attributes );
|
||||
} );
|
||||
}
|
||||
|
||||
hasAttachmentData.done( function() {
|
||||
control.renderContent();
|
||||
} );
|
||||
}
|
||||
|
||||
// Re-render whenever the control's setting changes.
|
||||
control.renderContent();
|
||||
} );
|
||||
// Ensure attachment data is initially set (for dynamically-instantiated controls).
|
||||
setAttachmentDataAndRenderContent( control.setting() );
|
||||
|
||||
// Update the attachment data and re-render the control when the setting changes.
|
||||
control.setting.bind( setAttachmentDataAndRenderContent );
|
||||
},
|
||||
|
||||
pausePlayer: function () {
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.6-alpha-37700';
|
||||
$wp_version = '4.6-alpha-37701';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue