Changeset 24613
- Timestamp:
- 07/09/2013 07:00:11 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/js/revisions.js
r24611 r24613 8 8 // Link settings. 9 9 revisions.settings = typeof _wpRevisionsSettings === 'undefined' ? {} : _wpRevisionsSettings; 10 11 // For debugging 12 revisions.debug = true; 13 14 revisions.log = function() { 15 if ( revisions.debug ) 16 console.log.apply( console, arguments ); 17 } 10 18 11 19 // wp_localize_script transforms top-level numbers into strings. Undo that. … … 112 120 113 121 loadNew: function( comparisons ) { 114 comparisons = _.object( comparisons, comparisons ); 115 _.each( comparisons, _.bind( function( id ) { 116 // Exists 117 if ( this.get( id ) ) 118 delete comparisons[ id ]; 119 }, this ) ); 120 comparisons = _.toArray( comparisons ); 121 return this.load( comparisons ); 122 var self = this; 123 _.each( comparisons, function( id, index ) { 124 // Already exists in collection. Don't request it again. 125 if ( self.get( id ) ) 126 delete comparisons[ index ]; 127 }); 128 wp.revisions.log( 'loadNew', comparisons ); 129 130 if ( comparisons.length ) 131 return this.load( comparisons ); 132 else 133 return $.Deferred().resolve().promise(); 122 134 }, 123 135 124 136 load: function( comparisons ) { 137 wp.revisions.log( 'load', comparisons ); 125 138 // Our collection should only ever grow, never shrink, so remove: false 126 139 return this.fetch({ data: { compare: comparisons }, remove: false }); … … 128 141 129 142 loadLast: function( num ) { 130 num = num || 1; 131 var ids = this.getProximalDiffIds(); 132 ids = _.last( ids, num ); 133 134 if ( ids.length ) { 143 var ids; 144 145 num = num || 1; 146 ids = _.last( this.getProximalDiffIds(), num ); 147 148 if ( ids.length ) 135 149 return this.loadNew( ids ); 136 } 150 else 151 return $.Deferred().resolve().promise(); 137 152 }, 138 153 139 154 loadLastUnloaded: function( num ) { 140 num = num || 1; 141 var ids = this.getUnloadedProximalDiffIds(); 142 ids = _.last( ids, num ); 143 144 if ( ids.length ) { 155 var ids; 156 157 num = num || 1; 158 ids = _.last( this.getUnloadedProximalDiffIds(), num ); 159 160 if ( ids.length ) 145 161 return this.loadNew( ids ); 146 } 162 else 163 return $.Deferred().resolve().promise(); 147 164 }, 148 165 … … 236 253 this.listenTo( this, 'change:from', this.changeRevisionHandler ); 237 254 this.listenTo( this, 'change:to', this.changeRevisionHandler ); 255 this.listenTo( this, 'update:revisions', this.loadSurrounding ); 256 this.listenTo( this, 'change:compareTwoMode', this.changedMode ); 238 257 this.updateDiff({ immediate: true }); 258 }, 259 260 changedMode: function() { 261 // This isn't passed from/to so we grab them from the model 262 this.loadSurrounding( this.get( 'from' ), this.get( 'to' ) ); 263 }, 264 265 loadSurrounding: function( from, to ) { 266 // Different strategies for single and compare-two models 267 if ( this.get( 'compareTwoMode' ) ) { 268 // TODO: compare-two loading strategy 269 } else { 270 // TODO: clean this up to hook in to the ensure process 271 if ( this.revisions.length ) { 272 // Load the rest: first 10, then the rest by 50 273 this.diffs.loadLastUnloaded( 10 ).always( _.bind( function() { 274 this.diffs.loadAllBy( 50 ); 275 }, this ) ); 276 } 277 } 239 278 }, 240 279 … … 315 354 model: this.model 316 355 }) ); 317 318 // TODO: The rest of this method should be rewritten and moved into the FrameState.319 if ( this.model.revisions.length ) {320 // Load the rest: first 10, then the rest by 50321 this.model.diffs.loadLastUnloaded( 10 ).always( _.bind( function() {322 this.model.diffs.loadAllBy( 50 );323 }, this ) );324 }325 356 }, 326 357
Note: See TracChangeset
for help on using the changeset viewer.