From 422d301ac0f910e6f2d19834a41892f8bf8953f6 Mon Sep 17 00:00:00 2001 From: Joe Dolson Date: Mon, 21 Jun 2021 20:44:41 +0000 Subject: [PATCH] Media: Update total attachment count when media added or removed. Add handlers to increment the total attachments count for the media collection when an item is added or removed. props adamsilverstein. Fixes #53171. git-svn-id: https://develop.svn.wordpress.org/trunk@51191 602fd350-edb4-49c9-b593-d223f7449a82 --- src/js/media/models/attachments.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/js/media/models/attachments.js b/src/js/media/models/attachments.js index 42b05d7546..23510bd949 100644 --- a/src/js/media/models/attachments.js +++ b/src/js/media/models/attachments.js @@ -212,6 +212,8 @@ var Attachments = Backbone.Collection.extend(/** @lends wp.media.model.Attachmen 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 ); this.validateAll( attachments ); return this; @@ -236,6 +238,30 @@ var Attachments = Backbone.Collection.extend(/** @lends wp.media.model.Attachmen return this; }, + /** + * Update total attachment count when items are added to a collection. + * + * @access private + * + * @since 5.8.0 + */ + _removeFromTotalAttachments: function() { + if ( this.mirroring ) { + this.mirroring.totalAttachments = this.mirroring.totalAttachments - 1; + } + }, + /** + * Update total attachment count when items are added to a collection. + * + * @access private + * + * @since 5.8.0 + */ + _addToTotalAttachments: function() { + if ( this.mirroring ) { + this.mirroring.totalAttachments = this.mirroring.totalAttachments + 1; + } + }, /** * @access private *