From c21c38722cf010952508eae12cbaaa33c629c704 Mon Sep 17 00:00:00 2001 From: Daryl Koopersmith Date: Tue, 9 Jul 2013 08:14:38 +0000 Subject: [PATCH] Revisions: Simplify how URLs are updated. See #24425. git-svn-id: http://core.svn.wordpress.org/trunk@24606 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/js/revisions.js | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/wp-admin/js/revisions.js b/wp-admin/js/revisions.js index afb7635a62..80157d6d7b 100644 --- a/wp-admin/js/revisions.js +++ b/wp-admin/js/revisions.js @@ -412,7 +412,7 @@ window.wp = window.wp || {}; this.model.set({ compareTwoMode: $('.compare-two-revisions').prop('checked') }); // Update route - this.model.revisionsRouter.navigateRoute( this.model.get('to').id, this.model.get('from').id ); + this.model.revisionsRouter.updateUrl(); }, ready: function() { @@ -498,7 +498,7 @@ window.wp = window.wp || {}; this.model.set( attributes ); // Update route - this.model.revisionsRouter.navigateRoute( attributes.to.id, attributes.from ? attributes.from.id : 0 ); + this.model.revisionsRouter.updateUrl(); }, // Go to the 'next' revision, direction takes into account RTL mode. @@ -796,27 +796,20 @@ window.wp = window.wp || {}; this.model = options.model; // Maintain state history when dragging - this.listenTo( this.model, 'renderDiff', this.updateURL ); + this.listenTo( this.model, 'renderDiff', _.debounce( this.updateUrl, 250 ) ); }, routes: { 'revision/from/:from/to/:to/handles/:handles': 'gotoRevisionId' }, - navigateRoute: function( to, from ) { - var navigateTo = '/revision/from/' + from + '/to/' + to + '/handles/'; - if ( this.model.get('compareTwoMode') ) { - navigateTo += '2'; - } else { - navigateTo += '1'; - } - this.navigate( navigateTo ); - }, + updateUrl: function() { + var from = this.model.has('from') ? this.model.get('from').id : 0; + var to = this.model.get('to').id; + var handles = this.model.get('compareTwoMode') ? '2' : '1'; - updateURL: _.debounce( function() { - var from = this.model.get('from'); - this.navigateRoute( this.model.get('to').id, from ? from.id : 0 ); - }, 250 ), + this.navigate( '/revision/from/' + from + '/to/' + to + '/handles/' + handles ); + }, gotoRevisionId: function( from, to, handles ) { from = parseInt( from, 10 );