mirror of
https://github.com/WordPress/WordPress.git
synced 2024-10-01 00:27:38 +02:00
Media: Make mirroring a collection of attachments a special case of observing a collection of attachments. see #21390.
git-svn-id: http://core.svn.wordpress.org/trunk@22746 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
ff482e86fb
commit
ff1707892d
@ -362,11 +362,6 @@ window.wp = window.wp || {};
|
|||||||
var valid = this.validator( attachment ),
|
var valid = this.validator( attachment ),
|
||||||
hasAttachment = !! this.getByCid( attachment.cid );
|
hasAttachment = !! this.getByCid( attachment.cid );
|
||||||
|
|
||||||
// Only retain the `silent` option.
|
|
||||||
options = {
|
|
||||||
silent: options && options.silent
|
|
||||||
};
|
|
||||||
|
|
||||||
if ( ! valid && hasAttachment )
|
if ( ! valid && hasAttachment )
|
||||||
this.remove( attachment, options );
|
this.remove( attachment, options );
|
||||||
else if ( valid && ! hasAttachment )
|
else if ( valid && ! hasAttachment )
|
||||||
@ -375,11 +370,16 @@ window.wp = window.wp || {};
|
|||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
validateAll: function( attachments ) {
|
validateAll: function( attachments, options ) {
|
||||||
|
options = options || {};
|
||||||
|
|
||||||
_.each( attachments.models, function( attachment ) {
|
_.each( attachments.models, function( attachment ) {
|
||||||
this.validate( attachment, { silent: true });
|
this.validate( attachment, { silent: true });
|
||||||
}, this );
|
}, this );
|
||||||
|
|
||||||
|
if ( ! options.silent )
|
||||||
|
this.trigger( 'reset', this, options );
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -410,6 +410,12 @@ window.wp = window.wp || {};
|
|||||||
},
|
},
|
||||||
|
|
||||||
_validateHandler: function( attachment, attachments, options ) {
|
_validateHandler: function( attachment, attachments, options ) {
|
||||||
|
// If we're not mirroring this `attachments` collection,
|
||||||
|
// only retain the `silent` option.
|
||||||
|
options = attachments === this.mirroring ? options : {
|
||||||
|
silent: options && options.silent
|
||||||
|
};
|
||||||
|
|
||||||
return this.validate( attachment, options );
|
return this.validate( attachment, options );
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -423,34 +429,21 @@ window.wp = window.wp || {};
|
|||||||
|
|
||||||
this.unmirror();
|
this.unmirror();
|
||||||
this.mirroring = attachments;
|
this.mirroring = attachments;
|
||||||
this.reset( attachments.models );
|
|
||||||
attachments.on( 'add', this._mirrorAdd, this );
|
// Clear the collection silently. A `reset` event will be fired
|
||||||
attachments.on( 'remove', this._mirrorRemove, this );
|
// when `observe()` calls `validateAll()`.
|
||||||
attachments.on( 'reset', this._mirrorReset, this );
|
this.reset( [], { silent: true } );
|
||||||
|
this.observe( attachments );
|
||||||
},
|
},
|
||||||
|
|
||||||
unmirror: function() {
|
unmirror: function() {
|
||||||
if ( ! this.mirroring )
|
if ( ! this.mirroring )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this.mirroring.off( 'add', this._mirrorAdd, this );
|
this.unobserve( this.mirroring );
|
||||||
this.mirroring.off( 'remove', this._mirrorRemove, this );
|
|
||||||
this.mirroring.off( 'reset', this._mirrorReset, this );
|
|
||||||
delete this.mirroring;
|
delete this.mirroring;
|
||||||
},
|
},
|
||||||
|
|
||||||
_mirrorAdd: function( attachment, attachments, options ) {
|
|
||||||
this.add( attachment, { at: options.index });
|
|
||||||
},
|
|
||||||
|
|
||||||
_mirrorRemove: function( attachment ) {
|
|
||||||
this.remove( attachment );
|
|
||||||
},
|
|
||||||
|
|
||||||
_mirrorReset: function( attachments ) {
|
|
||||||
this.reset( attachments.models );
|
|
||||||
},
|
|
||||||
|
|
||||||
more: function( options ) {
|
more: function( options ) {
|
||||||
if ( this.mirroring && this.mirroring.more )
|
if ( this.mirroring && this.mirroring.more )
|
||||||
return this.mirroring.more( options );
|
return this.mirroring.more( options );
|
||||||
|
Loading…
Reference in New Issue
Block a user