Media: Properly insert caption shortcodes for attachments.

git-svn-id: http://core.svn.wordpress.org/trunk@22554 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Daryl Koopersmith 2012-11-13 00:32:04 +00:00
parent 02d80201fa
commit b5ab7bbbc9
1 changed files with 24 additions and 4 deletions

View File

@ -455,7 +455,7 @@ window.wp = window.wp || {};
}; };
wp.media.string.image = function( attachment, props ) { wp.media.string.image = function( attachment, props ) {
var classes, img, options, size; var classes, img, options, size, shortcode, html;
props = _.defaults( props || {}, { props = _.defaults( props || {}, {
img: {}, img: {},
@ -481,8 +481,9 @@ window.wp = window.wp || {};
img.height = size.height; img.height = size.height;
img.src = size.url; img.src = size.url;
// Update `img` classes. // Only assign the align class to the image if we're not printing
if ( props.align ) // a caption, since the alignment is sent to the shortcode.
if ( props.align && ! attachment.caption )
classes.push( 'align' + props.align ); classes.push( 'align' + props.align );
if ( props.size ) if ( props.size )
@ -514,7 +515,26 @@ window.wp = window.wp || {};
}; };
} }
return wp.html.string( options ); html = wp.html.string( options );
// Generate the caption shortcode.
if ( attachment.caption ) {
shortcode = {
id: 'attachment_' + attachment.id,
width: img.width
};
if ( props.align )
shortcode.align = 'align' + props.align;
html = wp.shortcode.string({
tag: 'caption',
attrs: shortcode,
content: html + ' ' + attachment.caption
});
}
return html;
}; };
mceview.add( 'attachment', { mceview.add( 'attachment', {