Make WordPress Core

Ticket #53419: 53419.2.diff

File 53419.2.diff, 2.0 KB (added by adamsilverstein, 4 years ago)

resolve a linter issue

  • src/js/_enqueues/wp/util.js

    diff --git src/js/_enqueues/wp/util.js src/js/_enqueues/wp/util.js
    index 8384371173..8c37db324b 100644
    window.wp = window.wp || {}; 
    115115                                        }
    116116
    117117                                        if ( _.isObject( response ) && ! _.isUndefined( response.success ) ) {
    118                                                 deferred[ response.success ? 'resolveWith' : 'rejectWith' ]( deferred.jqXHR, [response.data] );
     118
     119                                                // When handling a media attachments request, get the total attachments from response headers.
     120                                                var context = this;
     121                                                deferred.done( function() {
     122                                                        if (
     123                                                                'query-attachments' === action.data.action &&
     124                                                                deferred.jqXHR.hasOwnProperty( 'getResponseHeader' ) &&
     125                                                                deferred.jqXHR.getResponseHeader( 'X-WP-Total' )
     126                                                        ) {
     127                                                                context.totalAttachments = parseInt( deferred.jqXHR.getResponseHeader( 'X-WP-Total' ), 10 );
     128                                                        } else {
     129                                                                context.totalAttachments = 0;
     130                                                        }
     131                                                } );
     132                                                deferred[ response.success ? 'resolveWith' : 'rejectWith' ]( this, [response.data] );
    119133                                        } else {
    120134                                                deferred.rejectWith( this, [response] );
    121135                                        }
  • src/js/media/models/attachments.js

    diff --git src/js/media/models/attachments.js src/js/media/models/attachments.js
    index e06d719939..42b05d7546 100644
    var Attachments = Backbone.Collection.extend(/** @lends wp.media.model.Attachmen 
    404404                });
    405405        },
    406406
    407         // Customize fetch so we can extract the total post count from the response headers.
    408         fetch: function(options) {
    409                 var collection = this;
    410                 var fetched = Backbone.Collection.prototype.fetch.call(this, options)
    411                         .done( function() {
    412                                 if ( this.hasOwnProperty( 'getResponseHeader' ) ) {
    413                                         collection.totalAttachments = parseInt( this.getResponseHeader( 'X-WP-Total' ), 10 );
    414                                 } else {
    415                                         collection.totalAttachments = 0;
    416                                 }
    417                         } );
    418                 return fetched;
    419         },
    420 
    421407        /**
    422408         * If the collection is a query, create and mirror an Attachments Query collection.
    423409         *