From 4d01db3f0af7f9313a93a390d2a4e03e9833004a Mon Sep 17 00:00:00 2001 From: Daryl Koopersmith Date: Wed, 21 Nov 2012 14:20:01 +0000 Subject: [PATCH] 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 --- wp-admin/js/media-upload.js | 63 ++++++++++++++----------------------- 1 file changed, 24 insertions(+), 39 deletions(-) diff --git a/wp-admin/js/media-upload.js b/wp-admin/js/media-upload.js index f56acd066f..75e05ef4db 100644 --- a/wp-admin/js/media-upload.js +++ b/wp-admin/js/media-upload.js @@ -148,7 +148,8 @@ var tb_position; props = _.defaults( props || {}, { align: getUserSetting( 'align', 'none' ), - size: getUserSetting( 'imgsize', 'medium' ) + size: getUserSetting( 'imgsize', 'medium' ), + url: '' }); if ( attachment ) { @@ -168,9 +169,8 @@ var tb_position; }); } - img.width = size.width; - img.height = size.height; - img.src = size.url; + img.src = props.url; + _.extend( img, _.pick( props, 'width', 'height', 'alt' ) ); // Only assign the align class to the image if we're not printing // a caption, since the alignment is sent to the shortcode. @@ -204,9 +204,10 @@ var tb_position; // Generate the caption shortcode. if ( props.caption ) { - shortcode = { - width: img.width - }; + shortcode = {}; + + if ( img.width ) + shortcode.width = img.width; if ( props.captionId ) shortcode.id = props.captionId; @@ -408,48 +409,32 @@ var tb_position; }, this ); workflow.get('embed').on( 'select', function() { - var embed = workflow.state().toJSON(), - options; + var embed = workflow.state().toJSON(); + + embed.url = embed.url || ''; if ( 'link' === embed.type ) { - this.insert( wp.html.string({ - tag: 'a', - content: embed.title || embed.url, - attrs: { - href: embed.url - } - }) ); + _.defaults( embed, { + title: embed.url, + linkUrl: embed.url + }); + + this.insert( wp.media.string.link( embed ) ); } else if ( 'image' === embed.type ) { _.defaults( embed, { - align: 'none', - url: '', - alt: '', + title: embed.url, linkUrl: '', + align: 'none', link: 'none' }); - options = { - single: true, - tag: 'img', - attrs: { - 'class': 'align' + embed.align, - src: embed.url, - alt: embed.alt - } - }; + if ( 'none' === embed.link ) + embed.linkUrl = ''; + else if ( 'file' === embed.link ) + embed.linkUrl = embed.url; - if ( 'custom' === embed.link || 'file' === embed.link ) { - options = { - tag: 'a', - content: options, - attrs: { - href: 'custom' === embed.link ? embed.linkUrl : embed.url - } - }; - } - - this.insert( wp.html.string( options ) ); + this.insert( wp.media.string.image( embed ) ); } }, this );