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 ) {
var classes, img, options, size;
var classes, img, options, size, shortcode, html;
props = _.defaults( props || {}, {
img: {},
@ -481,8 +481,9 @@ window.wp = window.wp || {};
img.height = size.height;
img.src = size.url;
// Update `img` classes.
if ( props.align )
// Only assign the align class to the image if we're not printing
// a caption, since the alignment is sent to the shortcode.
if ( props.align && ! attachment.caption )
classes.push( 'align' + props.align );
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', {