diff --git src/js/_enqueues/wp/util.js src/js/_enqueues/wp/util.js
index 8384371173..9df29dc357 100644
|
|
|
window.wp = window.wp || {}; |
| 115 | 115 | } |
| 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( r ) { |
| | 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] ); |
| 121 | 135 | } |
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 |
| 404 | 404 | }); |
| 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. |
| 423 | 409 | * |