Make WordPress Core

Changeset 22660


Ignore:
Timestamp:
11/19/2012 04:41:57 AM (14 years ago)
Author:
koopersmith
Message:

Media: Allow subviews to be inserted at a specific index. see #21390.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/js/media-views.js

    r22659 r22660  
    592592                        add      = options && options.add;
    593593                        existing = this.get( selector );
     594                        next     = views;
    594595                        method   = add ? 'attach' : 'replace';
    595596
    596                         if ( ! add && existing ) {
    597                                 this.unset( selector );
    598                                 _.invoke( existing, 'dispose' );
     597                        if ( existing ) {
     598                                if ( add ) {
     599                                        if ( _.isUndefined( options.at ) )
     600                                                next = existing.concat( views );
     601                                        else
     602                                                next = existing.splice.apply( existing, [ options.at, 0 ].concat( views ) );
     603                                } else {
     604                                        this.unset( selector );
     605                                        _.invoke( existing, 'dispose' );
     606                                }
    599607                        }
    600608
    601                         this._views[ selector ] = add && existing ? existing.concat( views ) : views;
     609                        this._views[ selector ] = next;
    602610
    603611                        $selector = selector ? this.view.$( selector ) : this.view.$el;
    … …  
    611619                        }, this );
    612620
    613                         this[ method ]( $selector, els );
    614                         return this;
    615                 },
    616 
    617                 add: function( selector, views ) {
    618                         return this.set( selector, views, { add: true });
     621                        this[ method ]( $selector, els, options );
     622                        return this;
     623                },
     624
     625                add: function( selector, views, options ) {
     626                        return this.set( selector, views, _.extend({ add: true }, options ) );
    619627                },
    620628
    … …  
    662670                },
    663671
    664                 attach: function( $target, els ) {
    665                         $target.append( els );
     672                attach: function( $target, els, options ) {
     673                        var at = options && options.at,
     674                                $children;
     675
     676                        if ( _.isNumber( at ) && ($children = $target.children()).length > at )
     677                                $children.eq( at ).before( els );
     678                        else
     679                                $target.append( els );
     680
    666681                        return this;
    667682                }
Note: See TracChangeset for help on using the changeset viewer.