Changeset 24609
- Timestamp:
- 07/09/2013 08:50:32 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/js/revisions.js
r24608 r24609 210 210 // the changed attributes in `set`, and then fires the `change` events. 211 211 updateDiff: function() { 212 var from = this.get('from'); 213 this.set( 'diffId', (from ? from.id : '0' ) + ':' + this.get('to').id ); 212 var from, to, diffId; 213 214 from = this.get('from'); 215 to = this.get('to'); 216 diffId = ( from ? from.id : 0 ) + ':' + to.id; 217 218 // Check if we're actually changing the diff id. 219 if ( this._diffId === diffId ) 220 return; 221 222 this._diffId = diffId; 223 this.trigger( 'update:revisions', from, to ); 224 225 this.diffs.ensure( diffId, this ).done( function( diff ) { 226 // Check if the current diff changed while the request was in flight. 227 if ( this._diffId !== diff.id ) 228 return; 229 230 this.trigger( 'update:diff', diff ); 231 }); 214 232 } 215 233 }); … … 232 250 }); 233 251 234 this.listenTo( this.model, ' change:diffId', this.updateDiff );252 this.listenTo( this.model, 'update:diff', this.renderDiff ); 235 253 this.listenTo( this.model, 'change:compareTwoMode', this.updateCompareTwoMode ); 236 254 … … 265 283 }, 266 284 267 updateDiff: function() { 268 this.model.diffs.ensure( this.model.get('diffId'), this ).done( function( diff ) { 269 if ( this.model.get('diffId') !== diff.id ) 270 return; 271 272 this.views.set( '.revisions-diff-frame', new revisions.view.Diff({ 273 model: diff 274 }) ); 275 276 this.model.trigger('renderDiff'); 277 }); 285 renderDiff: function( diff ) { 286 this.views.set( '.revisions-diff-frame', new revisions.view.Diff({ 287 model: diff 288 }) ); 278 289 }, 279 290 … … 365 376 366 377 initialize: function() { 367 this.listenTo( this.model, ' change:diffId', this.updateMeta );378 this.listenTo( this.model, 'update:revisions', this.updateMeta ); 368 379 }, 369 380 … … 373 384 }, 374 385 375 updateMeta: function( ) {386 updateMeta: function( from, to ) { 376 387 this.$el.html( this.template( this.model.toJSON() ) ); 377 388 378 $('#restore-revision').prop( 'disabled', t his.model.get('to').attributes.current );389 $('#restore-revision').prop( 'disabled', to.attributes.current ); 379 390 } 380 391 }); … … 482 493 483 494 ready: function() { 484 this.listenTo( this.model, ' change:diffId', this.disabledButtonCheck );495 this.listenTo( this.model, 'update:revisions', this.disabledButtonCheck ); 485 496 }, 486 497 … … 583 594 }, this ); 584 595 585 // Listen for changes in the diffId586 this.listenTo( this.model, ' change:diffId', this.diffIdChanged);596 // Listen for changes to the revisions 597 this.listenTo( this.model, 'update:revisions', this.updateRevisions ); 587 598 }, 588 599 … … 673 684 }, 674 685 675 diffIdChanged: function() {676 // Reset the view settings when diffId is changed686 updateRevisions: function( from, to ) { 687 // Update the view settings when the revisions have changed. 677 688 if ( this.model.get('compareTwoMode') ) { 678 689 this.settings.set({ 'values': [ 679 this.model.revisions.indexOf( this.model.get('from')),680 this.model.revisions.indexOf( t his.model.get('to'))690 this.model.revisions.indexOf( from ), 691 this.model.revisions.indexOf( to ) 681 692 ] }); 682 693 } else { 683 this.settings.set({ 'value': this.model.revisions.indexOf( t his.model.get('to')) });694 this.settings.set({ 'value': this.model.revisions.indexOf( to ) }); 684 695 } 685 696 },
Note: See TracChangeset
for help on using the changeset viewer.