Make WordPress Core

Ticket #24425: 24425.history-debounce.diff

File 24425.history-debounce.diff, 2.2 KB (added by markjaquith, 10 years ago)

Debounces the URL updates

  • wp-admin/js/revisions.js

    window.wp = window.wp || {}; 
    195195                        this.diffs     = new revisions.model.Diffs( [], {revisions: this.revisions} );
    196196                        this.listenTo( this, 'change:from', this.updateDiffFrom );
    197197                        this.listenTo( this, 'change:to', this.updateDiffTo );
    198                         this.revisionsRouter = new revisions.router.Router();
    199                         this.revisionsRouter.model = this;
     198                        this.revisionsRouter = new revisions.router.Router({ model: this });
    200199                },
    201200
    202201                updateDiffTo: function() {
    203202                        var from = this.get( 'from' );
    204                         var to   = this.get( 'to' );
    205                         this.set( 'diffId', (from ? from.id : '0' ) + ':' + to.id );
     203                        this.set( 'diffId', (from ? from.id : '0' ) + ':' + this.get('to').id );
    206204                },
    207205
    208206                updateDiffFrom: function() {
    window.wp = window.wp || {}; 
    268266                                this.views.set( '.revisions-diff-frame', new revisions.view.Diff({
    269267                                        model: diff
    270268                                }));
     269                                this.model.trigger( 'renderDiff' );
    271270                        });
    272271                }
    273272        });
    window.wp = window.wp || {}; 
    684683                                        this.model.unset('from', { silent: true });
    685684                        }
    686685                        this.model.set( attributes );
    687 
    688                         // Maintain state history when dragging
    689                         this.model.revisionsRouter.navigateRoute( attributes.to.id, ( attributes.from ? attributes.from.id : 0 ) );
    690686                },
    691687
    692688                stop: function( event, ui ) {
    window.wp = window.wp || {}; 
    717713        // The revisions router
    718714        // takes URLs with #hash fragments and routes them
    719715        revisions.router.Router = Backbone.Router.extend({
    720                 model: null,
     716                initialize: function( options ) {
     717                        this.model = options.model;
     718
     719                        // Maintain state history when dragging
     720                        this.listenTo( this.model, 'renderDiff', this.updateURL );
     721                },
    721722
    722723                routes: {
    723724                        'revision/from/:from/to/:to/handles/:handles': 'gotoRevisionId'
    window.wp = window.wp || {}; 
    733734                        this.navigate( navigateTo );
    734735                },
    735736
     737                updateURL: _.debounce( function() {
     738                        var from = this.model.get('from');
     739                        this.navigateRoute( this.model.get('to').id, from ? from.id : 0 );
     740                }, 250 ),
     741
    736742                gotoRevisionId: function( from, to, handles ) {
    737743                        if ( '2' === handles ) {
    738744                                this.model.set( { compareTwoMode: true } );