Ticket #24753: 24753.diff
File 24753.diff, 2.6 KB (added by , 12 years ago) |
---|
-
wp-includes/js/media-models.js
1 1 window.wp = window.wp || {}; 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 /** 7 7 * wp.media( attributes ) … … window.wp = window.wp || {}; 67 67 return a > b ? -1 : 1; 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 /** 93 72 * media.template( id ) … … window.wp = window.wp || {}; 197 176 action: 'get-attachment', 198 177 id: this.id 199 178 }); 200 bindSyncEvents( model, options );201 179 return media.ajax( options ); 202 180 203 181 // Overload the `update` request so properties can be saved. … … window.wp = window.wp || {}; 226 204 }, this ); 227 205 } 228 206 229 bindSyncEvents( model, options );230 207 return media.ajax( options ); 231 208 232 209 // Overload the `delete` request so attachments can be removed. … … window.wp = window.wp || {}; 244 221 _wpnonce: this.get('nonces')['delete'] 245 222 }); 246 223 247 bindSyncEvents( model, options );248 224 return media.ajax( options ).done( function() { 249 225 this.destroyed = true; 250 226 }).fail( function() { … … window.wp = window.wp || {}; 506 482 return this.mirroring ? this.mirroring.hasMore() : false; 507 483 }, 508 484 485 parse: function( resp, xhr ) { 486 if (! _.isArray(resp)) 487 resp = [resp]; 488 489 return _.map( resp, function( attrs ) { 490 if (attrs instanceof Backbone.Model ) 491 return attrs; 492 493 var attachment = Attachment.get( attrs.id ); 494 return attachment.set( attachment.parse( attrs, xhr ) ); 495 }); 496 }, 497 509 498 _requery: function() { 510 499 if ( this.props.get('query') ) 511 500 this.mirror( Query.get( this.props.toJSON() ) ); … … window.wp = window.wp || {}; 701 690 args.paged = Math.floor( this.length / args.posts_per_page ) + 1; 702 691 703 692 options.data.query = args; 704 bindSyncEvents( model, options );705 693 return media.ajax( options ); 706 694 707 695 // Otherwise, fall back to Backbone.sync()