Media: Allow subviews to be inserted at a specific index. see #21390.
git-svn-id: http://core.svn.wordpress.org/trunk@22660 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
795ba27d10
commit
473583a4f4
|
@ -591,14 +591,22 @@
|
||||||
views = _.isArray( views ) ? views : [ views ];
|
views = _.isArray( views ) ? views : [ views ];
|
||||||
add = options && options.add;
|
add = options && options.add;
|
||||||
existing = this.get( selector );
|
existing = this.get( selector );
|
||||||
|
next = views;
|
||||||
method = add ? 'attach' : 'replace';
|
method = add ? 'attach' : 'replace';
|
||||||
|
|
||||||
if ( ! add && existing ) {
|
if ( existing ) {
|
||||||
|
if ( add ) {
|
||||||
|
if ( _.isUndefined( options.at ) )
|
||||||
|
next = existing.concat( views );
|
||||||
|
else
|
||||||
|
next = existing.splice.apply( existing, [ options.at, 0 ].concat( views ) );
|
||||||
|
} else {
|
||||||
this.unset( selector );
|
this.unset( selector );
|
||||||
_.invoke( existing, 'dispose' );
|
_.invoke( existing, 'dispose' );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this._views[ selector ] = add && existing ? existing.concat( views ) : views;
|
this._views[ selector ] = next;
|
||||||
|
|
||||||
$selector = selector ? this.view.$( selector ) : this.view.$el;
|
$selector = selector ? this.view.$( selector ) : this.view.$el;
|
||||||
els = _.pluck( views, 'el' );
|
els = _.pluck( views, 'el' );
|
||||||
|
@ -610,12 +618,12 @@
|
||||||
subviews.selector = selector;
|
subviews.selector = selector;
|
||||||
}, this );
|
}, this );
|
||||||
|
|
||||||
this[ method ]( $selector, els );
|
this[ method ]( $selector, els, options );
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
add: function( selector, views ) {
|
add: function( selector, views, options ) {
|
||||||
return this.set( selector, views, { add: true });
|
return this.set( selector, views, _.extend({ add: true }, options ) );
|
||||||
},
|
},
|
||||||
|
|
||||||
unset: function( selector, views ) {
|
unset: function( selector, views ) {
|
||||||
|
@ -661,8 +669,15 @@
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
attach: function( $target, els ) {
|
attach: function( $target, els, options ) {
|
||||||
|
var at = options && options.at,
|
||||||
|
$children;
|
||||||
|
|
||||||
|
if ( _.isNumber( at ) && ($children = $target.children()).length > at )
|
||||||
|
$children.eq( at ).before( els );
|
||||||
|
else
|
||||||
$target.append( els );
|
$target.append( els );
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue