Ticket #24346: 24346.2.diff
File 24346.2.diff, 6.7 KB (added by , 11 years ago) |
---|
-
wp-admin/includes/ajax-actions.php
2208 2208 if ( ( ( 0 != $left_handle_at && $count < $left_handle_at ) || 2209 2209 ( 0 != $right_handle_at && $count > ( $right_handle_at - 2 ) ) ) ) { 2210 2210 $all_the_revisions[] = array ( 2211 'ID' => $revision->ID, 2211 'ID' => $revision->ID, 2212 'completed' => true, //mark as completed, no need to load diff 2212 2213 ); 2213 2214 continue; 2214 2215 } … … 2216 2217 if ( ( 0 != $left_handle_at && $count > ( $left_handle_at - 1 ) || 2217 2218 ( 0 != $left_handle_at && $count < $right_handle_at ) ) ) { 2218 2219 $all_the_revisions[] = array ( 2219 'ID' => $revision->ID, 2220 'ID' => $revision->ID, 2221 'completed' => true, //mark as completed, no need to load diff 2220 2222 ); 2221 2223 continue; 2222 2224 } -
wp-admin/js/revisions.js
56 56 } 57 57 }, 58 58 59 loadDiffs: function( models ) {59 loadDiffs: function( models, otherModels ) { 60 60 var self = this, 61 61 revisionsToLoad = models.where( { completed: false } ), 62 62 delay = 0, 63 totalChanges; 63 totalChanges, 64 foundModel; 64 65 66 // in two handle mode, pass the other handle's models and copy over scopeOfChanges (tick width) from that model for positions this handle can't reach (but the other handle can reach) 67 if ( 'undefined' !== typeof otherModels ) { // otherModels only passed in two handle mode 68 _.each( models.where( { completed: true } ), // select just the models that are marked as not needing loading, eg. positions this handle can't reach 69 function( theModel ) { 70 foundModel = otherModels.findWhere( { ID: theModel.id } ); //find the matching position from the other handle's models 71 if ( 'undefined' !== typeof foundModel ) { 72 theModel.set( 'scopeOfChanges', // set the displayed scope of changes for ticks this handle can't get to 73 foundModel 74 .get( 'scopeOfChanges' ) ); // copy the scope of changes from the other handle which can reach this spot 75 } 76 } 77 ); 78 } 79 65 80 // match slider to passed revision_id 66 81 _.each( revisionsToLoad, function( revision ) { 67 82 if ( revision.get( 'ID' ) == revisions.model.settings.revision_id ) … … 69 84 }); 70 85 71 86 _.each( revisionsToLoad, function( revision ) { 72 _.delay( function() { 73 revision.fetch( { 74 update: true, 75 add: false, 76 remove: false, 77 success: function( model ) { 78 model.set( 'completed', true ); 87 revision.fetch( { 88 update: true, 89 add: false, 90 remove: false, 91 success: function( model ) { 92 model.set( 'completed', true ); 79 93 80 81 82 94 // stop spinner when all models are loaded 95 if ( 0 === models.where( { completed: false } ).length ) 96 self.stopModelLoadingSpinner(); 83 97 84 85 98 totalChanges = model.get( 'linesAdded' ) + model.get( 'linesDeleted' ), 99 scopeOfChanges = 'vsmall'; 86 100 87 // Note: hard coded scope of changes 88 // TODO change to dynamic based on range of values 89 if ( totalChanges > 1 && totalChanges <= 3 ) { 90 scopeOfChanges = 'small'; 91 } else if ( totalChanges > 3 && totalChanges <= 5 ) { 92 scopeOfChanges = 'med'; 93 } else if ( totalChanges > 5 && totalChanges <= 10 ) { 94 scopeOfChanges = 'large'; 95 } else if ( totalChanges > 10 ) { 96 scopeOfChanges = 'vlarge'; 97 } 98 model.set( 'scopeOfChanges', scopeOfChanges ); 99 if ( 0 !== self.rightDiff && 100 model.get( 'ID' ) === self.revisions.at( self.rightDiff - 1 ).get( 'ID' ) ) { 101 // reload if current model refreshed 102 self.revisionView.render(); 103 } 104 self.tickmarkView.render(); 105 } 106 } ); 107 }, delay ) ; 108 delay = delay + 150; // stagger model loads to avoid hammering server with requests 109 } 110 ); 101 // Note: hard coded scope of changes 102 // TODO change to dynamic based on range of values 103 if ( totalChanges > 1 && totalChanges <= 3 ) { 104 scopeOfChanges = 'small'; 105 } else if ( totalChanges > 3 && totalChanges <= 5 ) { 106 scopeOfChanges = 'med'; 107 } else if ( totalChanges > 5 && totalChanges <= 10 ) { 108 scopeOfChanges = 'large'; 109 } else if ( totalChanges > 10 ) { 110 scopeOfChanges = 'vlarge'; 111 } 112 model.set( 'scopeOfChanges', scopeOfChanges ); 113 if ( 0 !== self.rightDiff && 114 model.get( 'ID' ) === self.revisions.at( self.rightDiff - 1 ).get( 'ID' ) ) { 115 // reload if current model refreshed 116 self.revisionView.render(); 117 } 118 self.tickmarkView.render(); 119 } 120 } ); 121 } ); 111 122 }, 112 123 113 124 startLeftModelLoading: function() { … … 186 197 self.leftHandleRevisions.fetch({ 187 198 success: function(){ 188 199 self.stopLeftModelLoading(); 189 self.loadDiffs( self.leftHandleRevisions );200 self.loadDiffs( self.leftHandleRevisions, self.rightHandleRevisions ); 190 201 self.tickmarkView.model = self.leftHandleRevisions; 191 202 self.slider.refresh({ 192 203 'max': self.revisions.length … … 216 227 self.rightHandleRevisions.fetch({ 217 228 success: function(){ 218 229 self.stopRightModelLoading(); 219 self.loadDiffs( self.rightHandleRevisions );230 self.loadDiffs( self.rightHandleRevisions, self.leftHandleRevisions ); 220 231 self.tickmarkView.model = self.rightHandleRevisions; 221 232 self.slider.refresh({ 222 233 'max': self.revisions.length … … 395 406 // and the right handle, swap out when dragging 396 407 if ( $( ui.handle ).hasClass( 'left-handle' ) ) { 397 408 // Left handler 398 if ( Diff.leftDiffStart !== isRtl ? ui.values[1] : ui.values[0]) // in RTL mode the 'left handle' is the second in the slider, 'right' is first409 if ( Diff.leftDiffStart !== ( isRtl ? ui.values[1] : ui.values[0] ) ) // in RTL mode the 'left handle' is the second in the slider, 'right' is first 399 410 Diff.reloadRight(); 400 411 } else { 401 412 // Right handler 402 if ( Diff.rightDiffStart !== isRtl ? ui.values[0] : ui.values[1]) // in RTL mode the 'left handle' is the second in the slider, 'right' is first413 if ( Diff.rightDiffStart !== ( isRtl ? ui.values[0] : ui.values[1] ) ) // in RTL mode the 'left handle' is the second in the slider, 'right' is first 403 414 Diff.reloadLeft(); 404 415 } 405 416 },