WordPress.org

Make WordPress Core

Changeset 22220


Ignore:
Timestamp:
10/12/2012 06:36:21 PM (7 years ago)
Author:
koopersmith
Message:

Properly align MCE attachment views.

  • Adds a $wrapper property to MCE views to allow them to manipulate the wrapper on render. This should be used sparingly — only for layout changes that cannot be accomplished through altering the wrapper's children — and likely only for adding/removing classes.
  • Uses wp.html.string() in wp.mce.view.toView().

see #21390, #21812, #21813.

Location:
trunk
Files:
2 edited

Legend:

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

    r22173 r22220  
    112112                this.insert( selection.map( function( attachment ) {
    113113                    if ( 'image' === attachment.get('type') )
    114                         return '\n' + wp.media.string.image( attachment ) + '\n';
     114                        return wp.media.string.image( attachment ) + ' ';
    115115                    else
    116116                        return wp.media.string.link( attachment ) + ' ';
  • trunk/wp-includes/js/mce-view.js

    r22210 r22220  
    282282        toView: function( viewType, options ) {
    283283            var view = wp.mce.view.get( viewType ),
    284                 instance, id, tag;
     284                instance, id;
    285285
    286286            if ( ! view )
     
    297297            instances[ id ] = instance;
    298298
    299             // If the view is a span, wrap it in a span.
    300             tag = 'span' === instance.tagName ? 'span' : 'div';
    301 
    302             return '<' + tag + ' class="wp-view-wrap" data-wp-view="' + id + '" contenteditable="false"></' + tag + '>';
     299            // Create a dummy `$wrapper` property to allow `$wrapper` to be
     300            // called in the view's `render` method without a conditional.
     301            instance.$wrapper = $();
     302
     303            return wp.html.string({
     304                // If the view is a span, wrap it in a span.
     305                tag: 'span' === instance.tagName ? 'span' : 'div',
     306
     307                attrs: {
     308                    'class':           'wp-view-wrap wp-view-type-' + viewType,
     309                    'data-wp-view':    id,
     310                    'contenteditable': false
     311                }
     312            });
    303313        },
    304314
     
    317327                    return;
    318328
     329                // Link the real wrapper to the view.
     330                view.$wrapper = wrapper;
    319331                // Render the view.
    320332                view.render();
     
    544556                    return;
    545557
     558                // Align the wrapper.
     559                if ( this.align )
     560                    this.$wrapper.addClass( 'align' + this.align );
     561
     562                // Generate the template options.
    546563                options = {
    547564                    url: 'image' === attachment.type ? attachment.url : attachment.icon,
Note: See TracChangeset for help on using the changeset viewer.