Make WordPress Core

Changeset 22746


Ignore:
Timestamp:
11/21/2012 11:35:30 AM (14 years ago)
Author:
koopersmith
Message:

Media: Make mirroring a collection of attachments a special case of observing a collection of attachments. see #21390.

File:
1 edited

Legend:

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

    r22743 r22746  
    363363                                hasAttachment = !! this.getByCid( attachment.cid );
    364364
    365                         // Only retain the `silent` option.
    366                         options = {
    367                                 silent: options && options.silent
    368                         };
    369 
    370365                        if ( ! valid && hasAttachment )
    371366                                this.remove( attachment, options );
    … …  
    376371                },
    377372
    378                 validateAll: function( attachments ) {
     373                validateAll: function( attachments, options ) {
     374                        options = options || {};
     375
    379376                        _.each( attachments.models, function( attachment ) {
    380377                                this.validate( attachment, { silent: true });
    381378                        }, this );
     379
     380                        if ( ! options.silent )
     381                                this.trigger( 'reset', this, options );
    382382
    383383                        return this;
    … …  
    411411
    412412                _validateHandler: function( attachment, attachments, options ) {
     413                        // If we're not mirroring this `attachments` collection,
     414                        // only retain the `silent` option.
     415                        options = attachments === this.mirroring ? options : {
     416                                silent: options && options.silent
     417                        };
     418
    413419                        return this.validate( attachment, options );
    414420                },
    … …  
    424430                        this.unmirror();
    425431                        this.mirroring = attachments;
    426                         this.reset( attachments.models );
    427                         attachments.on( 'add',    this._mirrorAdd,    this );
    428                         attachments.on( 'remove', this._mirrorRemove, this );
    429                         attachments.on( 'reset',  this._mirrorReset,  this );
     432
     433                        // Clear the collection silently. A `reset` event will be fired
     434                        // when `observe()` calls `validateAll()`.
     435                        this.reset( [], { silent: true } );
     436                        this.observe( attachments );
    430437                },
    431438
    … …  
    434441                                return;
    435442
    436                         this.mirroring.off( 'add',    this._mirrorAdd,    this );
    437                         this.mirroring.off( 'remove', this._mirrorRemove, this );
    438                         this.mirroring.off( 'reset',  this._mirrorReset,  this );
     443                        this.unobserve( this.mirroring );
    439444                        delete this.mirroring;
    440                 },
    441 
    442                 _mirrorAdd: function( attachment, attachments, options ) {
    443                         this.add( attachment, { at: options.index });
    444                 },
    445 
    446                 _mirrorRemove: function( attachment ) {
    447                         this.remove( attachment );
    448                 },
    449 
    450                 _mirrorReset: function( attachments ) {
    451                         this.reset( attachments.models );
    452445                },
    453446
Note: See TracChangeset for help on using the changeset viewer.