Media: Use the wp.media.string functions when generating embed strings. Embed captions now work. see #21390.

git-svn-id: http://core.svn.wordpress.org/trunk@22760 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Daryl Koopersmith 2012-11-21 14:20:01 +00:00
parent 75c464671d
commit 4d01db3f0a

View File

@ -148,7 +148,8 @@ var tb_position;
props = _.defaults( props || {}, { props = _.defaults( props || {}, {
align: getUserSetting( 'align', 'none' ), align: getUserSetting( 'align', 'none' ),
size: getUserSetting( 'imgsize', 'medium' ) size: getUserSetting( 'imgsize', 'medium' ),
url: ''
}); });
if ( attachment ) { if ( attachment ) {
@ -168,9 +169,8 @@ var tb_position;
}); });
} }
img.width = size.width; img.src = props.url;
img.height = size.height; _.extend( img, _.pick( props, 'width', 'height', 'alt' ) );
img.src = size.url;
// Only assign the align class to the image if we're not printing // Only assign the align class to the image if we're not printing
// a caption, since the alignment is sent to the shortcode. // a caption, since the alignment is sent to the shortcode.
@ -204,9 +204,10 @@ var tb_position;
// Generate the caption shortcode. // Generate the caption shortcode.
if ( props.caption ) { if ( props.caption ) {
shortcode = { shortcode = {};
width: img.width
}; if ( img.width )
shortcode.width = img.width;
if ( props.captionId ) if ( props.captionId )
shortcode.id = props.captionId; shortcode.id = props.captionId;
@ -408,48 +409,32 @@ var tb_position;
}, this ); }, this );
workflow.get('embed').on( 'select', function() { workflow.get('embed').on( 'select', function() {
var embed = workflow.state().toJSON(), var embed = workflow.state().toJSON();
options;
embed.url = embed.url || '';
if ( 'link' === embed.type ) { if ( 'link' === embed.type ) {
this.insert( wp.html.string({ _.defaults( embed, {
tag: 'a', title: embed.url,
content: embed.title || embed.url, linkUrl: embed.url
attrs: { });
href: embed.url
} this.insert( wp.media.string.link( embed ) );
}) );
} else if ( 'image' === embed.type ) { } else if ( 'image' === embed.type ) {
_.defaults( embed, { _.defaults( embed, {
align: 'none', title: embed.url,
url: '',
alt: '',
linkUrl: '', linkUrl: '',
align: 'none',
link: 'none' link: 'none'
}); });
options = { if ( 'none' === embed.link )
single: true, embed.linkUrl = '';
tag: 'img', else if ( 'file' === embed.link )
attrs: { embed.linkUrl = embed.url;
'class': 'align' + embed.align,
src: embed.url,
alt: embed.alt
}
};
if ( 'custom' === embed.link || 'file' === embed.link ) { this.insert( wp.media.string.image( embed ) );
options = {
tag: 'a',
content: options,
attrs: {
href: 'custom' === embed.link ? embed.linkUrl : embed.url
}
};
}
this.insert( wp.html.string( options ) );
} }
}, this ); }, this );