mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-24 18:18:01 +01:00
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: http://core.svn.wordpress.org/trunk@21689 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
77563d1614
commit
e2be7ec824
@ -145,34 +145,29 @@ if ( typeof wp === 'undefined' )
|
|||||||
|
|
||||||
this.filters = options.filters || {};
|
this.filters = options.filters || {};
|
||||||
|
|
||||||
if ( options.watch )
|
if ( options.observe )
|
||||||
this.watch( options.watch );
|
this.observe( options.observe );
|
||||||
|
|
||||||
if ( options.mirror )
|
if ( options.mirror )
|
||||||
this.mirror( options.mirror );
|
this.mirror( options.mirror );
|
||||||
},
|
},
|
||||||
|
|
||||||
validate: function( attachment ) {
|
validator: function( attachment ) {
|
||||||
return _.all( this.filters, function( filter ) {
|
return _.all( this.filters, function( filter ) {
|
||||||
return !! filter.call( this, attachment );
|
return !! filter.call( this, attachment );
|
||||||
}, this );
|
}, this );
|
||||||
},
|
},
|
||||||
|
|
||||||
changed: function( attachment, options ) {
|
validate: function( attachment, options ) {
|
||||||
|
return this[ this.validator( attachment ) ? 'add' : 'remove' ]( attachment, options );
|
||||||
if ( this.validate( attachment ) )
|
|
||||||
this.add( attachment );
|
|
||||||
else
|
|
||||||
this.remove( attachment );
|
|
||||||
return this;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
watch: function( attachments ) {
|
observe: function( attachments ) {
|
||||||
attachments.on( 'add change', this.changed, this );
|
attachments.on( 'add change', this.validate, this );
|
||||||
},
|
},
|
||||||
|
|
||||||
unwatch: function( attachments ) {
|
unobserve: function( attachments ) {
|
||||||
attachments.off( 'add change', this.changed, this );
|
attachments.off( 'add change', this.validate, this );
|
||||||
},
|
},
|
||||||
|
|
||||||
mirror: function( attachments ) {
|
mirror: function( attachments ) {
|
||||||
@ -318,7 +313,7 @@ if ( typeof wp === 'undefined' )
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
this.watch( Attachments.all );
|
this.observe( Attachments.all );
|
||||||
},
|
},
|
||||||
|
|
||||||
more: function( options ) {
|
more: function( options ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user