Ticket #24425: 24425.draft.34.diff
File 24425.draft.34.diff, 8.6 KB (added by , 12 years ago) |
---|
-
wp-admin/css/wp-admin.css
3778 3778 padding: 4px 4px; 3779 3779 } 3780 3780 3781 .revisions-tooltip {3782 display: none;3783 }3784 3785 3781 .arrow { 3786 3782 width: 70px; 3787 3783 height: 16px; -
wp-admin/js/revisions.js
23 23 } 24 24 }); 25 25 26 revisions.model.Tooltip = Backbone.Model.extend({ 27 defaults: { 28 revision: null, 29 position: 0 30 } 31 }); 32 26 33 revisions.model.Revision = Backbone.Model.extend({}); 27 34 28 35 revisions.model.Revisions = Backbone.Collection.extend({ … … 289 296 })); 290 297 291 298 // Add the tooltip view 292 this.views.add( new revisions.view.Tooltip({ 293 model: this.model 294 })); 295 // Add the Slider view 299 var tooltip = new revisions.view.Tooltip({ 300 model: new revisions.model.Tooltip() 301 }); 302 this.views.add( tooltip ); 303 304 // Add the Slider view with a reference to the tooltip view 296 305 this.views.add( new revisions.view.Slider({ 297 model: this.model 306 model: this.model, 307 tooltip: tooltip 298 308 }) ); 299 309 300 310 // Add the Meta view … … 394 404 template: wp.template( 'revisions-tooltip' ), 395 405 396 406 initialize: function() { 397 this.listenTo( this.model, 'change:sliderHovering', this.sliderHoveringChanged ); 398 this.listenTo( this.model, 'change:tooltipPosition', this.tooltipPositionChanged ); 407 this.listenTo( this.model, 'change', this.render ); 399 408 }, 400 409 401 410 ready: function() { 411 // Hide tooltip on start. 412 this.$el.addClass( 'hidden' ); 402 413 }, 403 414 404 // Show or hide tooltip based on sliderHovering is true 405 sliderHoveringChanged: function() { 406 if ( this.model.get( 'sliderHovering' ) ) { 407 this.$el.show(); 408 } else { 409 this.$el.hide(); 410 } 415 show: function() { 416 this.$el.removeClass( 'hidden' ); 411 417 }, 412 418 413 tooltipPositionChanged: function() { 414 this.$el.html( this.template( this.model.revisions.at( this.model.get( 'hoveringAt') ).toJSON() ) ); 415 416 this.setTooltip( this.model.get( 'tooltipPosition' ) ); 419 hide: function() { 420 this.$el.addClass( 'hidden' ); 417 421 }, 418 422 419 setTooltip: function( tooltipPosition ) { 423 render: function() { 424 // Check if a revision exists. 425 if ( null === this.model.get( 'revision' ) ) 426 return; 427 428 this.$el.html( this.template( this.model.get( 'revision' ).toJSON() ) ); 429 420 430 var offset = $( '.revisions-buttons' ).offset().left, 421 calculatedX = t ooltipPosition- offset;431 calculatedX = this.model.get( 'position' ) - offset; 422 432 423 424 this.$el.find( '.ui-slider-tooltip' ).css( 'left', calculatedX ); 425 this.$el.find( '.arrow' ).css( 'left', calculatedX ); 433 $( '.ui-slider-tooltip', this.$el ).css( 'left', calculatedX ); 434 $( '.arrow', this.$el ).css( 'left', calculatedX ); 426 435 } 427 436 }); 428 437 … … 486 495 val = this.model.revisions.indexOf( this.model.get( 'to' ) ); 487 496 488 497 // Disable "Next" button if you're on the last node. 489 if ( maxVal === val ) 490 next.prop( 'disabled', true ); 491 else 492 next.prop( 'disabled', false ); 498 next.prop( 'disabled', ( maxVal === val ) ); 493 499 494 500 // Disable "Previous" button if you're on the first node. 495 if ( minVal === val ) 496 previous.prop( 'disabled', true ); 497 else 498 previous.prop( 'disabled', false ); 501 previous.prop( 'disabled', ( minVal === val ) ); 499 502 } 500 503 }); 501 504 … … 512 515 'mouseleave' : 'mouseleave' 513 516 }, 514 517 515 initialize: function( ) {518 initialize: function( options ) { 516 519 _.bindAll( this, 'start', 'slide', 'stop' ); 517 520 521 this.tooltip = options.tooltip; 522 518 523 // Create the slider model from the provided collection data. 519 524 var latestRevisionIndex = this.model.revisions.length - 1; 520 525 521 526 // Find the initially selected revision 522 527 var initiallySelectedRevisionIndex = 523 528 this.model.revisions.indexOf( 524 this.model.revisions.findWhere( 529 this.model.revisions.findWhere( { id: Number( revisions.settings.selectedRevision ) } ) ); 525 530 526 531 this.settings = new revisions.model.Slider({ 527 532 max: latestRevisionIndex, … … 533 538 }, 534 539 535 540 ready: function() { 541 // Refresh the currently selected revision position in case router has set it. 542 this.settings.attributes.value = this.model.revisions.indexOf( 543 this.model.revisions.findWhere( { id: Number( revisions.settings.selectedRevision ) } ) ); 544 545 this.slide( '', this.settings.attributes ); 546 536 547 this.$el.slider( this.settings.toJSON() ); 537 548 538 549 // Listen for changes in Compare Two Mode setting 539 550 this.listenTo( this.model, 'change:compareTwoMode', this.updateSliderSettings ); 540 551 541 this.settings.on( 'change', function( model, options) {552 this.settings.on( 'change', function() { 542 553 this.updateSliderSettings(); 543 554 }, this ); 544 555 545 556 // Listen for changes in the diffId 546 557 this.listenTo( this.model, 'change:diffId', this.diffIdChanged ); 547 558 548 // Reset to the initially selected revision549 this.slide( '', this.settings.attributes );550 551 559 }, 552 560 553 561 mousemove: function( e ) { … … 557 565 actualX = e.clientX - sliderLeft, 558 566 hoveringAt = Math.floor( actualX / tickWidth ); 559 567 560 561 562 568 // Reverse direction in Rtl mode. 569 if ( isRtl ) 570 hoveringAt = this.model.revisions.length - hoveringAt - 1; 563 571 564 572 // Ensure sane value for hoveringAt. 565 573 if ( hoveringAt < 0 ) … … 567 575 else if ( hoveringAt >= this.model.revisions.length ) 568 576 hoveringAt = this.model.revisions.length - 1; 569 577 570 // Update the model 571 this.model.set( 'hoveringAt', hoveringAt ); 572 this.model.set( 'tooltipPosition', e.clientX ); 573 578 // Update the tooltip model 579 this.tooltip.model.set( 'revision', this.model.revisions.at( hoveringAt ) ); 580 this.tooltip.model.set( 'position', e.clientX ); 574 581 }, 575 582 576 583 mouseenter: function( e ) { 577 this. model.set( 'sliderHovering', true);584 this.tooltip.show(); 578 585 }, 579 586 580 587 mouseleave: function( e ) { 581 this. model.set( 'sliderHovering', false);588 this.tooltip.hide(); 582 589 }, 583 590 584 591 updateSliderSettings: function() { … … 592 599 values: [ 593 600 this.model.revisions.indexOf( this.model.get( 'from' ) ), 594 601 this.model.revisions.indexOf( this.model.get( 'to' ) ) 595 602 ], 596 603 value: null, 597 604 range: true // Range mode ensures handles can't cross 598 605 } ); … … 638 645 }, 639 646 640 647 start: function( event, ui ) { 641 if ( ! this.model.get( 'compareTwoMode' ) )642 return;643 644 // Track the mouse position to enable smooth dragging, overrides default jquery ui step behaviour .645 $( window ).mousemove( function( e ) {646 var sliderLeft = this.$el.offset().left,647 sliderRight = sliderLeft + this.$el.width();648 649 // Follow mouse movements, as long as handle remains inside slider.650 if ( e.clientX < sliderLeft ) {651 $( ui.handle ).css( 'left', 0 ); // Mouse to left of slider.652 } else if ( e.clientX > sliderRight ) {653 $( ui.handle ).css( 'left', sliderRight - sliderLeft); // Mouse to right of slider.654 } else {655 $( ui.handle ).css( 'left', e.clientX - sliderLeft ); // Mouse in slider.656 }657 } ); // End mousemove.658 648 }, 659 649 660 650 slide: function( event, ui ) { … … 686 676 }, 687 677 688 678 stop: function( event, ui ) { 689 if ( !this.model.get( 'compareTwoMode' ) )679 if ( this.model.get( 'compareTwoMode' ) ) 690 680 return; 691 681 692 // Stop tracking the mouse. 693 $( window ).unbind( 'mousemove' ); 694 695 // Reset settings pops handle back to the step position. 682 // Reset settings props handle back to the step position. 696 683 this.settings.trigger( 'change' ); 697 684 } 698 685 }); … … 726 713 727 714 navigateRoute: function( to, from ) { 728 715 var navigateTo = '/revision/from/' + from + '/to/' + to + '/handles/'; 729 if ( this.model.get( 'compareTwoMode' ) ) {730 navigateTo = navigateTo +'2';716 if ( this.model.get( 'compareTwoMode' ) ) { 717 navigateTo += '2'; 731 718 } else { 732 navigateTo = navigateTo +'1';719 navigateTo += '1'; 733 720 } 734 721 this.navigate( navigateTo ); 735 722 }, … … 740 727 }, 250 ), 741 728 742 729 gotoRevisionId: function( from, to, handles ) { 743 if ( '2' === handles ) { 744 this.model.set( { compareTwoMode: true } ); 745 } else { 746 this.model.set( { compareTwoMode: false } ); 747 } 730 this.model.set( { compareTwoMode: ( '2' === handles ) } ); 748 731 749 732 if ( 'undefined' !== typeof this.model ) { 750 733 var selectedToRevision = … … 756 739 to: selectedToRevision, 757 740 from: selectedFromRevision } ); 758 741 } 742 revisions.settings.selectedRevision = to; 759 743 } 760 744 }); 761 745