Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/js/media/models/attachments.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,17 +204,27 @@ var Attachments = Backbone.Collection.extend(/** @lends wp.media.model.Attachmen
* Start observing another attachments collection change events
* and replicate them on this collection.
*
* @param {wp.media.model.Attachments} The attachments collection to observe.
* @param {wp.media.model.Attachments} attachments The attachments collection to observe.
* @return {wp.media.model.Attachments} Returns itself to allow chaining.
*/
observe: function( attachments ) {
this.observers = this.observers || [];
this.observers.push( attachments );

attachments.on( 'add change remove', this._validateHandler, this );
attachments.on( 'add', this._addToTotalAttachments, this );
attachments.on( 'remove', this._removeFromTotalAttachments, this );
attachments.on( 'reset', this._validateAllHandler, this );

/*
* Only track the total number of attachments for the mirrored query
* collection. Other observed collections, such as the selection, must
* not change the count, otherwise an uploaded attachment that is also
* added to the selection is counted more than once. See ticket #65513.
*/
if ( attachments === this.mirroring ) {
attachments.on( 'add', this._addToTotalAttachments, this );
attachments.on( 'remove', this._removeFromTotalAttachments, this );
}

this.validateAll( attachments );
return this;
},
Expand All @@ -239,7 +249,7 @@ var Attachments = Backbone.Collection.extend(/** @lends wp.media.model.Attachmen
return this;
},
/**
* Update total attachment count when items are added to a collection.
* Update total attachment count when items are removed from a collection.
*
* @access private
*
Expand Down
Loading