Ticket #23897: 23897.4.diff
File 23897.4.diff, 12.7 KB (added by , 11 years ago) |
---|
-
wp-admin/includes/ajax-actions.php
2100 2100 $single_revision_id = ! empty( $_GET['single_revision_id'] ) ? absint( $_GET['single_revision_id'] ) : 0; 2101 2101 $compare_two_mode = (bool) $post_id; 2102 2102 2103 //2104 //TODO: currently code returns all possible comparisons for the indicated 'compare_to' revision2105 //however, the front end prevents users from pulling the right handle past the left or the left pass the right,2106 //so only the possible diffs need be generated2107 //2108 2103 $all_the_revisions = array(); 2109 2104 if ( ! $post_id ) 2110 2105 $post_id = $compare_to; … … 2174 2169 2175 2170 $count = -1; 2176 2171 2177 //reverse the list to start with oldes revision2172 //reverse the list to start with oldest revision 2178 2173 $revisions = array_reverse( $revisions ); 2179 2174 2180 2175 $previous_revision_id = 0; … … 2191 2186 $count++; 2192 2187 // return blank data for diffs to the left of the left handle (for right handel model) 2193 2188 // or to the right of the right handle (for left handel model) 2194 if ( ( 0 != $left_handle_at && $count < $left_handle_at ) || 2195 ( 0 != $right_handle_at && $count > ( $right_handle_at - 2 ) ) ) { 2189 /* 2190 2191 if ( ! is_rtl() && ( ( 0 != $left_handle_at && $count < $left_handle_at ) || 2192 ( 0 != $right_handle_at && $count > ( $right_handle_at - 2 ) ) ) ) { 2196 2193 $all_the_revisions[] = array ( 2197 2194 'ID' => $revision->ID, 2198 2195 ); 2199 2196 continue; 2200 2197 } 2201 2198 */ 2202 2199 if ( $compare_two_mode ) { 2203 2200 $compare_to_gravatar = get_avatar( $left_revision->post_author, 24 ); 2204 2201 $compare_to_author = get_the_author_meta( 'display_name', $left_revision->post_author ); … … 2286 2283 2287 2284 endforeach; 2288 2285 2286 if ( is_rtl() && $compare_two_mode ) { 2287 $all_the_revisions = array_reverse( $all_the_revisions ); 2288 } 2289 2289 2290 echo json_encode( $all_the_revisions ); 2290 2291 exit(); 2291 2292 } -
wp-admin/js/revisions.js
165 165 self.tickmarkView.model = self.revisions; 166 166 self.tickmarkView.render(); 167 167 self.slider.refresh({ 168 'max': revisionCount - 1, 169 'value': self.rightDiff - 1 168 'max': revisionCount - 1, // slider starts at 0 in single handle mode 169 'value': self.rightDiff - 1 // slider starts at 0 in single handle mode 170 170 }, true); 171 171 }, 172 172 … … 176 176 }); 177 177 }, 178 178 179 // load the models for the left handle 179 // load the models for the left handle (the right handler has moved) 180 180 reloadLeft: function() { 181 181 var self = this; 182 182 self.startLeftModelLoading(); 183 183 self.leftHandleRevisions = new Revisions( {}, { 184 'compareTo': self.revisions.at( self.rightDiff - 1 ).get( 'ID' ), 184 'compareTo': self.revisions.at( self.rightDiff - 1 ).get( 'ID' ), // diff and model count off by 1 185 185 'showAutosaves': self.autosaves, 186 186 'showSplitView': self.showSplitView, 187 187 'rightHandleAt': self.rightDiff … … 207 207 }); 208 208 }, 209 209 210 // load the models for the right handle 210 // load the models for the right handle (the left handle has moved) 211 211 reloadRight: function() { 212 212 var self = this; 213 213 self.startRightModelLoading(); 214 214 self.rightHandleRevisions = new Revisions( {}, { 215 'compareTo': self.revisions.at( self.leftDiff - 1 ).get( 'ID' ), 215 'compareTo': self.revisions.at( self.leftDiff - 1 ).get( 'ID' ), // diff and model count off by 1 216 216 'showAutosaves': self.autosaves, 217 217 'showSplitView': self.showSplitView, 218 218 'leftHandleAt': self.leftDiff … … 224 224 self.loadDiffs( self.rightHandleRevisions ); 225 225 self.tickmarkView.model = self.rightHandleRevisions; 226 226 self.slider.refresh({ 227 'max': self.revisions.length, 228 'values': [ self.leftDiff, self.rightDiff] 227 'max': self.revisions.length 229 228 }, true); 230 229 }, 231 230 … … 236 235 237 236 }, 238 237 238 /** 239 * reloadLeftRight reload models for both the left and right handles 240 */ 239 241 reloadLeftRight: function() { 240 242 this.startRightModelLoading(); 241 243 this.startLeftModelLoading(); … … 261 263 prev.prop( 'disabled', false ); 262 264 }, 263 265 266 /** 267 * completeApplicationSetup finishes loading all views once the initial model load is complete 268 */ 264 269 completeApplicationSetup: function() { 265 270 this.revisionView = new revisions.view.Diff({ 266 271 model: this.revisions 267 272 }); 268 this.revisionView.render(); 273 this.revisionView.render(); // render the revision view 269 274 270 this.loadDiffs( this.revisions ); 275 this.loadDiffs( this.revisions ); // get the actual revisions data 271 276 272 277 this.revisionsInteractions = new revisions.view.Interact({ 273 278 model: this.revisions 274 279 }); 275 this.revisionsInteractions.render(); 280 this.revisionsInteractions.render(); //render the interaction view 276 281 277 282 this.tickmarkView = new revisions.view.Tickmarks({ 278 283 model: this.revisions 279 284 }); 280 this.tickmarkView.render(); 285 this.tickmarkView.render(); //render the tickmark view 281 286 this.tickmarkView.resetTicks(); 282 287 } 283 288 }); … … 307 312 }); 308 313 }, 309 314 315 /** 316 * respond to slider slide events 317 * Note: in one handle mode, jQuery UI reports leftmost position as 0 318 * in two handle mode, jQuery UI Slider reports leftmost position as 1 319 */ 310 320 slide: function( event, ui ) { 311 321 if ( this.singleRevision ) { 312 322 Diff.rightDiff = ( ui.value + 1 ); … … 321 331 if ( Diff.leftModelLoading ) // left model still loading, prevent sliding left handle 322 332 return false; 323 333 324 Diff.leftDiff = ui.values[0];334 Diff.leftDiff = isRtl ? ui.values[1] : ui.values[0]; 325 335 } else { 326 336 // Right handler 327 337 if ( Diff.rightModelLoading ) // right model still loading, prevent sliding right handle 328 338 return false; 329 339 330 Diff.rightDiff = ui.values[1];340 Diff.rightDiff = isRtl ? ui.values[0] : ui.values[1]; 331 341 } 332 342 333 343 if ( 0 === Diff.leftDiff ) { … … 340 350 } 341 351 }, 342 352 353 /** 354 * responds to slider start sliding events 355 * in two handle mode stores start position, so if unchanged at stop event no need to reload diffs 356 * also swaps in the appropriate models - left handled or right handled 357 */ 343 358 start: function( event, ui ) { 344 359 // Not needed in one mode 345 360 if ( this.singleRevision ) … … 354 369 355 370 if ( Diff.revisionView.model !== Diff.leftHandleRevisions && 356 371 null !== Diff.leftHandleRevisions ) { 357 Diff.revisionView.model = Diff.leftHandleRevisions; 372 Diff.revisionView.model = Diff.leftHandleRevisions; //use the left handle models 358 373 Diff.tickmarkView.model = Diff.leftHandleRevisions; 359 374 Diff.tickmarkView.render(); 360 375 } 361 376 362 Diff.leftDiffStart = ui.values[ 0 ];377 Diff.leftDiffStart = isRtl ? ui.values[1] : ui.values[0]; // in RTL mode the 'left handle' is the second in the slider, 'right' is first 363 378 364 379 } else { 365 380 // Right handler … … 368 383 369 384 if ( Diff.revisionView.model !== Diff.rightHandleRevisions && 370 385 null !== Diff.rightHandleRevisions ) { 371 Diff.revisionView.model = Diff.rightHandleRevisions; 386 Diff.revisionView.model = Diff.rightHandleRevisions; //use the right handle models 372 387 Diff.tickmarkView.model = Diff.rightHandleRevisions; 373 388 Diff.tickmarkView.render(); 374 389 } 375 390 376 391 Diff.revisionView.draggingLeft = false; 377 Diff.rightDiffStart = ui.values[1];392 Diff.rightDiffStart = isRtl ? ui.values[0] : ui.values[1]; // in RTL mode the 'left handle' is the second in the slider, 'right' is first 378 393 } 379 394 }, 380 395 396 /** 397 * responds to slider stop events 398 * in two handled mode, if the handle that stopped has moved, reload the diffs for the other handle 399 * the other handle compares to this handle's position, so if it changes they need to be recalculated 400 */ 381 401 stop: function( event, ui ) { 382 402 // Not needed in one mode 383 403 if ( this.singleRevision ) … … 386 406 // calculate and generate a diff for comparing to the left handle 387 407 // and the right handle, swap out when dragging 388 408 if ( $( ui.handle ).hasClass( 'left-handle' ) ) { 389 // Left ha dnler390 if ( Diff.leftDiffStart !== ui.values[0] )409 // Left handler 410 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 391 411 Diff.reloadRight(); 392 412 } else { 393 413 // Right handler 394 if ( Diff.rightDiffStart !== ui.values[1] )414 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 395 415 Diff.reloadLeft(); 396 416 } 397 417 }, … … 449 469 $( '#diff-slider' ).slider( { 450 470 slide: $.proxy( self.slide, self ), 451 471 start: $.proxy( self.start, self ), 452 stop: $.proxy( self.stop, self )472 stop: $.proxy( self.stop, self ) 453 473 } ); 454 474 455 475 // Set options … … 540 560 541 561 if ( Diff.singleRevision ) { 542 562 Diff.slider.refresh({ 543 value: Diff.rightDiff - 1, 563 value: Diff.rightDiff - 1, //rightDiff value is off model index by 1 544 564 min: 0, 545 565 max: modelcount - 1 546 566 }); … … 549 569 550 570 } else { 551 571 Diff.slider.refresh({ 552 values: [ Diff.leftDiff, Diff.rightDiff + 1 ], 572 // in RTL mode the 'left handle' is the second in the slider, 'right' is first 573 values: [ isRtl ? Diff.rightDiff : Diff.leftDiff, isRtl ? Diff.leftDiff : Diff.rightDiff ], 553 574 min: 1, 554 575 max: modelcount + 1, 555 576 range: true 556 577 }); 557 578 558 579 $( '#revision-diff-container' ).addClass( 'comparing-two-revisions' ); 559 $( '#diff-slider a.ui-slider-handle' ).first().addClass( 'left-handle' ); 560 $( '#diff-slider a.ui-slider-handle' ).last().addClass( 'right-handle' ); 580 // in RTL mode the 'left handle' is the second in the slider, 'right' is first 581 $( '#diff-slider a.ui-slider-handle' ).first().addClass( isRtl ? 'right-handle' : 'left-handle' ); 582 $( '#diff-slider a.ui-slider-handle' ).last().addClass( isRtl ? 'left-handle' : 'right-handle' ); 561 583 562 584 } 563 585 … … 613 635 // compare two revisions mode? 614 636 if ( ! Diff.singleRevision ) { 615 637 if ( this.draggingLeft ) { 616 thediff = Diff.leftDiff - 1; 638 thediff = Diff.leftDiff - 1; //leftDiff value is off model index by 1 617 639 if ( this.model.at( thediff ) ) { 618 640 addHtml = this.template( this.model.at( thediff ).toJSON() ); 619 641 } 620 642 } else { // dragging right handle 621 thediff = Diff.rightDiff - 1;643 thediff = Diff.rightDiff - 1; //rightDiff value is off model index by 1 622 644 if ( this.model.at( thediff ) ) { 623 645 addHtml = this.template( this.model.at( thediff ).toJSON() ); 624 646 } 625 647 } 626 648 } else { // end compare two revisions mode, eg only one slider handle 627 if ( this.model.at( Diff.rightDiff - 1 ) ) { 649 if ( this.model.at( Diff.rightDiff - 1 ) ) { //rightDiff value is off model index by 1 628 650 addHtml = this.template( this.model.at( Diff.rightDiff - 1 ).toJSON() ); 629 651 } 630 652 } … … 667 689 if ( $( '#compare-two-revisions' ).is( ':checked' ) ) { // compare 2 mode 668 690 Diff.singleRevision = false ; 669 691 670 if ( 1 === Diff.rightDiff ) 671 Diff.rightDiff = 2; 692 // in RTL mode handles are swapped, so boundary checks are different; 693 if ( isRtl ){ 694 Diff.leftDiff = Diff.revisions.length; //put the left handle at the rightmost position, representing current revision 672 695 696 if ( Diff.revisions.length === Diff.rightDiff ) //make sure 'left' handle not in rightmost slot 697 Diff.rightDiff = Diff.rightDiff - 1; 698 } else { 699 if ( 1 === Diff.rightDiff ) //make sure right handle not in leftmost slot 700 Diff.rightDiff = 2; 701 } 702 673 703 Diff.revisionView.draggingLeft = false; 674 704 675 705 revisions.model.settings.revision_id = ''; // reset passed revision id so switching back to one handle mode doesn't re-select revision 676 Diff.reloadLeftRight(); 706 Diff.reloadLeftRight(); // load diffs for left and right handles 677 707 Diff.revisionView.model = Diff.rightHandleRevisions; 678 708 679 709 } else { // compare one mode … … 756 786 url: function() { 757 787 return ajaxurl + 758 788 '?action=revisions-data' + 759 '&compare_to=' + this.options.compareTo + 760 '&post_id=' + this.options.post_id + 761 '&show_autosaves=' + this.options.showAutosaves + 762 '&show_split_view=' + this.options.showSplitView + 763 '&right_handle_at=' + this.options.rightHandleAt + 764 '&left_handle_at=' + this.options.leftHandleAt + 789 '&compare_to=' + this.options.compareTo + // revision are we comparing to 790 '&post_id=' + this.options.post_id + // the post id 791 '&show_autosaves=' + this.options.showAutosaves + // show or hide autosaves 792 '&show_split_view=' + this.options.showSplitView + // show in split view or single column view 793 '&right_handle_at=' + this.options.rightHandleAt + // mark point for comparison list 794 '&left_handle_at=' + this.options.leftHandleAt + // mark point for comparison list 765 795 '&nonce=' + this.options.nonce; 766 796 }, 767 797