<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[24671] trunk/wp-admin: Revisions: Cleanup, bug fixes, refactoring, polish.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/24671">24671</a></dd>
<dt>Author</dt> <dd>markjaquith</dd>
<dt>Date</dt> <dd>2013-07-12 14:01:39 +0000 (Fri, 12 Jul 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>Revisions: Cleanup, bug fixes, refactoring, polish.

* Hide the tooltip initially.
* Fix a bug with routing.
* Further separate the Slider model and view, refactoring its code.
* More reliance on events than direct calls between areas.
* Smarter background diff loading (single mode). Loads the diffs closest to your position first.
* Removed a bunch of manual templating and `render()` methods. Now relies more on the WP Backbone Views functionality.
* include the requested `id` in `ensure:load`.
* new trigger: `ensure`, for `ensure()` attempts, regardless of whether they are already loaded.
* pass along a promise in both `ensure` and `ensure:load`.
* in `ensure`, remove requests for diffs we aready have

See <a href="http://core.trac.wordpress.org/ticket/24425">#24425</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadmincsswpadmincss">trunk/wp-admin/css/wp-admin.css</a></li>
<li><a href="#trunkwpadminincludesrevisionphp">trunk/wp-admin/includes/revision.php</a></li>
<li><a href="#trunkwpadminjsrevisionsjs">trunk/wp-admin/js/revisions.js</a></li>
<li><a href="#trunkwpadminrevisionphp">trunk/wp-admin/revision.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadmincsswpadmincss"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/css/wp-admin.css (24670 => 24671)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/css/wp-admin.css  2013-07-12 07:26:11 UTC (rev 24670)
+++ trunk/wp-admin/css/wp-admin.css     2013-07-12 14:01:39 UTC (rev 24671)
</span><span class="lines">@@ -3697,6 +3697,7 @@
</span><span class="cx">  max-width: 350px;
</span><span class="cx">  min-width: 130px;
</span><span class="cx">  padding: 4px;
</span><ins>+       display: none;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> .comparing-two-revisions .revisions-tooltip {
</span></span></pre></div>
<a id="trunkwpadminincludesrevisionphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/revision.php (24670 => 24671)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/revision.php     2013-07-12 07:26:11 UTC (rev 24670)
+++ trunk/wp-admin/includes/revision.php        2013-07-12 14:01:39 UTC (rev 24671)
</span><span class="lines">@@ -99,11 +99,14 @@
</span><span class="cx">  }
</span><span class="cx"> 
</span><span class="cx">  // Now, grab the initial diff
</span><del>-       $compare_two_mode = (bool) $from;
-       if ( ! $from ) // Single mode
</del><ins>+        $compare_two_mode = is_numeric( $from );
+       if ( ! $compare_two_mode ) {
</ins><span class="cx">           $from = array_keys( array_slice( $revisions, array_search( $selected_revision_id, array_keys( $revisions ) ) - 1, 1, true ) );
</span><span class="cx">          $from = $from[0];
</span><ins>+       }
</ins><span class="cx"> 
</span><ins>+       $from = absint( $from );
+
</ins><span class="cx">   $diffs = array( array(
</span><span class="cx">          'id' => $from . ':' . $selected_revision_id,
</span><span class="cx">          'fields' => wp_get_revision_ui_diff( $post->ID, $from, $selected_revision_id ),
</span></span></pre></div>
<a id="trunkwpadminjsrevisionsjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/js/revisions.js (24670 => 24671)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/js/revisions.js   2013-07-12 07:26:11 UTC (rev 24670)
+++ trunk/wp-admin/js/revisions.js      2013-07-12 14:01:39 UTC (rev 24671)
</span><span class="lines">@@ -33,21 +33,18 @@
</span><span class="cx">   */
</span><span class="cx">  revisions.model.Slider = Backbone.Model.extend({
</span><span class="cx">          defaults: {
</span><del>-                       value: 0,
</del><ins>+                        value: null,
+                       values: null,
</ins><span class="cx">                   min: 0,
</span><span class="cx">                  max: 1,
</span><span class="cx">                  step: 1,
</span><ins>+                       range: false,
</ins><span class="cx">                   compareTwoMode: false
</span><span class="cx">          },
</span><span class="cx"> 
</span><span class="cx">          initialize: function( options ) {
</span><span class="cx">                  this.frame = options.frame;
</span><span class="cx">                  this.revisions = options.revisions;
</span><del>-                       this.set({
-                               max:   this.revisions.length - 1,
-                               value: this.revisions.indexOf( this.revisions.get( revisions.settings.to ) ),
-                               compareTwoMode: this.frame.get('compareTwoMode')
-                       });
</del><span class="cx"> 
</span><span class="cx">                  // Listen for changes to the revisions or mode from outside
</span><span class="cx">                  this.listenTo( this.frame, 'update:revisions', this.receiveRevisions );
</span><span class="lines">@@ -56,11 +53,45 @@
</span><span class="cx">                  // Listen for internal changes
</span><span class="cx">                  this.listenTo( this, 'change:from', this.handleLocalChanges );
</span><span class="cx">                  this.listenTo( this, 'change:to', this.handleLocalChanges );
</span><ins>+                       this.listenTo( this, 'change:compareTwoMode', this.updateSliderSettings );
+                       this.listenTo( this, 'update:revisions', this.updateSliderSettings );
</ins><span class="cx"> 
</span><span class="cx">                  // Listen for changes to the hovered revision
</span><span class="cx">                  this.listenTo( this, 'change:hoveredRevision', this.hoverRevision );
</span><ins>+
+                       this.set({
+                               max:   this.revisions.length - 1,
+                               compareTwoMode: this.frame.get('compareTwoMode'),
+                               from: this.frame.get('from'),
+                               to: this.frame.get('to')
+                       });
+                       this.updateSliderSettings();
</ins><span class="cx">           },
</span><span class="cx"> 
</span><ins>+               getSliderValue: function( a, b ) {
+                       return isRtl ? this.revisions.length - this.revisions.indexOf( this.get(a) ) - 1 : this.revisions.indexOf( this.get(b) );
+               },
+
+               updateSliderSettings: function() {
+                       if ( this.get('compareTwoMode') ) {
+                               this.set({
+                                       values: [
+                                               this.getSliderValue( 'to', 'from' ),
+                                               this.getSliderValue( 'from', 'to' )
+                                       ],
+                                       value: null,
+                                       range: true // ensures handles cannot cross
+                               });
+                       } else {
+                               this.set({
+                                       value: this.getSliderValue( 'to', 'to' ),
+                                       values: null,
+                                       range: false
+                               });
+                       }
+                       this.trigger( 'update:slider' );
+               },
+
</ins><span class="cx">           // Called when a revision is hovered
</span><span class="cx">          hoverRevision: function( model, value ) {
</span><span class="cx">                  this.trigger( 'hovered:revision', value );
</span><span class="lines">@@ -161,6 +192,8 @@
</span><span class="cx"> 
</span><span class="cx">  revisions.model.Diffs = Backbone.Collection.extend({
</span><span class="cx">          initialize: function( models, options ) {
</span><ins>+                       _.bindAll( this, 'getClosestUnloaded' );
+                       this.loadAll = _.once( this._loadAll );
</ins><span class="cx">                   this.revisions = options.revisions;
</span><span class="cx">                  this.requests  = {};
</span><span class="cx">          },
</span><span class="lines">@@ -172,15 +205,25 @@
</span><span class="cx">                  var request  = this.requests[ id ];
</span><span class="cx">                  var deferred = $.Deferred();
</span><span class="cx">                  var ids      = {};
</span><ins>+                       var from     = id.split(':')[0];
+                       var to       = id.split(':')[1];
+                       ids[id] = true;
</ins><span class="cx"> 
</span><ins>+                       wp.revisions.log( 'ensure', id );
+
+                       this.trigger( 'ensure', ids, from, to, deferred.promise() );
+
</ins><span class="cx">                   if ( diff ) {
</span><span class="cx">                          deferred.resolveWith( context, [ diff ] );
</span><span class="cx">                  } else {
</span><del>-                               this.trigger( 'ensure:load', ids );
-                               _.each( ids, _.bind( function(id) {
</del><ins>+                                this.trigger( 'ensure:load', ids, from, to, deferred.promise() );
+                               _.each( ids, _.bind( function( id ) {
</ins><span class="cx">                                   // Remove anything that has an ongoing request
</span><span class="cx">                                  if ( this.requests[ id ] )
</span><span class="cx">                                          delete ids[ id ];
</span><ins>+                                       // Remove anything we already have
+                                       if ( this.get( id ) )
+                                               delete ids[ id ];
</ins><span class="cx">                           }, this ) );
</span><span class="cx">                          if ( ! request ) {
</span><span class="cx">                                  // Always include the ID that started this ensure
</span><span class="lines">@@ -196,81 +239,40 @@
</span><span class="cx">                  return deferred.promise();
</span><span class="cx">          },
</span><span class="cx"> 
</span><del>-               loadNew: function( comparisons ) {
</del><ins>+                // Returns an array of proximal diffs
+               getClosestUnloaded: function( ids, centerId ) {
</ins><span class="cx">                   var self = this;
</span><del>-                       _.each( comparisons, function( id, index ) {
-                               // Already exists in collection. Don't request it again.
-                               if ( self.get( id ) )
-                                       delete comparisons[ index ];
-                       });
-                       wp.revisions.log( 'loadNew', comparisons );
</del><ins>+                        return _.chain([0].concat( ids )).initial().zip( ids ).sortBy( function( pair ) {
+                               return Math.abs( centerId - pair[1] );
+                       }).map( function( pair ) {
+                               return pair.join(':');
+                       }).filter( function( diffId ) {
+                               return _.isUndefined( self.get( diffId ) ) && ! self.requests[ diffId ];
+                       }).value();
+               },
</ins><span class="cx"> 
</span><del>-                       if ( comparisons.length )
-                               return this.load( comparisons );
-                       else
-                               return $.Deferred().resolve().promise();
</del><ins>+                _loadAll: function( allRevisionIds, centerId, num ) {
+                       var self = this, deferred = $.Deferred();
+                       diffs = _.first( this.getClosestUnloaded( allRevisionIds, centerId ), num );
+                       if ( _.size( diffs ) > 0 ) {
+                               this.load( diffs ).done( function() {
+                                       deferred.resolve();
+                                       self._loadAll( allRevisionIds, centerId, num );
+                               });
+                               return deferred.promise();
+                       } else {
+                               return deferred.reject().promise();
+                       }
</ins><span class="cx">           },
</span><span class="cx"> 
</span><span class="cx">          load: function( comparisons ) {
</span><span class="cx">                  wp.revisions.log( 'load', comparisons );
</span><span class="cx">                  // Our collection should only ever grow, never shrink, so remove: false
</span><del>-                       return this.fetch({ data: { compare: comparisons }, remove: false });
</del><ins>+                        return this.fetch({ data: { compare: comparisons }, remove: false }).done( function(){
+                               wp.revisions.log( 'load:complete', comparisons );
+                       });
</ins><span class="cx">           },
</span><span class="cx"> 
</span><del>-               loadLast: function( num ) {
-                       var ids;
-
-                       num = num || 1;
-                       ids = _.last( this.getProximalDiffIds(), num );
-
-                       if ( ids.length )
-                               return this.loadNew( ids );
-                       else
-                               return $.Deferred().resolve().promise();
-               },
-
-               loadLastUnloaded: function( num ) {
-                       var ids;
-
-                       num = num || 1;
-                       ids = _.last( this.getUnloadedProximalDiffIds(), num );
-
-                       if ( ids.length )
-                               return this.loadNew( ids );
-                       else
-                               return $.Deferred().resolve().promise();
-               },
-
-               getProximalDiffIds: function() {
-                       var previous = 0, ids = [];
-                       this.revisions.each( _.bind( function( revision ) {
-                               ids.push( previous + ':' + revision.id );
-                               previous = revision.id;
-                       }, this ) );
-                       return ids;
-               },
-
-               getUnloadedProximalDiffIds: function() {
-                       var comparisons = this.getProximalDiffIds();
-                       comparisons     = _.object( comparisons, comparisons );
-                       _.each( comparisons, _.bind( function( id ) {
-                               // Exists
-                               if ( this.get( id ) )
-                                       delete comparisons[ id ];
-                       }, this ) );
-                       return _.toArray( comparisons );
-               },
-
-               loadAllBy: function( chunkSize ) {
-                       chunkSize    = chunkSize || 20;
-                       var unloaded = this.getUnloadedProximalDiffIds();
-                       if ( unloaded.length ) {
-                               return this.loadLastUnloaded( chunkSize ).always( _.bind( function() {
-                                       this.loadAllBy( chunkSize );
-                               }, this ) );
-                       }
-               },
-
</del><span class="cx">           sync: function( method, model, options ) {
</span><span class="cx">                  if ( 'read' === method ) {
</span><span class="cx">                          options = options || {};
</span><span class="lines">@@ -329,8 +331,7 @@
</span><span class="cx">                  // Set up internal listeners
</span><span class="cx">                  this.listenTo( this, 'change:from', this.changeRevisionHandler );
</span><span class="cx">                  this.listenTo( this, 'change:to', this.changeRevisionHandler );
</span><del>-                       this.listenTo( this, 'update:revisions', this.loadSurrounding );
-                       this.listenTo( this, 'change:compareTwoMode', this.changedMode );
</del><ins>+                        this.listenTo( this, 'update:revisions', this.updatedRevisions );
</ins><span class="cx">                   this.listenTo( this.diffs, 'ensure:load', this.updateLoadingStatus );
</span><span class="cx">                  this.listenTo( this, 'update:diff', this.updateLoadingStatus );
</span><span class="cx"> 
</span><span class="lines">@@ -339,34 +340,22 @@
</span><span class="cx">                  properties.from = this.revisions.get( revisions.settings.from );
</span><span class="cx">                  properties.compareTwoMode = revisions.settings.compareTwoMode;
</span><span class="cx">                  properties.baseUrl = revisions.settings.baseUrl;
</span><del>-                       this.set( properties, { silent: true } );
</del><ins>+                        this.set( properties );
</ins><span class="cx"> 
</span><span class="cx">                  // Start the router
</span><span class="cx">                  this.router = new revisions.Router({ model: this });
</span><span class="cx">                  Backbone.history.start({ pushState: true });
</span><span class="cx">          },
</span><span class="cx"> 
</span><del>-               changedMode: function() {
-                       // This isn't passed from/to so we grab them from the model
-                       this.loadSurrounding( this.get( 'from' ), this.get( 'to' ) );
-               },
-
</del><span class="cx">           updateLoadingStatus: function() {
</span><span class="cx">                  this.set( 'loading', ! this.diff() );
</span><span class="cx">          },
</span><span class="cx"> 
</span><del>-               loadSurrounding: function( from, to ) {
-                       // Different strategies for single and compare-two models
</del><ins>+                updatedRevisions: function( from, to ) {
</ins><span class="cx">                   if ( this.get( 'compareTwoMode' ) ) {
</span><span class="cx">                          // TODO: compare-two loading strategy
</span><span class="cx">                  } else {
</span><del>-                               // TODO: clean this up to hook in to the ensure process
-                               if ( this.revisions.length ) {
-                                       // Load the rest: first 10, then the rest by 50
-                                       this.diffs.loadLastUnloaded( 10 ).always( _.bind( function() {
-                                               this.diffs.loadAllBy( 50 );
-                                       }, this ) );
-                               }
</del><ins>+                                this.diffs.loadAll( this.revisions.pluck('id'), to.id, 40 );
</ins><span class="cx">                   }
</span><span class="cx">          },
</span><span class="cx"> 
</span><span class="lines">@@ -393,8 +382,9 @@
</span><span class="cx">                  this._diffId = diffId;
</span><span class="cx">                  this.trigger( 'update:revisions', from, to );
</span><span class="cx"> 
</span><ins>+                       diff = this.diffs.get( diffId );
+
</ins><span class="cx">                   // If we already have the diff, then immediately trigger the update.
</span><del>-                       diff = this.diffs.get( diffId );
</del><span class="cx">                   if ( diff ) {
</span><span class="cx">                          this.trigger( 'update:diff', diff );
</span><span class="cx">                          return $.Deferred().resolve().promise();
</span><span class="lines">@@ -447,14 +437,12 @@
</span><span class="cx">          },
</span><span class="cx"> 
</span><span class="cx">          render: function() {
</span><del>-                       console.log( 'diff', this.model.diff() );
-                       this.model.updateDiff({ immediate: true }).done( _.bind( function() {
-                               wp.Backbone.View.prototype.render.apply( this, arguments );
</del><ins>+                        wp.Backbone.View.prototype.render.apply( this, arguments );
</ins><span class="cx"> 
</span><del>-                               $('#wpbody-content .wrap').append( this.el );
-                               this.updateCompareTwoMode();
-                               this.views.ready();
-                       }, this ) );
</del><ins>+                        $('#wpbody-content .wrap').append( this.el );
+                       this.updateCompareTwoMode();
+                       this.renderDiff( this.model.diff() );
+                       this.views.ready();
</ins><span class="cx"> 
</span><span class="cx">                  return this;
</span><span class="cx">          },
</span><span class="lines">@@ -523,29 +511,20 @@
</span><span class="cx">  });
</span><span class="cx"> 
</span><span class="cx">  // The tickmarks view
</span><del>-       // This contains the slider tickmarks.
</del><span class="cx">   revisions.view.Tickmarks = wp.Backbone.View.extend({
</span><span class="cx">          className: 'revisions-tickmarks',
</span><span class="cx"> 
</span><del>-               render: function() {
</del><ins>+                ready: function() {
</ins><span class="cx">                   var tickCount, tickWidth;
</span><del>-
</del><span class="cx">                   tickCount = this.model.revisions.length - 1;
</span><span class="cx">                  tickWidth = 1 / tickCount;
</span><span class="cx"> 
</span><del>-                       this.$el.html('');
</del><span class="cx">                   _(tickCount).times( function(){ this.$el.append( '<div></div>' ); }, this );
</span><del>-
</del><span class="cx">                   this.$('div').css( 'width', ( 100 * tickWidth ) + '%' );
</span><del>-               },
-
-               ready: function() {
-                       this.render();
</del><span class="cx">           }
</span><span class="cx">  });
</span><span class="cx"> 
</span><del>-       // The meta view.
-       // This contains the revision meta, and the restore button.
</del><ins>+        // The meta view
</ins><span class="cx">   revisions.view.Meta = wp.Backbone.View.extend({
</span><span class="cx">          className: 'revisions-meta',
</span><span class="cx">          template: wp.template('revisions-meta'),
</span><span class="lines">@@ -555,22 +534,24 @@
</span><span class="cx">          },
</span><span class="cx"> 
</span><span class="cx">          initialize: function() {
</span><del>-                       this.listenTo( this.model, 'update:revisions', this.updateMeta );
</del><ins>+                        this.listenTo( this.model, 'update:revisions', this.ready );
</ins><span class="cx">           },
</span><span class="cx"> 
</span><ins>+               prepare: function() {
+                       return this.model.toJSON();
+               },
+
+               ready: function() {
+                       this.$('.restore-revision').prop( 'disabled', this.model.get('to').get('current') );
+               },
+
</ins><span class="cx">           restoreRevision: function() {
</span><del>-                       var restoreUrl    = this.model.get('to').attributes.restoreUrl.replace(/&amp;/g, '&');
</del><ins>+                        var restoreUrl = this.model.get('to').attributes.restoreUrl.replace(/&amp;/g, '&');
</ins><span class="cx">                   document.location = restoreUrl;
</span><del>-               },
-
-               updateMeta: function( from, to ) {
-                       this.$el.html( this.template( this.model.toJSON() ) );
-                       this.$('.restore-revision').prop( 'disabled', to.attributes.current );
</del><span class="cx">           }
</span><span class="cx">  });
</span><span class="cx"> 
</span><span class="cx">  // The checkbox view.
</span><del>-       // Encapsulates all of the configuration for the compare checkbox.
</del><span class="cx">   revisions.view.Checkbox = wp.Backbone.View.extend({
</span><span class="cx">          className: 'revisions-checkbox',
</span><span class="cx">          template: wp.template('revisions-checkbox'),
</span><span class="lines">@@ -580,9 +561,14 @@
</span><span class="cx">          },
</span><span class="cx"> 
</span><span class="cx">          initialize: function() {
</span><del>-                       this.$el.html( this.template() );
</del><ins>+                        this.listenTo( this.model, 'change:compareTwoMode', this.updateCompareTwoMode );
</ins><span class="cx">           },
</span><span class="cx"> 
</span><ins>+               ready: function() {
+                       if ( this.model.revisions.length < 3 )
+                               $('.revision-toggle-compare-mode').hide();
+               },
+
</ins><span class="cx">           updateCompareTwoMode: function() {
</span><span class="cx">                  this.$('.compare-two-revisions').prop( 'checked', this.model.get('compareTwoMode') );
</span><span class="cx">          },
</span><span class="lines">@@ -591,22 +577,7 @@
</span><span class="cx">          compareTwoToggle: function( event ) {
</span><span class="cx">                  // Activate compare two mode?
</span><span class="cx">                  this.model.set({ compareTwoMode: $('.compare-two-revisions').prop('checked') });
</span><del>-
-                       // Update route
-                       this.model.router.updateUrl();
-               },
-
-               ready: function() {
-                       // Hide compare two mode toggle when fewer than three revisions.
-                       if ( this.model.revisions.length < 3 )
-                               $('.revision-toggle-compare-mode').hide();
-
-                       this.listenTo( this.model, 'change:compareTwoMode', this.updateCompareTwoMode );
-
-                       // Update the mode in case route has set it
-                       this.updateCompareTwoMode();
</del><span class="cx">           }
</span><del>-
</del><span class="cx">   });
</span><span class="cx"> 
</span><span class="cx">  // The tooltip view.
</span><span class="lines">@@ -621,10 +592,6 @@
</span><span class="cx">                  this.listenTo( this.model, 'change:scrubbing', this.toggleVisibility );
</span><span class="cx">          },
</span><span class="cx"> 
</span><del>-               ready: function() {
-                       this.toggleVisibility({ immediate: true });
-               },
-
</del><span class="cx">           visible: function() {
</span><span class="cx">                  return this.model.get( 'scrubbing' ) || this.model.get( 'hovering' );
</span><span class="cx">          },
</span><span class="lines">@@ -650,7 +617,6 @@
</span><span class="cx">                  if ( _.isNull( this.model.get('revision') ) )
</span><span class="cx">                          return;
</span><span class="cx"> 
</span><del>-                       // Insert revision data.
</del><span class="cx">                   this.$el.html( this.template( this.model.get('revision').toJSON() ) );
</span><span class="cx"> 
</span><span class="cx">                  // Set the position.
</span><span class="lines">@@ -675,7 +641,6 @@
</span><span class="cx">          },
</span><span class="cx"> 
</span><span class="cx">          initialize: function() {
</span><del>-                       this.$el.html( this.template() );
</del><span class="cx">                   this.listenTo( this.model, 'update:revisions', this.disabledButtonCheck );
</span><span class="cx">          },
</span><span class="cx"> 
</span><span class="lines">@@ -695,9 +660,6 @@
</span><span class="cx">                          this.model.unset('from', { silent: true });
</span><span class="cx"> 
</span><span class="cx">                  this.model.set( attributes );
</span><del>-
-                       // Update route
-                       this.model.router.updateUrl();
</del><span class="cx">           },
</span><span class="cx"> 
</span><span class="cx">          // Go to the 'next' revision, direction takes into account RTL mode.
</span><span class="lines">@@ -743,8 +705,7 @@
</span><span class="cx"> 
</span><span class="cx">          initialize: function() {
</span><span class="cx">                  _.bindAll( this, 'start', 'slide', 'stop', 'mouseMove' );
</span><del>-                       this.listenTo( this.model, 'change:compareTwoMode', this.updateSliderSettings );
-                       this.listenTo( this.model, 'update:revisions', this.updateSliderSettings );
</del><ins>+                        this.listenTo( this.model, 'update:slider', this.applySliderSettings );
</ins><span class="cx">           },
</span><span class="cx"> 
</span><span class="cx">          ready: function() {
</span><span class="lines">@@ -754,7 +715,7 @@
</span><span class="cx">                          stop:  this.stop
</span><span class="cx">                  }) );
</span><span class="cx"> 
</span><del>-                       this.listenTo( this, 'slide:stop', this.updateSliderSettings );
</del><ins>+                        this.applySliderSettings();
</ins><span class="cx">           },
</span><span class="cx"> 
</span><span class="cx">          mouseMove: function( e ) {
</span><span class="lines">@@ -789,27 +750,11 @@
</span><span class="cx">                  this.model.set({ hovering: true });
</span><span class="cx">          },
</span><span class="cx"> 
</span><del>-               updateSliderSettings: function() {
-                       var handles, leftValue, rightValue;
</del><ins>+                applySliderSettings: function() {
+                       this.$el.slider( _.pick( this.model.toJSON(), 'value', 'values', 'range' ) );
+                       var handles = this.$('a.ui-slider-handle');
</ins><span class="cx"> 
</span><span class="cx">                  if ( this.model.get('compareTwoMode') ) {
</span><del>-                               leftValue = isRtl ?     this.model.revisions.length - this.model.revisions.indexOf( this.model.get('to') ) - 1 :
-                                                                                       this.model.revisions.indexOf( this.model.get('from') ),
-                               rightValue = isRtl ?    this.model.revisions.length - this.model.revisions.indexOf( this.model.get('from') ) - 1 :
-                                                                                       this.model.revisions.indexOf( this.model.get('to') );
-
-                               // Set handles to current from / to models.
-                               // Reverse order for RTL
-                               this.$el.slider( {
-                                       values: [
-                                               leftValue,
-                                               rightValue
-                                       ],
-                                       value: null,
-                                       range: true // Range mode ensures handles can't cross
-                               } );
-
-                               handles = this.$('a.ui-slider-handle');
</del><span class="cx">                           // in RTL mode the 'left handle' is the second in the slider, 'right' is first
</span><span class="cx">                          handles.first()
</span><span class="cx">                                  .toggleClass( 'right-handle', !! isRtl )
</span><span class="lines">@@ -817,16 +762,8 @@
</span><span class="cx">                          handles.last()
</span><span class="cx">                                  .toggleClass( 'left-handle', !! isRtl )
</span><span class="cx">                                  .toggleClass( 'right-handle', ! isRtl );
</span><del>-
</del><span class="cx">                   } else {
</span><del>-                               this.$el.slider( { // Set handle to current to model
-                                       // Reverse order for RTL.
-                                       value: isRtl ? this.model.revisions.length - this.model.revisions.indexOf( this.model.get('to') ) - 1 :
-                                                                       this.model.revisions.indexOf( this.model.get('to') ),
-                                       values: null, // Clear existing two handled values
-                                       range: false
-                               } );
-                               this.$('a.ui-slider-handle').removeClass('left-handle right-handle');
</del><ins>+                                handles.removeClass('left-handle right-handle');
</ins><span class="cx">                   }
</span><span class="cx">          },
</span><span class="cx"> 
</span><span class="lines">@@ -850,7 +787,7 @@
</span><span class="cx"> 
</span><span class="cx">                          // In two handle mode, ensure handles can't be dragged past each other.
</span><span class="cx">                          // Adjust left/right boundaries and reset points.
</span><del>-                               if ( view.model.frame.get('compareTwoMode') ) {
</del><ins>+                                if ( view.model.get('compareTwoMode') ) {
</ins><span class="cx">                                   var rightHandle = $( ui.handle ).parent().find('.right-handle'),
</span><span class="cx">                                          leftHandle  = $( ui.handle ).parent().find('.left-handle');
</span><span class="cx"> 
</span><span class="lines">@@ -892,7 +829,7 @@
</span><span class="cx">          slide: function( event, ui ) {
</span><span class="cx">                  var attributes;
</span><span class="cx">                  // Compare two revisions mode
</span><del>-                       if ( ! _.isUndefined( ui.values ) && this.model.frame.get('compareTwoMode') ) {
</del><ins>+                        if ( ! _.isUndefined( ui.values ) && this.model.get('compareTwoMode') ) {
</ins><span class="cx">                           // Prevent sliders from occupying same spot
</span><span class="cx">                          if ( ui.values[1] === ui.values[0] )
</span><span class="cx">                                  return false;
</span><span class="lines">@@ -927,7 +864,7 @@
</span><span class="cx"> 
</span><span class="cx">          stop: function( event, ui ) {
</span><span class="cx">                  $( window ).off('mousemove.wp.revisions');
</span><del>-                       this.updateSliderSettings();
</del><ins>+                        this.model.updateSliderSettings(); // To snap us back to a tick mark
</ins><span class="cx">                   this.model.set({ scrubbing: false });
</span><span class="cx">          }
</span><span class="cx">  });
</span><span class="lines">@@ -951,8 +888,9 @@
</span><span class="cx">                  this.model = options.model;
</span><span class="cx">                  this.routes = this.getRoutes();
</span><span class="cx"> 
</span><del>-                       // Maintain state history when dragging
</del><ins>+                        // Maintain state history when dragging/clicking
</ins><span class="cx">                   this.listenTo( this.model, 'update:diff', _.debounce( this.updateUrl, 250 ) );
</span><ins>+                       this.listenTo( this.model, 'change:compareTwoMode', this.updateUrl );
</ins><span class="cx">           },
</span><span class="cx"> 
</span><span class="cx">          getRoutes: function() {
</span></span></pre></div>
<a id="trunkwpadminrevisionphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/revision.php (24670 => 24671)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/revision.php      2013-07-12 07:26:11 UTC (rev 24670)
+++ trunk/wp-admin/revision.php 2013-07-12 14:01:39 UTC (rev 24671)
</span><span class="lines">@@ -14,7 +14,8 @@
</span><span class="cx"> wp_reset_vars( array( 'revision', 'action', 'from', 'to' ) );
</span><span class="cx"> 
</span><span class="cx"> $revision_id = absint( $revision );
</span><del>-$from = absint( $from );
</del><ins>+
+$from = is_numeric( $from ) ? absint( $from ) : null;
</ins><span class="cx"> if ( ! $revision_id )
</span><span class="cx">  $revision_id = absint( $to );
</span><span class="cx"> $redirect = 'edit.php';
</span></span></pre>
</div>
</div>

</body>
</html>