wp/wp-includes/js/wp-util.js
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 21 48c4eec2b7e6
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
   113 					if ( response === '1' || response === 1 ) {
   113 					if ( response === '1' || response === 1 ) {
   114 						response = { success: true };
   114 						response = { success: true };
   115 					}
   115 					}
   116 
   116 
   117 					if ( _.isObject( response ) && ! _.isUndefined( response.success ) ) {
   117 					if ( _.isObject( response ) && ! _.isUndefined( response.success ) ) {
       
   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 								action &&
       
   124 								action.data &&
       
   125 								'query-attachments' === action.data.action &&
       
   126 								deferred.jqXHR.hasOwnProperty( 'getResponseHeader' ) &&
       
   127 								deferred.jqXHR.getResponseHeader( 'X-WP-Total' )
       
   128 							) {
       
   129 								context.totalAttachments = parseInt( deferred.jqXHR.getResponseHeader( 'X-WP-Total' ), 10 );
       
   130 							} else {
       
   131 								context.totalAttachments = 0;
       
   132 							}
       
   133 						} );
   118 						deferred[ response.success ? 'resolveWith' : 'rejectWith' ]( this, [response.data] );
   134 						deferred[ response.success ? 'resolveWith' : 'rejectWith' ]( this, [response.data] );
   119 					} else {
   135 					} else {
   120 						deferred.rejectWith( this, [response] );
   136 						deferred.rejectWith( this, [response] );
   121 					}
   137 					}
   122 				}).fail( function() {
   138 				}).fail( function() {