Make WordPress Core

Changeset 51191


Ignore:
Timestamp:
06/21/2021 08:44:41 PM (5 years ago)
Author:
joedolson
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/media/models/attachments.js

    r51187 r51191  
    213213
    214214                attachments.on( 'add change remove', this._validateHandler, this );
     215                attachments.on( 'add', this._addToTotalAttachments, this );
     216                attachments.on( 'remove', this._removeFromTotalAttachments, this );
    215217                attachments.on( 'reset', this._validateAllHandler, this );
    216218                this.validateAll( attachments );
    … …  
    236238
    237239                return this;
     240        },
     241        /**
     242         * Update total attachment count when items are added to a collection.
     243         *
     244         * @access private
     245         *
     246         * @since 5.8.0
     247         */
     248        _removeFromTotalAttachments: function() {
     249                if ( this.mirroring ) {
     250                        this.mirroring.totalAttachments = this.mirroring.totalAttachments - 1;
     251                }
     252        },
     253        /**
     254         * Update total attachment count when items are added to a collection.
     255         *
     256         * @access private
     257         *
     258         * @since 5.8.0
     259         */
     260        _addToTotalAttachments: function() {
     261                if ( this.mirroring ) {
     262                        this.mirroring.totalAttachments = this.mirroring.totalAttachments + 1;
     263                }
    238264        },
    239265        /**
Note: See TracChangeset for help on using the changeset viewer.