mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-03 15:08:10 +01:00
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.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.
|
if ( control.extended( api.UploadControl ) ) {
|
||||||
wp.media.attachment( value ).fetch().done( function() {
|
hasAttachmentData.resolve();
|
||||||
wp.customize.previewer.send( control.setting.id + '-attachment-data', this.attributes );
|
} 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.
|
// Ensure attachment data is initially set (for dynamically-instantiated controls).
|
||||||
control.renderContent();
|
setAttachmentDataAndRenderContent( control.setting() );
|
||||||
} );
|
|
||||||
|
// Update the attachment data and re-render the control when the setting changes.
|
||||||
|
control.setting.bind( setAttachmentDataAndRenderContent );
|
||||||
},
|
},
|
||||||
|
|
||||||
pausePlayer: function () {
|
pausePlayer: function () {
|
||||||
|
4
wp-admin/js/customize-controls.min.js
vendored
4
wp-admin/js/customize-controls.min.js
vendored
File diff suppressed because one or more lines are too long
@ -4,7 +4,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @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.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
Loading…
Reference in New Issue
Block a user