Media: Keep the selected featured image in the media modal in sync with the page. fixes #22404, see #21390.
git-svn-id: http://core.svn.wordpress.org/trunk@22528 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
14295d4374
commit
ead998c57d
|
@ -1009,15 +1009,29 @@ function post_thumbnail_meta_box( $post ) {
|
||||||
$thumbnailId = $element.find('input[name="thumbnail_id"]'),
|
$thumbnailId = $element.find('input[name="thumbnail_id"]'),
|
||||||
title = '<?php _e( "Choose a Featured Image" ); ?>',
|
title = '<?php _e( "Choose a Featured Image" ); ?>',
|
||||||
update = '<?php _e( "Update Featured Image" ); ?>',
|
update = '<?php _e( "Update Featured Image" ); ?>',
|
||||||
|
Attachment = wp.media.model.Attachment,
|
||||||
frame, setFeaturedImage;
|
frame, setFeaturedImage;
|
||||||
|
|
||||||
setFeaturedImage = function( thumbnailId ) {
|
setFeaturedImage = function( thumbnailId ) {
|
||||||
|
var selection;
|
||||||
|
|
||||||
$element.find('img').remove();
|
$element.find('img').remove();
|
||||||
$element.toggleClass( 'has-featured-image', -1 != thumbnailId );
|
$element.toggleClass( 'has-featured-image', -1 != thumbnailId );
|
||||||
$thumbnailId.val( thumbnailId );
|
$thumbnailId.val( thumbnailId );
|
||||||
|
|
||||||
|
if ( frame ) {
|
||||||
|
selection = frame.get('library').get('selection');
|
||||||
|
|
||||||
|
if ( -1 === thumbnailId )
|
||||||
|
selection.clear();
|
||||||
|
else
|
||||||
|
selection.add( Attachment.get( thumbnailId ) );
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$element.on( 'click', '.choose, img', function( event ) {
|
$element.on( 'click', '.choose, img', function( event ) {
|
||||||
|
var options, thumbnailId;
|
||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
if ( frame ) {
|
if ( frame ) {
|
||||||
|
@ -1025,13 +1039,18 @@ function post_thumbnail_meta_box( $post ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
frame = wp.media({
|
options = {
|
||||||
title: title,
|
title: title,
|
||||||
selection: [ wp.media.model.Attachment.get( $thumbnailId.val() ) ],
|
library: {
|
||||||
library: {
|
|
||||||
type: 'image'
|
type: 'image'
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
thumbnailId = $thumbnailId.val();
|
||||||
|
if ( '' !== thumbnailId && -1 !== thumbnailId )
|
||||||
|
options.selection = [ Attachment.get( thumbnailId ) ];
|
||||||
|
|
||||||
|
frame = wp.media( options );
|
||||||
|
|
||||||
frame.toolbar.on( 'activate:select', function() {
|
frame.toolbar.on( 'activate:select', function() {
|
||||||
frame.toolbar.view().add({
|
frame.toolbar.view().add({
|
||||||
|
|
Loading…
Reference in New Issue