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:
Daryl Koopersmith 2012-08-31 18:38:32 +00:00
parent 77563d1614
commit e2be7ec824

View File

@ -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 ) {