Make WordPress Core

Ticket #24425: 24425.draft.28.diff

File 24425.draft.28.diff, 24.7 KB (added by ocean90, 12 years ago)

Little cleanup

  • wp-admin/css/colors-fresh.css

     
    13791379        border: 1px solid #dfdfdf;
    13801380}
    13811381
    1382 #diff-slider .ui-slider-tooltip,
    1383 #diff-slider-ticks .ui-slider-tooltip {
     1382.ui-slider-tooltip,
     1383.ui-slider-tooltip {
    13841384        border-color: #d7d7d7;
    13851385        background-color: #fff;
    13861386}
  • wp-admin/css/wp-admin-rtl.css

     
    975975        left: 6px;
    976976}
    977977
    978 #toggle-revision-compare-mode {
     978.revision-toggle-compare-mode {
    979979        right: auto;
    980980        left: 0;
    981981        padding: 9px 0 0 9px;
    982982}
    983983
    984 #diff-next-revision {
     984.revisions-next {
    985985        float: left;
    986986}
    987987
    988 #diff-previous-revision {
     988.revisions-previous {
    989989        float: right;
    990990}
    991991
  • wp-admin/css/wp-admin.css

     
    35023502        margin-bottom: 10px;
    35033503}
    35043504
     3505.comparing-two-revisions .revisions-controls {
     3506        height: 90px;
     3507}
     3508
    35053509.revisions-meta {
    35063510        margin-top: 15px;
    35073511}
     
    35103514        top: 0;
    35113515        right: 0;
    35123516}
     3517.comparing-two-revisions .revisions-previous,
     3518.comparing-two-revisions .revisions-next {
     3519        display: none;
     3520}
    35133521
    35143522.revisions-previous {
    35153523        float: left;
     
    35903598        width: 95%;
    35913599}
    35923600
    3593 #diff-slider .ui-slider-tooltip,
    3594 #diff-slider-ticks .ui-slider-tooltip {
     3601.revisions .ui-slider-tooltip {
     3602        position: absolute;
     3603        bottom: 86px;
     3604        margin-left: -70px;
    35953605        display: none;
    3596         position: absolute;
    3597         bottom: 21px;
    3598         margin-left: -74px;
     3606        line-height: 28px;
    35993607}
    36003608
    3601 #diff-slider .ui-state-active .ui-slider-tooltip,
    3602 #diff-slider .ui-state-focus .ui-slider-tooltip,
    3603 #diff-slider .ui-state-hover .ui-slider-tooltip {
    3604         display: block;
    3605 }
    3606 
    36073609#diff-title-to strong {
    36083610        display: inline;
    36093611}
     
    36553657        margin-top: 20px;
    36563658}
    36573659
    3658 .comparing-two-revisions #diff-previous-revision,
    3659 .comparing-two-revisions #diff-next-revision,
     3660#diff-previous-revision,
     3661#diff-next-revision,
    36603662#diff-header-from {
    36613663        display: none;
    36623664}
     
    37403742.ui-slider-tooltip img {
    37413743        float: left;
    37423744        margin-right: 5px;
    3743         margin-top: 5px;
     3745        margin-top: 2px;
     3746        padding: 0;
     3747        vertical-align: middle;
    37443748}
    37453749
    37463750
     
    37483752
    37493753.ui-tooltip,
    37503754.ui-slider-tooltip {
    3751         padding: 8px;
     3755        padding: 4px;
    37523756        position: absolute;
    37533757        z-index: 9999;
    37543758        max-width: 300px;
     
    37683772
    37693773.ui-tooltip,
    37703774.ui-slider-tooltip {
    3771         padding: 5px 10px;
     3775        padding: 4px 4px;
    37723776}
    37733777
    37743778.arrow {
     
    37763780        height: 16px;
    37773781        overflow: hidden;
    37783782        position: absolute;
    3779         left: 50%;
     3783        left: 0;
    37803784        margin-left: -35px;
    3781         bottom: -16px;
    3782         z-index: 99999;
     3785        bottom: 71px;
     3786        z-index: 10000;
     3787        display: none;
    37833788}
    37843789
    37853790.arrow.top {
     
    38713876
    38723877.wp-slider.ui-slider-horizontal {
    38733878        height: .8em;
     3879        z-index: 10001;
    38743880}
    38753881
    38763882.wp-slider.ui-slider-horizontal .ui-slider-handle {
  • wp-admin/js/revisions.js

     
    33(function($) {
    44        var revisions;
    55
    6         revisions = wp.revisions = { model: {}, view: {}, controller: {} };
     6        revisions = wp.revisions = { model: {}, view: {}, controller: {}, router: {} };
    77
    88        // Link settings.
    99        revisions.settings = typeof _wpRevisionsSettings === 'undefined' ? {} : _wpRevisionsSettings;
     
    3030
    3131                comparator: function( revision ) {
    3232                        return revision.id;
    33                 },
     33                }
    3434        });
    3535
    3636        revisions.model.Field = Backbone.Model.extend({});
     
    101101                        return this.fetch({ data: { compare: comparisons }, remove: false });
    102102                },
    103103
    104 /**/
    105104                loadLast: function( num ) {
    106105                        num     = num || 1;
    107106                        var ids = this.getProximalDiffIds();
     
    194193                initialize: function( attributes, options ) {
    195194                        this.revisions = options.revisions;
    196195                        this.diffs     = new revisions.model.Diffs( [], {revisions: this.revisions} );
     196                        this.listenTo( this, 'change:from', this.updateDiffFrom );
     197                        this.listenTo( this, 'change:to', this.updateDiffTo );
     198                        this.revisionsRouter = new revisions.router.Router();
     199                        this.revisionsRouter.model = this;
    197200
    198                         this.listenTo( this, 'change:from change:to', this.updateDiffId );
    199201                },
    200202
    201                 updateDiffId: function() {
     203                updateDiffTo: function() {
    202204                        var from = this.get( 'from' );
    203205                        var to   = this.get( 'to' );
    204                         this.set( 'diffId', (from ? from.id : '0') + ':' + to.id );
     206                        this.set( 'diffId', (from ? from.id : '0' ) + ':' + to.id );
     207                },
     208
     209                updateDiffFrom: function() {
     210                        if ( this.get( 'compareTwoMode' ) )
     211                                this.updateDiffTo();
    205212                }
    206213        });
    207214
     
    243250                                        this.model.diffs.loadAllBy( 50 );
    244251                                }, this ) );
    245252                        }
     253                        Backbone.history.start();
    246254                },
    247255
    248256                render: function() {
     
    266274        });
    267275
    268276        // The control view.
    269         // This contains the revision slider, previous/next buttons, and the compare checkbox.
     277        // This contains the revision slider, previous/next buttons, the meta info and the compare checkbox.
    270278        revisions.view.Controls = wp.Backbone.View.extend({
    271279                tagName: 'div',
    272280                className: 'revisions-controls',
    273281
    274282                initialize: function() {
    275283                        // Add the button view
    276                         this.views.add( new revisions.view.Buttons({ 
     284                        this.views.add( new revisions.view.Buttons({
    277285                                model: this.model
    278286                        }));
    279287
     288                        // Add the checkbox view
     289                        this.views.add( new revisions.view.Checkbox({
     290                                model: this.model
     291                        }));
     292
     293                        // Add the tooltip view
     294                        this.views.add( new revisions.view.Tooltip({
     295                                model: this.model
     296                        }));
     297
    280298                        // Add the Slider view
    281299                        this.views.add( new revisions.view.Slider({
    282300                                model: this.model
     
    314332                        if( this.model.get( 'to' ).attributes.current ) {
    315333                                $( '#restore-revision' ).prop( 'disabled', true);
    316334                        } else {
    317                                 $( '#restore-revision' ).prop( 'disabled', false)
     335                                $( '#restore-revision' ).prop( 'disabled', false);
    318336                        }
    319337                }
    320338        });
    321339
     340        // The checkbox view.
     341        // Encapsulates all of the configuration for the compare check-box.
     342        revisions.view.Checkbox = wp.Backbone.View.extend({
     343                tagName: 'div',
     344                className: 'revisions-checkbox',
     345                template: wp.template('revisions-checkbox'),
    322346
     347                initialize: function() {
     348                        this.$el.html( this.template() );
     349                        this.listenTo( this.model, 'change:compareTwoMode', this.updateCompareTwoMode );
     350                },
     351
     352                events: {
     353                        'click .compare-two-revisions': 'compareTwoToggle'
     354                },
     355
     356                updateCompareTwoMode: function() {
     357                        if ( this.model.get( 'compareTwoMode' ) ) {
     358                                $( '.revisions-control-frame' ).addClass( 'comparing-two-revisions' );
     359                                // in RTL mode the 'left handle' is the second in the slider, 'right' is first
     360                                $( '.wp-slider a.ui-slider-handle' ).first().addClass( isRtl ? 'right-handle' : 'left-handle' );
     361                                $( '.wp-slider a.ui-slider-handle' ).last().addClass( isRtl ? 'left-handle' : 'right-handle' );
     362                        } else {
     363                                $( '.revisions-control-frame' ).removeClass( 'comparing-two-revisions' );
     364                                $( '.wp-slider a.ui-slider-handle' ).removeClass( 'left-handle' ).removeClass( 'right-handle' );
     365                        }
     366
     367                },
     368
     369                // Toggle the compare two mode feature when the compare two check-box is checked.
     370                compareTwoToggle: function( event ){
     371                        // Activate compare two mode?
     372                        if ( $( '.compare-two-revisions' ).is( ':checked' ) ) {
     373                                this.model.set( { compareTwoMode: true } );
     374                        } else {
     375                                this.model.set( { compareTwoMode: false } );
     376                        }
     377
     378                        // Update route
     379                        this.model.revisionsRouter.navigateRoute( this.model.get( 'to').id, this.model.get( 'from' ).id );
     380                }
     381        });
     382
     383        // The tooltip view.
     384        // Encapsulates the tooltip.
     385        revisions.view.Tooltip = wp.Backbone.View.extend({
     386                tagName: 'div',
     387                className: 'revisions-tooltip',
     388                template: wp.template('revisions-tooltip'),
     389
     390                initialize: function() {
     391                        this.$el.html( this.template() );
     392                }
     393        });
     394
    323395        // The buttons view.
    324         // Encapsulates all of the configuration for the previous/next buttons, and the compare checkbox.
     396        // Encapsulates all of the configuration for the previous / next buttons.
    325397        revisions.view.Buttons = wp.Backbone.View.extend({
    326398                tagName: 'div',
    327399                className: 'revisions-buttons',
    328                 template: wp.template('revisions-controls'),
     400                template: wp.template('revisions-buttons'),
    329401
    330402                initialize: function() {
    331                         this.$el.html( this.template() )
     403                        this.$el.html( this.template() );
    332404                },
    333405
    334406                events: {
    335407                        'click #next': 'nextRevision',
    336408                        'click #previous': 'previousRevision'
    337409                },
    338                
     410
     411                // Go to a specific modelindex, taking into account RTL mode.
    339412                gotoModel: function( toIndex ) {
    340413                        var attributes = {
    341                                 to: this.model.revisions.at( isRtl ? this.model.revisions.length - toIndex - 1 : toIndex ) // Reverse directions for Rtl
     414                                to: this.model.revisions.at( isRtl ? this.model.revisions.length - toIndex - 1 : toIndex ) // Reverse directions for RTL.
    342415                        };
    343416                        // If we're at the first revision, unset 'from'.
    344                         if ( isRtl ? this.model.revisions.length - toIndex - 1 : toIndex ) // Reverse directions for Rtl
     417                        if ( isRtl ? this.model.revisions.length - toIndex - 1 : toIndex ) // Reverse directions for RTL
    345418                                attributes.from = this.model.revisions.at( isRtl ? this.model.revisions.length - toIndex - 2 : toIndex - 1 );
    346419                        else
    347420                                this.model.unset('from', { silent: true });
    348421
    349422                        this.model.set( attributes );
     423
     424                        // Update route
     425                        this.model.revisionsRouter.navigateRoute( attributes.to.id, attributes.from ? attributes.from.id : 0 );
    350426                },
    351427
     428                // Go to the 'next' revision, direction takes into account RTL mode.
    352429                nextRevision: function() {
    353                         var toIndex = this.model.revisions.indexOf( this.model.get( 'to' ) );
     430                        var toIndex = isRtl ? this.model.revisions.length - this.model.revisions.indexOf( this.model.get( 'to' ) ) - 1 : this.model.revisions.indexOf( this.model.get( 'to' ) );
    354431                        toIndex     = isRtl ? toIndex - 1 : toIndex + 1;
    355432                        this.gotoModel( toIndex );
    356433                },
    357                
     434
     435                // Go to the 'previous' revision, direction takes into account RTL mode.
    358436                previousRevision: function() {
    359                         var toIndex = this.model.revisions.indexOf( this.model.get('to') );
     437                        var toIndex = isRtl ? this.model.revisions.length - this.model.revisions.indexOf( this.model.get( 'to' ) ) - 1 : this.model.revisions.indexOf( this.model.get( 'to' ) );
    360438                        toIndex     = isRtl ? toIndex + 1 : toIndex - 1;
    361439                        this.gotoModel( toIndex );
    362440                },
    363441
    364442                ready: function() {
    365443                        this.listenTo( this.model, 'change:diffId', this.disabledButtonCheck );
     444
     445                        // Hide compare two mode toggle when fewer than three revisions.
     446                        if ( this.model.revisions.length < 3 )
     447                                $( '.revision-toggle-compare-mode' ).hide();
    366448                },
    367449
    368                 // Check to see if the Previous or Next buttons need to be disabled or enabled
     450                // Check to see if the Previous or Next buttons need to be disabled or enabled.
    369451                disabledButtonCheck: function() {
    370                         var maxVal   = isRtl ? 0 : this.model.revisions.length - 1,
    371                                 minVal   = isRtl ? this.model.revisions.length - 1 : 0,
    372                                 next     = $( '.revisions-next .button' ),
     452                        var maxVal = this.model.revisions.length - 1,
     453                                minVal = 0,
     454                                next = $( '.revisions-next .button' ),
    373455                                previous = $( '.revisions-previous .button' ),
    374                                 val      = this.model.revisions.indexOf( this.model.get( 'to' ) );
     456                                val = this.model.revisions.indexOf( this.model.get( 'to' ) );
    375457
    376                         // Disable "Next" button if you're on the last node
     458                        // Disable "Next" button if you're on the last node.
    377459                        if ( maxVal === val )
    378460                                next.prop( 'disabled', true );
    379461                        else
    380462                                next.prop( 'disabled', false );
    381463
    382                         // Disable "Previous" button if you're on the first node
     464                        // Disable "Previous" button if you're on the first node.
    383465                        if ( minVal === val )
    384466                                previous.prop( 'disabled', true );
    385467                        else
    386468                                previous.prop( 'disabled', false );
    387                 },
    388 
    389 
     469                }
    390470        });
    391471
    392472        // The slider view.
     
    395475                tagName: 'div',
    396476                className: 'wp-slider',
    397477
     478                events: {
     479                        'mousemove'  : 'mousemove',
     480                        'mouseenter' : 'mouseenter',
     481                        'mouseleave' : 'mouseleave'
     482                },
     483
    398484                initialize: function() {
    399485                        _.bindAll( this, 'start', 'slide', 'stop' );
    400486
     
    404490
    405491                        // Find the initially selected revision
    406492                        var initiallySelectedRevisionIndex =
    407                                 this.model.revisions.indexOf( 
     493                                this.model.revisions.indexOf(
    408494                                        this.model.revisions.findWhere(  { id: Number( revisions.settings.selectedRevision ) } ) );
    409495
    410496                        this.settings = new revisions.model.Slider({
     
    418504
    419505                ready: function() {
    420506                        this.$el.slider( this.settings.toJSON() );
     507
     508                        // Listen for changes in Compare Two Mode setting
     509                        this.listenTo( this.model, 'change:compareTwoMode', this.updateSliderSettings );
     510
    421511                        this.settings.on( 'change', function( model, options ) {
    422                                 // Apply changes to slider settings here.
    423                                 this.$el.slider( { value: this.model.revisions.indexOf( this.model.get( 'to' ) ) } ); // Set handle to current to model
     512                                this.updateSliderSettings();
    424513                        }, this );
    425                         // Reset to the initially selected revision
    426                         this.slide( '', this.settings.attributes );
    427514
    428515                        // Listen for changes in the diffId
    429516                        this.listenTo( this.model, 'change:diffId', this.diffIdChanged );
    430517
     518                        // Reset to the initially selected revision
     519                        this.slide( '', this.settings.attributes );
     520
     521                        // TODO: Move this out of slider view
     522                        if ( this.model.get( 'compareTwoMode' ) )
     523                                $( '.compare-two-revisions' ).trigger( 'click' );
    431524                },
    432525
     526                mousemove: function( e ) {
     527                        var sliderLeft = Math.ceil( this.$el.offset().left ),
     528                                sliderWidth = Math.ceil( this.$el.width() ) + 2,
     529                                tickWidth = Math.ceil( ( sliderWidth ) / this.model.revisions.length ),
     530                                hoveringAt = Math.floor( ( e.clientX - sliderLeft ) / tickWidth );
     531
     532                        // Ensure sane value for hoveringAt.
     533                        if ( hoveringAt < 0 )
     534                                hoveringAt = 0;
     535                        else if ( hoveringAt >= this.model.revisions.length )
     536                                hoveringAt = this.model.revisions.length - 1;
     537
     538                        var tooltipHtml = this.model.revisions.at( hoveringAt ).get( 'author' ).avatar +
     539                                this.model.revisions.at( hoveringAt ).get( 'author' ).name +
     540                                ', ' + this.model.revisions.at( hoveringAt ).get( 'dateShort' );
     541
     542                        this.addTooltip( $( e.currentTarget ), tooltipHtml, e );
     543                },
     544
     545                mouseenter: function( e ) {
     546                        $( e.currentTarget ).parent().find( '.ui-slider-tooltip' ).show();
     547                        $( e.currentTarget ).parent().find( '.arrow' ).show();
     548                },
     549
     550                mouseleave: function( e ) {
     551                        $( e.currentTarget ).parent().find( '.ui-slider-tooltip' ).hide();
     552                        $( e.currentTarget ).parent().find( '.arrow' ).hide();
     553                },
     554
     555                updateSliderSettings: function() {
     556                        if ( isRtl ) {
     557                                this.$el.slider( { // Order reversed in RTL mode
     558                                        value: this.model.revisions.length - this.model.revisions.indexOf( this.model.get( 'to' ) ) - 1
     559                                } );
     560                        } else {
     561                                if ( this.model.get( 'compareTwoMode' ) ) {
     562                                        this.$el.slider( { // Set handles to current from/to models
     563                                                values: [
     564                                                        this.model.revisions.indexOf( this.model.get( 'from' ) ),
     565                                                        this.model.revisions.indexOf( this.model.get( 'to' ) )
     566                                                                ],
     567                                                value: null,
     568                                                range: true // Range mode ensures handles can't cross
     569                                        } );
     570                                } else {
     571                                        this.$el.slider( { // Set handle to current to model
     572                                                value: this.model.revisions.indexOf( this.model.get( 'to' ) ),
     573                                                values: null, // Clear existing two handled values
     574                                                range: false
     575                                        } );
     576                                }
     577                        }
     578                        if ( this.model.get( 'compareTwoMode' ) ){
     579                                $( '.revisions' ).addClass( 'comparing-two-revisions' );
     580
     581                                // in RTL mode the 'left handle' is the second in the slider, 'right' is first
     582                                $( 'a.ui-slider-handle', this.$el )
     583                                        .first()
     584                                        .addClass( isRtl ? 'right-handle' : 'left-handle' )
     585                                        .removeClass( isRtl ? 'left-handle' : 'right-handle' );
     586                                $( 'a.ui-slider-handle', this.$el )
     587                                        .last()
     588                                        .addClass( isRtl ? 'left-handle' : 'right-handle' )
     589                                        .removeClass( isRtl ? 'right-handle' : 'left-handle' );
     590                        } else {
     591                                $( '.revisions' ).removeClass( 'comparing-two-revisions' );
     592                        }
     593                },
     594
    433595                diffIdChanged: function() {
    434596                        // Reset the view settings when diffId is changed
    435                         this.settings.set( { 'value': this.model.revisions.indexOf( this.model.get( 'to' ) ) } );
     597                        if ( this.model.get( 'compareTwoMode' ) ) {
     598                                this.settings.set( { 'values': [
     599                                                this.model.revisions.indexOf( this.model.get( 'from' ) ),
     600                                                this.model.revisions.indexOf( this.model.get( 'to' ) )
     601                                        ] } );
     602                        } else {
     603                                this.settings.set( { 'value': this.model.revisions.indexOf( this.model.get( 'to' ) ) } );
     604                        }
    436605                },
    437606
     607                addTooltip: function( handle, message, e ) {
     608                        var offset = $( '.revisions-buttons' ).offset().left,
     609                                calculatedX = e.clientX - offset;
     610
     611                        handle.parent().find( '.ui-slider-tooltip' ).html( message ).css( 'left', calculatedX );
     612                        handle.parent().find( '.arrow' ).css( 'left', calculatedX );
     613                },
     614
     615                getSliderPosition: function( ui ){
     616                        return isRtl ? this.model.revisions.length - ui.value - 1 : ui.value;
     617                },
     618
    438619                start: function( event, ui ) {
    439                         // Track the mouse position to enable smooth dragging, overrides default jquery ui step behaviour
    440                         $( window ).mousemove( function( e ) {
    441                                 var sliderLeft  = $( '.wp-slider' ).offset().left,
    442                                         sliderRight = sliderLeft + $( '.wp-slider' ).width();
     620                        if ( ! this.model.get( 'compareTwoMode' ) )
     621                                return;
    443622
    444                                 // Follow mouse movements, as long as handle remains inside slider
     623                        // Track the mouse position to enable smooth dragging, overrides default jquery ui step behaviour .
     624                        $( window ).mousemove( function( e ) {
     625                                var sliderLeft = this.$el.offset().left,
     626                                        sliderRight = sliderLeft + this.$el.width();
     627
     628                                // Follow mouse movements, as long as handle remains inside slider.
    445629                                if ( e.clientX < sliderLeft ) {
    446                                         $( ui.handle ).css( 'left', 0 ); // Mouse to left of slider
     630                                        $( ui.handle ).css( 'left', 0 ); // Mouse to left of slider.
    447631                                } else if ( e.clientX > sliderRight ) {
    448                                         $( ui.handle ).css( 'left', sliderRight - sliderLeft); // Mouse to right of slider
     632                                        $( ui.handle ).css( 'left', sliderRight - sliderLeft); // Mouse to right of slider.
    449633                                } else {
    450                                         $( ui.handle ).css( 'left', e.clientX - sliderLeft ); // Mouse in slider
     634                                        $( ui.handle ).css( 'left', e.clientX - sliderLeft ); // Mouse in slider.
    451635                                }
    452                         } ); // End mousemove 
     636                        } ); // End mousemove.
    453637                },
    454638
    455639                slide: function( event, ui ) {
    456                         var attributes = {
    457                                 to: this.model.revisions.at( isRtl ? this.model.revisions.length - ui.value - 1 : ui.value ) // Reverse directions for Rtl
    458                         };
     640                        var attributes;
     641                        // Compare two revisions mode
     642                        if ( 'undefined' !== typeof ui.values && this.model.get( 'compareTwoMode' ) ) {
     643                                // Prevent sliders from occupying same spot
     644                                if ( ui.values[1] === ui.values[0] )
     645                                        return false;
    459646
    460                         // If we're at the first revision, unset 'from'.
    461                         if ( isRtl ? this.model.revisions.length - ui.value - 1 : ui.value ) // Reverse directions for Rtl
    462                                 attributes.from = this.model.revisions.at( isRtl ? this.model.revisions.length - ui.value - 2 : ui.value - 1 );
    463                         else
    464                                 this.model.unset('from', { silent: true });
     647                                attributes = {
     648                                        to: this.model.revisions.at( isRtl ? this.model.revisions.length - ui.values[1] - 1 : ui.values[1] ), // Reverse directions for RTL.
     649                                        from: this.model.revisions.at( isRtl ? this.model.revisions.length - ui.values[0] - 1 : ui.values[0] ) // Reverse directions for RTL.
     650                                };
     651                        } else {
     652                                // Compare single revision mode
     653                                var sliderPosition = this.getSliderPosition( ui );
     654                                attributes = {
     655                                        to: this.model.revisions.at( sliderPosition )
     656                                };
    465657
     658                                // If we're at the first revision, unset 'from'.
     659                                if ( sliderPosition ) // Reverse directions for RTL.
     660                                        attributes.from = this.model.revisions.at( sliderPosition - 1  );
     661                                else
     662                                        this.model.unset('from', { silent: true });
     663                        }
    466664                        this.model.set( attributes );
     665
     666                        // Maintain state history when dragging
     667                        this.model.revisionsRouter.navigateRoute( attributes.to.id, ( attributes.from ? attributes.from.id : 0 ) );
    467668                },
    468669
    469670                stop: function( event, ui ) {
    470                         $( window ).unbind( 'mousemove' ); // Stop tracking the mouse
    471                         // Reset settings pops handle back to the step position
     671                        if ( ! this.model.get( 'compareTwoMode' ) )
     672                                return;
     673
     674                        // Stop tracking the mouse.
     675                        $( window ).unbind( 'mousemove' );
     676
     677                        // Reset settings pops handle back to the step position.
    472678                        this.settings.trigger( 'change' );
    473679                }
    474680        });
     
    486692                }
    487693        });
    488694
     695        // The revisions router
     696        // takes URLs with #hash fragments and routes them
     697        revisions.router.Router = Backbone.Router.extend({
     698                model: null,
     699
     700                routes: {
     701                        'revision/from/:from/to/:to/handles/:handles': 'gotoRevisionId'
     702                },
     703
     704                navigateRoute: function( to, from ) {
     705                        var navigateTo = '/revision/from/' + from + '/to/' + to + '/handles/';
     706                        if ( this.model.get( 'compareTwoMode' ) ){
     707                                navigateTo = navigateTo + '2';
     708                        } else {
     709                                navigateTo = navigateTo + '1';
     710                        }
     711                        this.navigate( navigateTo );
     712                },
     713
     714                gotoRevisionId: function( from, to, handles ) {
     715                        if ( '2' === handles ) {
     716                                this.model.set( { compareTwoMode: true } );
     717                        } else {
     718                                this.model.set( { compareTwoMode: false } );
     719                        }
     720
     721                        if ( 'undefined' !== typeof this.model ) {
     722                                var selectedToRevision =
     723                                        this.model.revisions.findWhere( { 'id': Number( to ) } ),
     724                                        selectedFromRevision =
     725                                        this.model.revisions.findWhere( { 'id': Number( from ) } );
     726
     727                                this.model.set( {
     728                                        to:   selectedToRevision,
     729                                        from: selectedFromRevision } );
     730                        }
     731                }
     732        });
     733
    489734        // Initialize the revisions UI.
    490735        revisions.init = function() {
    491736                revisions.view.frame = new revisions.view.Frame({
    492737                        collection: new revisions.model.Revisions( revisions.settings.revisionData )
    493738                }).render();
     739                // Only allow compare two mode if three or more revisions
    494740        };
    495741
    496742        $( revisions.init );
  • wp-admin/revision.php

     
    118118        <span class="spinner"></span>
    119119        <div class="revisions-control-frame"></div>
    120120        <div class="revisions-diff-frame"></div>
     121
    121122</script>
    122123
    123 <script id="tmpl-revisions-controls" type="text/html">
    124 
    125         <div class="revision-toggle-compare-mode">
    126                 <label>
    127                         <input type="checkbox" class="compare-two-revisions" />
    128                         <?php esc_attr_e( 'Compare two revisions' ); ?>
    129                 </label>
    130         </div>
    131 
     124<script id="tmpl-revisions-buttons" type="text/html">
    132125        <div class="revisions-previous">
    133126                <input class="button" type="button" id="previous" value="<?php echo esc_attr_x( 'Previous', 'Button label for a previous revision' ); ?>" />
    134127        </div>
     
    138131        </div>
    139132</script>
    140133
     134<script id="tmpl-revisions-tooltip" type="text/html">
     135        <div class="ui-slider-tooltip ui-widget-content ui-corner-all "></div>
     136        <div class="arrow"></div>
     137</script>
    141138
     139<script id="tmpl-revisions-checkbox" type="text/html">
     140        <div class="revision-toggle-compare-mode">
     141                <label>
     142                        <input type="checkbox" class="compare-two-revisions" />
     143                        <?php esc_attr_e( 'Compare two revisions' ); ?>
     144                </label>
     145        </div>
     146</script>
     147
    142148<script id="tmpl-revisions-meta" type="text/html">
    143149        <div id="diff-header">
    144150                <div id="diff-header-from" class="diff-header">
     
    177183        <# }); #>
    178184</script>
    179185
    180 <script id="tmpl-revisions-diff-old" type="text/html">
    181         <div id="toggle-revision-compare-mode">
    182                 <label>
    183                         <input type="checkbox" id="compare-two-revisions" />
    184                         <?php esc_attr_e( 'Compare two revisions' ); ?>
    185                 </label>
    186         </div>
    187 
    188         <div id="diff-header">
    189                 <div id="diff-header-from" class="diff-header">
    190                         <div id="diff-title-from" class="diff-title">
    191                                 <strong><?php _ex( 'From:', 'Followed by post revision info' ); ?></strong> {{{ data.titleFrom }}}
    192                         </div>
    193                         <div class="clear"></div>
    194                 </div>
    195 
    196                 <div id="diff-header-to" class="diff-header">
    197                         <div id="diff-title-to" class="diff-title">
    198                                 <strong><?php _ex( 'To:', 'Followed by post revision info' ); ?></strong> {{{ data.titleTo }}}
    199                         </div>
    200 
    201                         <input type="button" id="restore-revision" class="button button-primary" data-restore-link="{{{ data.restoreLink }}}" value="<?php esc_attr_e( 'Restore This Revision' )?>" />
    202                         <div class="clear"></div>
    203                 </div>
    204         </div>
    205 
    206         <div id="diff-table">{{{ data.diff }}}</div>
    207 </script>
    208 
    209 <script id="tmpl-revision-interact-old" type="text/html">
    210         <div id="diff-previous-revision">
    211                 <input class="button" type="button" id="previous" value="<?php echo esc_attr_x( 'Previous', 'Button label for a previous revision' ); ?>" />
    212         </div>
    213 
    214         <div id="diff-next-revision">
    215                 <input class="button" type="button" id="next" value="<?php echo esc_attr_x( 'Next', 'Button label for a next revision' ); ?>" />
    216         </div>
    217 
    218 </script>
    219 
    220186<script id="tmpl-revision-ticks" type="text/html">
    221187        <div class="revision-tick completed-{{{ data.completed }}} scope-of-changes-{{{ data.scopeOfChanges }}}">
    222188                <span class="ui-slider-tooltip ui-widget-content ui-corner-all hidden"></span>
    223189        </div>
    224190</script>
     191
    225192<?php
    226193require_once( './admin-footer.php' );