Changeset 24579
- Timestamp:
- 07/06/2013 08:22:02 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/js/revisions.js
r24578 r24579 237 237 this.listenTo( this.model, 'change:diffId', this.updateDiff ); 238 238 239 this.listenTo( this.model, 'change:compareTwoMode', this.updateCompareTwoMode ); 240 239 241 this.views.set( '.revisions-control-frame', new revisions.view.Controls({ 240 242 model: this.model … … 276 278 this.model.trigger( 'renderDiff' ); 277 279 }); 280 }, 281 282 updateCompareTwoMode: function() { 283 this.$el.toggleClass( 'comparing-two-revisions' ); 278 284 } 279 285 }); … … 337 343 updateMeta: function() { 338 344 this.$el.html( this.template( this.model.toJSON() ) ); 339 if( this.model.get( 'to' ).attributes.current ) { 340 $( '#restore-revision' ).prop( 'disabled', true ); 341 } else { 342 $( '#restore-revision' ).prop( 'disabled', false ); 343 } 345 346 $( '#restore-revision' ).prop( 'disabled', this.model.get( 'to' ).attributes.current ); 344 347 } 345 348 }); … … 376 379 compareTwoToggle: function( event ) { 377 380 // Activate compare two mode? 378 if ( $( '.compare-two-revisions' ).is( ':checked' ) ) { 379 this.model.set( { compareTwoMode: true } ); 380 } else { 381 this.model.set( { compareTwoMode: false } ); 382 } 381 this.model.set( { compareTwoMode: $( '.compare-two-revisions' ).prop( 'checked' ) } ); 383 382 384 383 // Update route … … 546 545 // And update the slider in case the route has set it. 547 546 this.updateSliderSettings(); 548 549 547 this.slide( '', this.settings.attributes ); 550 551 548 this.$el.slider( this.settings.toJSON() ); 552 549 … … 569 566 hoveringAt = Math.floor( actualX / tickWidth ); 570 567 571 // Reverse direction in R tlmode.568 // Reverse direction in RTL mode. 572 569 if ( isRtl ) 573 570 hoveringAt = this.model.revisions.length - hoveringAt - 1; … … 607 604 } 608 605 } else { 609 leftValue = isRtl ? this.model.revisions.length -this.model.revisions.indexOf( this.model.get( 'to' ) ) - 1 :606 leftValue = isRtl ? this.model.revisions.length - this.model.revisions.indexOf( this.model.get( 'to' ) ) - 1 : 610 607 this.model.revisions.indexOf( this.model.get( 'from' ) ), 611 608 rightValue = isRtl ? this.model.revisions.length - this.model.revisions.indexOf( this.model.get( 'from' ) ) - 1 : … … 632 629 } ); 633 630 } 631 634 632 if ( this.model.get( 'compareTwoMode' ) ){ 635 $( '.revisions' ).addClass( 'comparing-two-revisions' );636 637 633 // in RTL mode the 'left handle' is the second in the slider, 'right' is first 638 634 $( 'a.ui-slider-handle', this.$el ) … … 644 640 .addClass( isRtl ? 'left-handle' : 'right-handle' ) 645 641 .removeClass( isRtl ? 'right-handle' : 'left-handle' ); 646 } else {647 $( '.revisions' ).removeClass( 'comparing-two-revisions' );648 642 } 649 643 }, … … 666 660 667 661 start: function( event, ui ) { 668 if ( this.model.get( 'compareTwoMode' ) )669 return;670 671 662 // Track the mouse position to enable smooth dragging, 672 // overrides default jQuery UI step behaviour. 673 $( window ).on( 'mousemove', { slider: this }, function( e ) { 674 var slider = e.data.slider, 675 sliderLeft = slider.$el.offset().left, 676 sliderRight = sliderLeft + slider.$el.width(); 663 // overrides default jQuery UI step behavior. 664 $( window ).on( 'mousemove', { view: this }, function( e ) { 665 var view = e.data.view, 666 leftDragBoundary = view.$el.offset().left, // Initial left boundary 667 sliderOffset = leftDragBoundary, 668 sliderRightEdge = leftDragBoundary + view.$el.width(), 669 rightDragBoundary = sliderRightEdge, // Initial right boundary 670 leftDragReset = 0, // Initial left drag reset 671 rightDragReset = sliderRightEdge - sliderOffset; // Initial right drag reset 672 673 // In two handle mode, ensure handles can't be dragged past each other. 674 // Adjust left/right boundaries and reset points. 675 if ( view.model.get( 'compareTwoMode' ) ) { 676 var rightHandle = $( ui.handle ).parent().find( '.right-handle' ), 677 leftHandle = $( ui.handle ).parent().find( '.left-handle' ); 678 679 if ( $( ui.handle ).hasClass( 'left-handle' ) ) { 680 // Dragging the left handle, boundary is right handle. 681 // RTL mode calculations reverse directions. 682 if ( isRtl ) { 683 leftDragBoundary = rightHandle.offset().left + rightHandle.width(); 684 leftDragReset = leftDragBoundary - sliderOffset; 685 } else { 686 rightDragBoundary = rightHandle.offset().left; 687 rightDragReset = rightDragBoundary - sliderOffset; 688 } 689 } else { 690 // Dragging the right handle, boundary is the left handle. 691 // RTL mode calculations reverse directions. 692 if ( isRtl ) { 693 rightDragBoundary = leftHandle.offset().left; 694 rightDragReset = rightDragBoundary - sliderOffset; 695 } else { 696 leftDragBoundary = leftHandle.offset().left + leftHandle.width() ; 697 leftDragReset = leftDragBoundary - sliderOffset; 698 } 699 } 700 } 677 701 678 702 // Follow mouse movements, as long as handle remains inside slider. 679 if ( e.clientX < sliderLeft) {680 $( ui.handle ).css( 'left', 0); // Mouse to left of slider.681 } else if ( e.clientX > sliderRight) {682 $( ui.handle ).css( 'left', sliderRight - sliderLeft); // Mouse to right of slider.703 if ( e.clientX < leftDragBoundary ) { 704 $( ui.handle ).css( 'left', leftDragReset ); // Mouse to left of slider. 705 } else if ( e.clientX > rightDragBoundary ) { 706 $( ui.handle ).css( 'left', rightDragReset ); // Mouse to right of slider. 683 707 } else { 684 $( ui.handle ).css( 'left', e.clientX - slider Left ); // Mouse in slider.708 $( ui.handle ).css( 'left', e.clientX - sliderOffset ); // Mouse in slider. 685 709 } 686 710 } ); … … 717 741 718 742 stop: function( event, ui ) { 719 if ( this.model.get( 'compareTwoMode' ) )720 return;721 722 743 $( window ).off( 'mousemove' ); 723 744
Note: See TracChangeset
for help on using the changeset viewer.