Make WordPress Core

Changeset 24679


Ignore:
Timestamp:
07/12/2013 06:14:23 PM (13 years ago)
Author:
markjaquith
Message:

Revisions: Code and whitespace cleanup.

See #24425.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/js/revisions.js

    r24678 r24679  
    738738
    739739                        // Update the tooltip model
    740                         this.model.set({
    741                                 'hoveredRevision': this.model.revisions.at( currentModelIndex )
    742                         });
     740                        this.model.set({ hoveredRevision: this.model.revisions.at( currentModelIndex ) });
    743741                },
    744742
     
    828826                // Responds to slide events
    829827                slide: function( event, ui ) {
    830                         var attributes, movedRevision;
     828                        var attributes, movedRevision, sliderPosition;
    831829                        // Compare two revisions mode
    832                         if ( ! _.isUndefined( ui.values ) && this.model.get('compareTwoMode') ) {
     830                        if ( this.model.get('compareTwoMode') ) {
    833831                                // Prevent sliders from occupying same spot
    834832                                if ( ui.values[1] === ui.values[0] )
     
    836834
    837835                                attributes = {
    838                                         to: this.model.revisions.at( isRtl ? this.model.revisions.length - ui.values[0] - 1 : ui.values[1] ), // Reverse directions for RTL.
    839                                         from: this.model.revisions.at( isRtl ? this.model.revisions.length - ui.values[1] - 1 : ui.values[0] ) // Reverse directions for RTL.
     836                                        to: this.model.revisions.at( isRtl ? this.model.revisions.length - ui.values[0] - 1 : ui.values[1] ),
     837                                        from: this.model.revisions.at( isRtl ? this.model.revisions.length - ui.values[1] - 1 : ui.values[0] )
    840838                                };
    841839                                movedRevision = ! isRtl && ui.value === ui.values[0] ? attributes.from : attributes.to;
    842840                        } else {
    843                                 // Compare single revision mode
    844                                 var sliderPosition = this.getSliderPosition( ui );
     841                                sliderPosition = this.getSliderPosition( ui );
    845842                                attributes = {
    846843                                        to: this.model.revisions.at( sliderPosition )
     
    885882                initialize: function( options ) {
    886883                        this.model = options.model;
    887                         this.routes = this.getRoutes();
    888 
    889                         // Maintain state history when dragging/clicking
     884                        this.routes = _.object([
     885                                [ this.baseUrl( '?from=:from&to=:to' ), 'handleRoute' ],
     886                                [ this.baseUrl( '?from=:from&to=:to' ), 'handleRoute' ]
     887                        ]);
     888                        // Maintain state and history when navigating
    890889                        this.listenTo( this.model, 'update:diff', _.debounce( this.updateUrl, 250 ) );
    891890                        this.listenTo( this.model, 'change:compareTwoMode', this.updateUrl );
    892                 },
    893 
    894                 getRoutes: function() {
    895                         var routes = {};
    896                         routes[this.baseUrl( '?from=:from&to=:to' )] = 'handleRoute';
    897                         routes[this.baseUrl( '?revision=:to' )] = 'handleRoute';
    898                         return routes;
    899891                },
    900892
     
    913905
    914906                handleRoute: function( a, b ) {
    915                         var from, to, compareTwo;
    916 
    917                         // If `b` is undefined, this is an 'at/:to' route, for a single revision
    918                         if ( _.isUndefined( b ) ) {
     907                        var from, to, compareTwo = _.isUndefined( b );
     908
     909                        if ( ! compareTwo ) {
    919910                                b = this.model.revisions.get( a );
    920911                                a = this.model.revisions.prev( b );
    921912                                b = b ? b.id : 0;
    922913                                a = a ? a.id : 0;
    923                                 compareTwo = false;
    924                         } else {
    925                                 compareTwo = true;
    926914                        }
    927915
    928                         from = parseInt( a, 10 );
    929                         to = parseInt( b, 10 );
    930 
    931                         this.model.set({ compareTwoMode: compareTwo });
    932 
    933                         if ( ! _.isUndefined( this.model ) ) {
    934                                 var selectedToRevision = this.model.revisions.get( to ),
    935                                         selectedFromRevision = this.model.revisions.get( from );
    936 
    937                                 this.model.set({
    938                                         to: selectedToRevision,
    939                                         from: selectedFromRevision
    940                                 });
    941                         }
    942                         revisions.settings.to = to;
     916                        this.model.set({
     917                                from: this.model.revisions.get( parseInt( a, 10 ) ),
     918                                to: this.model.revisions.get( parseInt( a, 10 ) ),
     919                                compareTwoMode: compareTwo
     920                        });
    943921                }
    944922        });
Note: See TracChangeset for help on using the changeset viewer.