Make WordPress Core

Changeset 21689


Ignore:
Timestamp:
08/31/2012 06:38:32 PM (14 years ago)
Author:
koopersmith
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/js/media-models.js

    r21683 r21689  
    146146                        this.filters = options.filters || {};
    147147
    148                         if ( options.watch )
    149                                 this.watch( options.watch );
     148                        if ( options.observe )
     149                                this.observe( options.observe );
    150150
    151151                        if ( options.mirror )
     
    153153                },
    154154
    155                 validate: function( attachment ) {
     155                validator: function( attachment ) {
    156156                        return _.all( this.filters, function( filter ) {
    157157                                return !! filter.call( this, attachment );
     
    159159                },
    160160
    161                 changed: function( attachment, options ) {
    162 
    163                         if ( this.validate( attachment ) )
    164                                 this.add( attachment );
    165                         else
    166                                 this.remove( attachment );
    167                         return this;
    168                 },
    169 
    170                 watch: function( attachments ) {
    171                         attachments.on( 'add change', this.changed, this );
    172                 },
    173 
    174                 unwatch: function( attachments ) {
    175                         attachments.off( 'add change', this.changed, this );
     161                validate: function( attachment, options ) {
     162                        return this[ this.validator( attachment ) ? 'add' : 'remove' ]( attachment, options );
     163                },
     164
     165                observe: function( attachments ) {
     166                        attachments.on( 'add change', this.validate, this );
     167                },
     168
     169                unobserve: function( attachments ) {
     170                        attachments.off( 'add change', this.validate, this );
    176171                },
    177172
     
    319314                        }
    320315
    321                         this.watch( Attachments.all );
     316                        this.observe( Attachments.all );
    322317                },
    323318
Note: See TracChangeset for help on using the changeset viewer.