Media: Properly insert caption shortcodes for attachments.

git-svn-id: https://develop.svn.wordpress.org/trunk@22554 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Daryl Koopersmith 2012-11-13 00:32:04 +00:00
parent 55543163fe
commit 630484f453
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', {