Changeset 51187
- Timestamp:
- 06/20/2021 11:25:55 PM (3 years ago)
- Location:
- trunk/src/js
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/js/_enqueues/wp/util.js
r51145 r51187 116 116 117 117 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] ); 119 133 } else { 120 134 deferred.rejectWith( this, [response] ); -
trunk/src/js/media/models/attachments.js
r51145 r51187 405 405 }, 406 406 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 421 407 /** 422 408 * If the collection is a query, create and mirror an Attachments Query collection.
Note: See TracChangeset
for help on using the changeset viewer.