Ticket #23897: 23897.7.diff
File 23897.7.diff, 13.1 KB (added by , 11 years ago) |
---|
-
wp-admin/includes/ajax-actions.php
2119 2119 $single_revision_id = ! empty( $_GET['single_revision_id'] ) ? absint( $_GET['single_revision_id'] ) : 0; 2120 2120 $compare_two_mode = (bool) $post_id; 2121 2121 2122 //2123 //TODO: currently code returns all possible comparisons for the indicated 'compare_to' revision2124 //however, the front end prevents users from pulling the right handle past the left or the left pass the right,2125 //so only the possible diffs need be generated2126 //2127 2122 $all_the_revisions = array(); 2128 2123 if ( ! $post_id ) 2129 2124 $post_id = $compare_to; … … 2193 2188 2194 2189 $count = -1; 2195 2190 2196 //reverse the list to start with oldes revision2191 //reverse the list to start with oldest revision 2197 2192 $revisions = array_reverse( $revisions ); 2198 2193 2199 2194 $previous_revision_id = 0; … … 2208 2203 $revision_from_date_author = ''; 2209 2204 $is_current_revision = false; 2210 2205 $count++; 2211 // return blank data for diffs to the left of the left handle (for right handel model) 2212 // or to the right of the right handle (for left handel model) 2213 if ( ( 0 != $left_handle_at && $count < $left_handle_at ) || 2214 ( 0 != $right_handle_at && $count > ( $right_handle_at - 2 ) ) ) { 2215 $all_the_revisions[] = array ( 2216 'ID' => $revision->ID, 2217 ); 2218 continue; 2206 2207 /** 2208 * return blank data for diffs to the left of the left handle (for right handel model) 2209 * or to the right of the right handle (for left handel model) 2210 * and visa versa in RTL mode 2211 */ 2212 if( ! is_rtl() ) { 2213 if ( ( ( 0 != $left_handle_at && $count < $left_handle_at ) || 2214 ( 0 != $right_handle_at && $count > ( $right_handle_at - 2 ) ) ) ) { 2215 $all_the_revisions[] = array ( 2216 'ID' => $revision->ID, 2217 ); 2218 continue; 2219 } 2220 } else { // is_rtl 2221 2222 if ( ( 0 != $left_handle_at && $count > ( $left_handle_at - 1 ) || 2223 ( 0 != $left_handle_at && $count < $right_handle_at ) ) ) { 2224 $all_the_revisions[] = array ( 2225 'ID' => $revision->ID, 2226 ); 2227 continue; 2228 } 2229 2219 2230 } 2220 2231 2221 2232 if ( $compare_two_mode ) { … … 2307 2318 2308 2319 endforeach; 2309 2320 2321 if ( is_rtl() && $compare_two_mode ) { 2322 $all_the_revisions = array_reverse( $all_the_revisions ); 2323 } 2324 2310 2325 echo json_encode( $all_the_revisions ); 2311 2326 exit(); 2312 2327 } -
wp-admin/js/revisions.js
161 161 self.tickmarkView.model = self.revisions; 162 162 self.tickmarkView.render(); 163 163 self.slider.refresh({ 164 'max': revisionCount - 1, 165 'value': self.rightDiff - 1 164 'max': revisionCount - 1, // slider starts at 0 in single handle mode 165 'value': self.rightDiff - 1 // slider starts at 0 in single handle mode 166 166 }, true); 167 167 }, 168 168 … … 172 172 }); 173 173 }, 174 174 175 // load the models for the left handle 175 // load the models for the left handle (the right handler has moved) 176 176 reloadLeft: function() { 177 177 var self = this; 178 178 self.startLeftModelLoading(); 179 179 self.leftHandleRevisions = new Revisions( {}, { 180 'compareTo': self.revisions.at( self.rightDiff - 1 ).get( 'ID' ), 180 'compareTo': self.revisions.at( self.rightDiff - 1 ).get( 'ID' ), // diff and model count off by 1 181 181 'showAutosaves': self.autosaves, 182 182 'showSplitView': self.showSplitView, 183 183 'rightHandleAt': self.rightDiff … … 202 202 }); 203 203 }, 204 204 205 // load the models for the right handle 205 // load the models for the right handle (the left handle has moved) 206 206 reloadRight: function() { 207 207 var self = this; 208 208 self.startRightModelLoading(); 209 209 self.rightHandleRevisions = new Revisions( {}, { 210 'compareTo': self.revisions.at( self.leftDiff - 1 ).get( 'ID' ), 210 'compareTo': self.revisions.at( self.leftDiff - 1 ).get( 'ID' ), // diff and model count off by 1 211 211 'showAutosaves': self.autosaves, 212 212 'showSplitView': self.showSplitView, 213 213 'leftHandleAt': self.leftDiff … … 219 219 self.loadDiffs( self.rightHandleRevisions ); 220 220 self.tickmarkView.model = self.rightHandleRevisions; 221 221 self.slider.refresh({ 222 'max': self.revisions.length, 223 'values': [ self.leftDiff, self.rightDiff] 222 'max': self.revisions.length 224 223 }, true); 225 224 }, 226 225 … … 231 230 232 231 }, 233 232 233 /** 234 * reloadLeftRight reload models for both the left and right handles 235 */ 234 236 reloadLeftRight: function() { 235 237 this.startRightModelLoading(); 236 238 this.startLeftModelLoading(); … … 256 258 prev.prop( 'disabled', false ); 257 259 }, 258 260 261 /** 262 * completeApplicationSetup finishes loading all views once the initial model load is complete 263 */ 259 264 completeApplicationSetup: function() { 260 265 this.revisionView = new revisions.view.Diff({ 261 266 model: this.revisions 262 267 }); 263 this.revisionView.render(); 268 this.revisionView.render(); // render the revision view 264 269 265 this.loadDiffs( this.revisions ); 270 this.loadDiffs( this.revisions ); // get the actual revisions data 266 271 267 272 this.revisionsInteractions = new revisions.view.Interact({ 268 273 model: this.revisions 269 274 }); 270 this.revisionsInteractions.render(); 275 this.revisionsInteractions.render(); //render the interaction view 271 276 272 277 this.tickmarkView = new revisions.view.Tickmarks({ 273 278 model: this.revisions 274 279 }); 275 this.tickmarkView.render(); 280 this.tickmarkView.render(); //render the tickmark view 276 281 } 277 282 }); 278 283 … … 301 306 }); 302 307 }, 303 308 309 /** 310 * respond to slider slide events 311 * Note: in one handle mode, jQuery UI reports leftmost position as 0 312 * in two handle mode, jQuery UI Slider reports leftmost position as 1 313 */ 304 314 slide: function( event, ui ) { 305 315 if ( this.singleRevision ) { 306 316 Diff.rightDiff = ( ui.value + 1 ); … … 315 325 if ( Diff.leftModelLoading ) // left model still loading, prevent sliding left handle 316 326 return false; 317 327 318 Diff.leftDiff = ui.values[0];328 Diff.leftDiff = isRtl ? ui.values[1] : ui.values[0]; 319 329 } else { 320 330 // Right handler 321 331 if ( Diff.rightModelLoading ) // right model still loading, prevent sliding right handle 322 332 return false; 323 333 324 Diff.rightDiff = ui.values[1];334 Diff.rightDiff = isRtl ? ui.values[0] : ui.values[1]; 325 335 } 326 336 327 337 Diff.revisionView.render(); 328 338 } 329 339 }, 330 340 341 /** 342 * responds to slider start sliding events 343 * in two handle mode stores start position, so if unchanged at stop event no need to reload diffs 344 * also swaps in the appropriate models - left handled or right handled 345 */ 331 346 start: function( event, ui ) { 332 347 // Not needed in one mode 333 348 if ( this.singleRevision ) … … 342 357 343 358 if ( Diff.revisionView.model !== Diff.leftHandleRevisions && 344 359 null !== Diff.leftHandleRevisions ) { 345 Diff.revisionView.model = Diff.leftHandleRevisions; 360 Diff.revisionView.model = Diff.leftHandleRevisions; //use the left handle models 346 361 Diff.tickmarkView.model = Diff.leftHandleRevisions; 347 362 Diff.tickmarkView.render(); 348 363 } 349 364 350 Diff.leftDiffStart = ui.values[ 0 ];365 Diff.leftDiffStart = isRtl ? ui.values[1] : ui.values[0]; // in RTL mode the 'left handle' is the second in the slider, 'right' is first 351 366 352 367 } else { 353 368 // Right handler … … 356 371 357 372 if ( Diff.revisionView.model !== Diff.rightHandleRevisions && 358 373 null !== Diff.rightHandleRevisions ) { 359 Diff.revisionView.model = Diff.rightHandleRevisions; 374 Diff.revisionView.model = Diff.rightHandleRevisions; //use the right handle models 360 375 Diff.tickmarkView.model = Diff.rightHandleRevisions; 361 376 Diff.tickmarkView.render(); 362 377 } 363 378 364 379 Diff.revisionView.draggingLeft = false; 365 Diff.rightDiffStart = ui.values[1];380 Diff.rightDiffStart = isRtl ? ui.values[0] : ui.values[1]; // in RTL mode the 'left handle' is the second in the slider, 'right' is first 366 381 } 367 382 }, 368 383 384 /** 385 * responds to slider stop events 386 * in two handled mode, if the handle that stopped has moved, reload the diffs for the other handle 387 * the other handle compares to this handle's position, so if it changes they need to be recalculated 388 */ 369 389 stop: function( event, ui ) { 370 390 // Not needed in one mode 371 391 if ( this.singleRevision ) … … 374 394 // calculate and generate a diff for comparing to the left handle 375 395 // and the right handle, swap out when dragging 376 396 if ( $( ui.handle ).hasClass( 'left-handle' ) ) { 377 // Left ha dnler378 if ( Diff.leftDiffStart !== ui.values[0] )397 // 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 first 379 399 Diff.reloadRight(); 380 400 } else { 381 401 // Right handler 382 if ( Diff.rightDiffStart !== ui.values[1] )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 first 383 403 Diff.reloadLeft(); 384 404 } 385 405 }, … … 416 436 $( '#diff-slider' ).slider( { 417 437 slide: $.proxy( self.slide, self ), 418 438 start: $.proxy( self.start, self ), 419 stop: $.proxy( self.stop, self )439 stop: $.proxy( self.stop, self ) 420 440 } ); 421 441 422 442 // Set options … … 554 574 555 575 if ( Diff.singleRevision ) { 556 576 Diff.slider.refresh({ 557 value: Diff.rightDiff - 1, 577 value: Diff.rightDiff - 1, //rightDiff value is off model index by 1 558 578 min: 0, 559 579 max: modelcount - 1 560 580 }); … … 563 583 564 584 } else { 565 585 Diff.slider.refresh({ 566 values: [ Diff.leftDiff, Diff.rightDiff + 1 ], 586 // in RTL mode the 'left handle' is the second in the slider, 'right' is first 587 values: [ isRtl ? Diff.rightDiff : Diff.leftDiff, isRtl ? Diff.leftDiff : Diff.rightDiff ], 567 588 min: 1, 568 589 max: modelcount + 1, 569 590 range: true 570 591 }); 571 592 572 593 $( '#revision-diff-container' ).addClass( 'comparing-two-revisions' ); 573 $( '#diff-slider a.ui-slider-handle' ).first().addClass( 'left-handle' ); 574 $( '#diff-slider a.ui-slider-handle' ).last().addClass( 'right-handle' ); 594 // in RTL mode the 'left handle' is the second in the slider, 'right' is first 595 $( '#diff-slider a.ui-slider-handle' ).first().addClass( isRtl ? 'right-handle' : 'left-handle' ); 596 $( '#diff-slider a.ui-slider-handle' ).last().addClass( isRtl ? 'left-handle' : 'right-handle' ); 575 597 576 598 } 577 599 … … 626 648 // compare two revisions mode? 627 649 if ( ! Diff.singleRevision ) { 628 650 if ( this.draggingLeft ) { 629 thediff = Diff.leftDiff - 1; 651 thediff = Diff.leftDiff - 1; //leftDiff value is off model index by 1 630 652 if ( this.model.at( thediff ) ) { 631 653 addHtml = this.template( this.model.at( thediff ).toJSON() ); 632 654 } 633 655 } else { // dragging right handle 634 thediff = Diff.rightDiff - 1;656 thediff = Diff.rightDiff - 1; //rightDiff value is off model index by 1 635 657 if ( this.model.at( thediff ) ) { 636 658 addHtml = this.template( this.model.at( thediff ).toJSON() ); 637 659 } 638 660 } 639 661 } else { // end compare two revisions mode, eg only one slider handle 640 if ( this.model.at( Diff.rightDiff - 1 ) ) { 662 if ( this.model.at( Diff.rightDiff - 1 ) ) { //rightDiff value is off model index by 1 641 663 addHtml = this.template( this.model.at( Diff.rightDiff - 1 ).toJSON() ); 642 664 } 643 665 } … … 669 691 if ( $( '#compare-two-revisions' ).is( ':checked' ) ) { // compare 2 mode 670 692 Diff.singleRevision = false ; 671 693 672 if ( 1 === Diff.rightDiff ) 673 Diff.rightDiff = 2; 694 // in RTL mode handles are swapped, so boundary checks are different; 695 if ( isRtl ){ 696 Diff.leftDiff = Diff.revisions.length; //put the left handle at the rightmost position, representing current revision 674 697 698 if ( Diff.revisions.length === Diff.rightDiff ) //make sure 'left' handle not in rightmost slot 699 Diff.rightDiff = Diff.rightDiff - 1; 700 } else { 701 if ( 1 === Diff.rightDiff ) //make sure right handle not in leftmost slot 702 Diff.rightDiff = 2; 703 } 704 675 705 Diff.revisionView.draggingLeft = false; 676 706 677 707 revisions.model.settings.revision_id = ''; // reset passed revision id so switching back to one handle mode doesn't re-select revision 678 Diff.reloadLeftRight(); 708 Diff.reloadLeftRight(); // load diffs for left and right handles 679 709 Diff.revisionView.model = Diff.rightHandleRevisions; 680 710 681 711 } else { // compare one mode … … 758 788 url: function() { 759 789 return ajaxurl + 760 790 '?action=revisions-data' + 761 '&compare_to=' + this.options.compareTo + 762 '&post_id=' + this.options.post_id + 763 '&show_autosaves=' + this.options.showAutosaves + 764 '&show_split_view=' + this.options.showSplitView + 765 '&right_handle_at=' + this.options.rightHandleAt + 766 '&left_handle_at=' + this.options.leftHandleAt + 791 '&compare_to=' + this.options.compareTo + // revision are we comparing to 792 '&post_id=' + this.options.post_id + // the post id 793 '&show_autosaves=' + this.options.showAutosaves + // show or hide autosaves 794 '&show_split_view=' + this.options.showSplitView + // show in split view or single column view 795 '&right_handle_at=' + this.options.rightHandleAt + // mark point for comparison list 796 '&left_handle_at=' + this.options.leftHandleAt + // mark point for comparison list 767 797 '&nonce=' + this.options.nonce; 768 798 }, 769 799