Media JS: Attachments collection API improvements.
Rename watch() and unwatch() to observe() and unobserve(), respectively, to avoid conflicts with Firefox's proprietary Object.prototype.watch method. Rename validate() to validator(), and changed() to validate(), as the latter will be more frequently used, and better explains its purpose. Also, make the new validate() more concise. see #21390. git-svn-id: https://develop.svn.wordpress.org/trunk@21689 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
02975388bd
commit
8f7b835954
@ -145,34 +145,29 @@ if ( typeof wp === 'undefined' )
|
||||
|
||||
this.filters = options.filters || {};
|
||||
|
||||
if ( options.watch )
|
||||
this.watch( options.watch );
|
||||
if ( options.observe )
|
||||
this.observe( options.observe );
|
||||
|
||||
if ( options.mirror )
|
||||
this.mirror( options.mirror );
|
||||
},
|
||||
|
||||
validate: function( attachment ) {
|
||||
validator: function( attachment ) {
|
||||
return _.all( this.filters, function( filter ) {
|
||||
return !! filter.call( this, attachment );
|
||||
}, this );
|
||||
},
|
||||
|
||||
changed: function( attachment, options ) {
|
||||
|
||||
if ( this.validate( attachment ) )
|
||||
this.add( attachment );
|
||||
else
|
||||
this.remove( attachment );
|
||||
return this;
|
||||
validate: function( attachment, options ) {
|
||||
return this[ this.validator( attachment ) ? 'add' : 'remove' ]( attachment, options );
|
||||
},
|
||||
|
||||
watch: function( attachments ) {
|
||||
attachments.on( 'add change', this.changed, this );
|
||||
observe: function( attachments ) {
|
||||
attachments.on( 'add change', this.validate, this );
|
||||
},
|
||||
|
||||
unwatch: function( attachments ) {
|
||||
attachments.off( 'add change', this.changed, this );
|
||||
unobserve: function( attachments ) {
|
||||
attachments.off( 'add change', this.validate, this );
|
||||
},
|
||||
|
||||
mirror: function( attachments ) {
|
||||
@ -318,7 +313,7 @@ if ( typeof wp === 'undefined' )
|
||||
};
|
||||
}
|
||||
|
||||
this.watch( Attachments.all );
|
||||
this.observe( Attachments.all );
|
||||
},
|
||||
|
||||
more: function( options ) {
|
||||
|
Loading…
Reference in New Issue
Block a user