Changeset 24771
- Timestamp:
- 07/22/2013 10:24:33 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/js/media-models.js
r24652 r24771 2 2 3 3 (function($){ 4 var Attachment, Attachments, Query, compare, l10n, media , bindSyncEvents;4 var Attachment, Attachments, Query, compare, l10n, media; 5 5 6 6 /** … … 68 68 }; 69 69 70 // Ensures the 'sync' and 'error' events are always71 // correctly triggered when overloading `Backbone.sync`.72 bindSyncEvents = function( model, options ) {73 var success = options.success,74 error = options.error;75 76 options.success = function( resp ) {77 if ( success )78 success( resp );79 model.trigger( 'sync', model, resp, options );80 };81 82 options.error = function( xhr ) {83 if ( error )84 error( xhr );85 model.trigger( 'error', model, xhr, options );86 };87 88 return options;89 };90 91 70 _.extend( media, { 92 71 /** … … 198 177 id: this.id 199 178 }); 200 bindSyncEvents( model, options );201 179 return media.ajax( options ); 202 180 … … 227 205 } 228 206 229 bindSyncEvents( model, options );230 207 return media.ajax( options ); 231 208 … … 245 222 }); 246 223 247 bindSyncEvents( model, options );248 224 return media.ajax( options ).done( function() { 249 225 this.destroyed = true; … … 505 481 hasMore: function() { 506 482 return this.mirroring ? this.mirroring.hasMore() : false; 483 }, 484 485 parse: function( resp, xhr ) { 486 if ( ! _.isArray( resp ) ) 487 resp = [resp]; 488 489 return _.map( resp, function( attrs ) { 490 var id, attachment; 491 if ( attrs instanceof Backbone.Model ) { 492 id = attrs.get( 'id' ); 493 attrs = attrs.attributes; 494 } else { 495 id = attrs.id; 496 } 497 498 attachment = Attachment.get( attrs.id ); 499 if ( ! _.isEqual( attachment.attributes, attrs ) ) 500 attachment.set( attachment.parse( attrs, xhr ) ); 501 502 return attachment; 503 }); 507 504 }, 508 505 … … 702 699 703 700 options.data.query = args; 704 bindSyncEvents( model, options );705 701 return media.ajax( options ); 706 702
Note: See TracChangeset
for help on using the changeset viewer.