Make WordPress Core

Changeset 22760


Ignore:
Timestamp:
11/21/2012 02:20:01 PM (14 years ago)
Author:
koopersmith
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/js/media-upload.js

    r22758 r22760  
    149149                        props = _.defaults( props || {}, {
    150150                                align: getUserSetting( 'align', 'none' ),
    151                                 size:  getUserSetting( 'imgsize', 'medium' )
     151                                size:  getUserSetting( 'imgsize', 'medium' ),
     152                                url:   ''
    152153                        });
    153154
     
    169170                        }
    170171
    171                         img.width  = size.width;
    172                         img.height = size.height;
    173                         img.src    = size.url;
     172                        img.src = props.url;
     173                        _.extend( img, _.pick( props, 'width', 'height', 'alt' ) );
    174174
    175175                        // Only assign the align class to the image if we're not printing
     
    205205                        // Generate the caption shortcode.
    206206                        if ( props.caption ) {
    207                                 shortcode = {
    208                                         width: img.width
    209                                 };
     207                                shortcode = {};
     208
     209                                if ( img.width )
     210                                        shortcode.width = img.width;
    210211
    211212                                if ( props.captionId )
     
    409410
    410411                        workflow.get('embed').on( 'select', function() {
    411                                 var embed = workflow.state().toJSON(),
    412                                         options;
     412                                var embed = workflow.state().toJSON();
     413
     414                                embed.url = embed.url || '';
    413415
    414416                                if ( 'link' === embed.type ) {
    415                                         this.insert( wp.html.string({
    416                                                 tag:     'a',
    417                                                 content: embed.title || embed.url,
    418                                                 attrs:   {
    419                                                         href: embed.url
    420                                                 }
    421                                         }) );
     417                                        _.defaults( embed, {
     418                                                title:   embed.url,
     419                                                linkUrl: embed.url
     420                                        });
     421
     422                                        this.insert( wp.media.string.link( embed ) );
    422423
    423424                                } else if ( 'image' === embed.type ) {
    424425                                        _.defaults( embed, {
     426                                                title:   embed.url,
     427                                                linkUrl: '',
    425428                                                align:   'none',
    426                                                 url:     '',
    427                                                 alt:     '',
    428                                                 linkUrl: '',
    429429                                                link:    'none'
    430430                                        });
    431431
    432                                         options = {
    433                                                 single: true,
    434                                                 tag:    'img',
    435                                                 attrs:  {
    436                                                         'class': 'align' + embed.align,
    437                                                         src:     embed.url,
    438                                                         alt:     embed.alt
    439                                                 }
    440                                         };
    441 
    442                                         if ( 'custom' === embed.link || 'file' === embed.link ) {
    443                                                 options = {
    444                                                         tag:     'a',
    445                                                         content: options,
    446                                                         attrs:   {
    447                                                                 href: 'custom' === embed.link ? embed.linkUrl : embed.url
    448                                                         }
    449                                                 };
    450                                         }
    451 
    452                                         this.insert( wp.html.string( options ) );
     432                                        if ( 'none' === embed.link )
     433                                                embed.linkUrl = '';
     434                                        else if ( 'file' === embed.link )
     435                                                embed.linkUrl = embed.url;
     436
     437                                        this.insert( wp.media.string.image( embed ) );
    453438                                }
    454439                        }, this );
Note: See TracChangeset for help on using the changeset viewer.