<!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>[24565] trunk/wp-admin: Revisions improvements</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/24565">24565</a></dd>
<dt>Author</dt> <dd>markjaquith</dd>
<dt>Date</dt> <dd>2013-07-05 17:44:47 +0000 (Fri, 05 Jul 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>Revisions improvements

* Consolidated router code
* Corrected routing behavior
* Tooltip model
* Removed mouse dragging code

props adamsilverstein, ocean90. 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="#trunkwpadminjsrevisionsjs">trunk/wp-admin/js/revisions.js</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 (24564 => 24565)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/css/wp-admin.css  2013-07-05 17:38:14 UTC (rev 24564)
+++ trunk/wp-admin/css/wp-admin.css     2013-07-05 17:44:47 UTC (rev 24565)
</span><span class="lines">@@ -3778,10 +3778,6 @@
</span><span class="cx">  padding: 4px 4px;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-.revisions-tooltip {
-       display: none;
-}
-
</del><span class="cx"> .arrow {
</span><span class="cx">  width: 70px;
</span><span class="cx">  height: 16px;
</span></span></pre></div>
<a id="trunkwpadminjsrevisionsjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/js/revisions.js (24564 => 24565)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/js/revisions.js   2013-07-05 17:38:14 UTC (rev 24564)
+++ trunk/wp-admin/js/revisions.js      2013-07-05 17:44:47 UTC (rev 24565)
</span><span class="lines">@@ -23,6 +23,13 @@
</span><span class="cx">          }
</span><span class="cx">  });
</span><span class="cx"> 
</span><ins>+       revisions.model.Tooltip = Backbone.Model.extend({
+               defaults: {
+                       revision: null,
+                       position: 0
+               }
+       });
+
</ins><span class="cx">   revisions.model.Revision = Backbone.Model.extend({});
</span><span class="cx"> 
</span><span class="cx">  revisions.model.Revisions = Backbone.Collection.extend({
</span><span class="lines">@@ -289,12 +296,15 @@
</span><span class="cx">                  }));
</span><span class="cx"> 
</span><span class="cx">                  // Add the tooltip view
</span><del>-                       this.views.add( new revisions.view.Tooltip({
-                               model: this.model
-                       }));
-                       // Add the Slider view
</del><ins>+                        var tooltip = new revisions.view.Tooltip({
+                               model: new revisions.model.Tooltip()
+                       });
+                       this.views.add( tooltip );
+
+                       // Add the Slider view with a reference to the tooltip view
</ins><span class="cx">                   this.views.add( new revisions.view.Slider({
</span><del>-                               model: this.model
</del><ins>+                                model: this.model,
+                               tooltip: tooltip
</ins><span class="cx">                   }) );
</span><span class="cx"> 
</span><span class="cx">                  // Add the Meta view
</span><span class="lines">@@ -394,35 +404,34 @@
</span><span class="cx">          template: wp.template( 'revisions-tooltip' ),
</span><span class="cx"> 
</span><span class="cx">          initialize: function() {
</span><del>-                       this.listenTo( this.model, 'change:sliderHovering', this.sliderHoveringChanged );
-                       this.listenTo( this.model, 'change:tooltipPosition', this.tooltipPositionChanged );
</del><ins>+                        this.listenTo( this.model, 'change', this.render );
</ins><span class="cx">           },
</span><span class="cx"> 
</span><span class="cx">          ready: function() {
</span><ins>+                       // Hide tooltip on start.
+                       this.$el.addClass( 'hidden' );
</ins><span class="cx">           },
</span><span class="cx"> 
</span><del>-               // Show or hide tooltip based on sliderHovering is true
-               sliderHoveringChanged: function() {
-                       if ( this.model.get( 'sliderHovering' ) ) {
-                               this.$el.show();
-                       } else {
-                               this.$el.hide();
-                       }
</del><ins>+                show: function() {
+                       this.$el.removeClass( 'hidden' );
</ins><span class="cx">           },
</span><span class="cx"> 
</span><del>-               tooltipPositionChanged: function() {
-                       this.$el.html( this.template( this.model.revisions.at( this.model.get( 'hoveringAt') ).toJSON() ) );
-
-                       this.setTooltip( this.model.get( 'tooltipPosition' ) );
</del><ins>+                hide: function() {
+                       this.$el.addClass( 'hidden' );
</ins><span class="cx">           },
</span><span class="cx"> 
</span><del>-               setTooltip: function( tooltipPosition ) {
</del><ins>+                render: function() {
+                       // Check if a revision exists.
+                       if ( null === this.model.get( 'revision' ) )
+                               return;
+
+                       this.$el.html( this.template( this.model.get( 'revision' ).toJSON() ) );
+
</ins><span class="cx">                   var offset = $( '.revisions-buttons' ).offset().left,
</span><del>-                               calculatedX = tooltipPosition - offset;
</del><ins>+                                calculatedX = this.model.get( 'position' ) - offset;
</ins><span class="cx"> 
</span><del>-
-                       this.$el.find( '.ui-slider-tooltip' ).css( 'left', calculatedX );
-                       this.$el.find( '.arrow' ).css( 'left', calculatedX );
</del><ins>+                        $( '.ui-slider-tooltip', this.$el ).css( 'left', calculatedX );
+                       $( '.arrow', this.$el ).css( 'left', calculatedX );
</ins><span class="cx">           }
</span><span class="cx">  });
</span><span class="cx"> 
</span><span class="lines">@@ -486,16 +495,10 @@
</span><span class="cx">                          val = this.model.revisions.indexOf( this.model.get( 'to' ) );
</span><span class="cx"> 
</span><span class="cx">                  // Disable "Next" button if you're on the last node.
</span><del>-                       if ( maxVal === val )
-                               next.prop( 'disabled', true );
-                       else
-                               next.prop( 'disabled', false );
</del><ins>+                        next.prop( 'disabled', ( maxVal === val ) );
</ins><span class="cx"> 
</span><span class="cx">                  // Disable "Previous" button if you're on the first node.
</span><del>-                       if ( minVal === val )
-                               previous.prop( 'disabled', true );
-                       else
-                               previous.prop( 'disabled', false );
</del><ins>+                        previous.prop( 'disabled', ( minVal === val ) );
</ins><span class="cx">           }
</span><span class="cx">  });
</span><span class="cx"> 
</span><span class="lines">@@ -512,16 +515,18 @@
</span><span class="cx">                  'mouseleave' : 'mouseleave'
</span><span class="cx">          },
</span><span class="cx"> 
</span><del>-               initialize: function() {
</del><ins>+                initialize: function( options ) {
</ins><span class="cx">                   _.bindAll( this, 'start', 'slide', 'stop' );
</span><span class="cx"> 
</span><ins>+                       this.tooltip = options.tooltip;
+
</ins><span class="cx">                   // Create the slider model from the provided collection data.
</span><span class="cx">                  var latestRevisionIndex = this.model.revisions.length - 1;
</span><span class="cx"> 
</span><span class="cx">                  // Find the initially selected revision
</span><span class="cx">                  var initiallySelectedRevisionIndex =
</span><span class="cx">                          this.model.revisions.indexOf(
</span><del>-                                       this.model.revisions.findWhere(  { id: Number( revisions.settings.selectedRevision ) } ) );
</del><ins>+                                        this.model.revisions.findWhere( { id: Number( revisions.settings.selectedRevision ) } ) );
</ins><span class="cx"> 
</span><span class="cx">                  this.settings = new revisions.model.Slider({
</span><span class="cx">                          max:   latestRevisionIndex,
</span><span class="lines">@@ -533,21 +538,24 @@
</span><span class="cx">          },
</span><span class="cx"> 
</span><span class="cx">          ready: function() {
</span><ins>+                       // Refresh the currently selected revision position in case router has set it.
+                       this.settings.attributes.value = this.model.revisions.indexOf(
+                               this.model.revisions.findWhere( { id: Number( revisions.settings.selectedRevision ) } ) );
+
+                       this.slide( '', this.settings.attributes );
+
</ins><span class="cx">                   this.$el.slider( this.settings.toJSON() );
</span><span class="cx"> 
</span><span class="cx">                  // Listen for changes in Compare Two Mode setting
</span><span class="cx">                  this.listenTo( this.model, 'change:compareTwoMode', this.updateSliderSettings );
</span><span class="cx"> 
</span><del>-                       this.settings.on( 'change', function( model, options ) {
</del><ins>+                        this.settings.on( 'change', function() {
</ins><span class="cx">                           this.updateSliderSettings();
</span><span class="cx">                  }, this );
</span><span class="cx"> 
</span><span class="cx">                  // Listen for changes in the diffId
</span><span class="cx">                  this.listenTo( this.model, 'change:diffId', this.diffIdChanged );
</span><span class="cx"> 
</span><del>-                       // Reset to the initially selected revision
-                       this.slide( '', this.settings.attributes );
-
</del><span class="cx">           },
</span><span class="cx"> 
</span><span class="cx">          mousemove: function( e ) {
</span><span class="lines">@@ -557,9 +565,9 @@
</span><span class="cx">                          actualX = e.clientX - sliderLeft,
</span><span class="cx">                          hoveringAt = Math.floor( actualX / tickWidth );
</span><span class="cx"> 
</span><del>-                               // Reverse direction in Rtl mode.
-                               if ( isRtl )
-                                       hoveringAt = this.model.revisions.length - hoveringAt - 1;
</del><ins>+                        // Reverse direction in Rtl mode.
+                       if ( isRtl )
+                               hoveringAt = this.model.revisions.length - hoveringAt - 1;
</ins><span class="cx"> 
</span><span class="cx">                  // Ensure sane value for hoveringAt.
</span><span class="cx">                  if ( hoveringAt < 0 )
</span><span class="lines">@@ -567,18 +575,17 @@
</span><span class="cx">                  else if ( hoveringAt >= this.model.revisions.length )
</span><span class="cx">                          hoveringAt = this.model.revisions.length - 1;
</span><span class="cx"> 
</span><del>-                       // Update the model
-                       this.model.set( 'hoveringAt', hoveringAt );
-                       this.model.set( 'tooltipPosition', e.clientX );
-
</del><ins>+                        // Update the tooltip model
+                       this.tooltip.model.set( 'revision', this.model.revisions.at( hoveringAt ) );
+                       this.tooltip.model.set( 'position', e.clientX );
</ins><span class="cx">           },
</span><span class="cx"> 
</span><span class="cx">          mouseenter: function( e ) {
</span><del>-                       this.model.set( 'sliderHovering', true );
</del><ins>+                        this.tooltip.show();
</ins><span class="cx">           },
</span><span class="cx"> 
</span><span class="cx">          mouseleave: function( e ) {
</span><del>-                       this.model.set( 'sliderHovering', false );
</del><ins>+                        this.tooltip.hide();
</ins><span class="cx">           },
</span><span class="cx"> 
</span><span class="cx">          updateSliderSettings: function() {
</span><span class="lines">@@ -592,7 +599,7 @@
</span><span class="cx">                                          values: [
</span><span class="cx">                                                  this.model.revisions.indexOf( this.model.get( 'from' ) ),
</span><span class="cx">                                                  this.model.revisions.indexOf( this.model.get( 'to' ) )
</span><del>-                                                               ],
</del><ins>+                                                ],
</ins><span class="cx">                                           value: null,
</span><span class="cx">                                          range: true // Range mode ensures handles can't cross
</span><span class="cx">                                  } );
</span><span class="lines">@@ -638,23 +645,6 @@
</span><span class="cx">          },
</span><span class="cx"> 
</span><span class="cx">          start: function( event, ui ) {
</span><del>-                       if ( ! this.model.get( 'compareTwoMode' ) )
-                               return;
-
-                       // Track the mouse position to enable smooth dragging, overrides default jquery ui step behaviour .
-                       $( window ).mousemove( function( e ) {
-                               var sliderLeft = this.$el.offset().left,
-                                       sliderRight = sliderLeft + this.$el.width();
-
-                               // Follow mouse movements, as long as handle remains inside slider.
-                               if ( e.clientX < sliderLeft ) {
-                                       $( ui.handle ).css( 'left', 0 ); // Mouse to left of slider.
-                               } else if ( e.clientX > sliderRight ) {
-                                       $( ui.handle ).css( 'left', sliderRight - sliderLeft); // Mouse to right of slider.
-                               } else {
-                                       $( ui.handle ).css( 'left', e.clientX - sliderLeft ); // Mouse in slider.
-                               }
-                       } ); // End mousemove.
</del><span class="cx">           },
</span><span class="cx"> 
</span><span class="cx">          slide: function( event, ui ) {
</span><span class="lines">@@ -686,13 +676,10 @@
</span><span class="cx">          },
</span><span class="cx"> 
</span><span class="cx">          stop: function( event, ui ) {
</span><del>-                       if ( ! this.model.get( 'compareTwoMode' ) )
</del><ins>+                        if ( this.model.get( 'compareTwoMode' ) )
</ins><span class="cx">                           return;
</span><span class="cx"> 
</span><del>-                       // Stop tracking the mouse.
-                       $( window ).unbind( 'mousemove' );
-
-                       // Reset settings pops handle back to the step position.
</del><ins>+                        // Reset settings props handle back to the step position.
</ins><span class="cx">                   this.settings.trigger( 'change' );
</span><span class="cx">          }
</span><span class="cx">  });
</span><span class="lines">@@ -726,10 +713,10 @@
</span><span class="cx"> 
</span><span class="cx">          navigateRoute: function( to, from ) {
</span><span class="cx">                  var navigateTo = '/revision/from/' + from + '/to/' + to + '/handles/';
</span><del>-                       if ( this.model.get( 'compareTwoMode' ) ){
-                               navigateTo = navigateTo + '2';
</del><ins>+                        if ( this.model.get( 'compareTwoMode' ) ) {
+                               navigateTo += '2';
</ins><span class="cx">                   } else {
</span><del>-                               navigateTo = navigateTo + '1';
</del><ins>+                                navigateTo += '1';
</ins><span class="cx">                   }
</span><span class="cx">                  this.navigate( navigateTo );
</span><span class="cx">          },
</span><span class="lines">@@ -740,11 +727,7 @@
</span><span class="cx">          }, 250 ),
</span><span class="cx"> 
</span><span class="cx">          gotoRevisionId: function( from, to, handles ) {
</span><del>-                       if ( '2' === handles ) {
-                               this.model.set( { compareTwoMode: true } );
-                       } else {
-                               this.model.set( { compareTwoMode: false } );
-                       }
</del><ins>+                        this.model.set( { compareTwoMode: ( '2' === handles ) } );
</ins><span class="cx"> 
</span><span class="cx">                  if ( 'undefined' !== typeof this.model ) {
</span><span class="cx">                          var selectedToRevision =
</span><span class="lines">@@ -756,6 +739,7 @@
</span><span class="cx">                                  to:   selectedToRevision,
</span><span class="cx">                                  from: selectedFromRevision } );
</span><span class="cx">                  }
</span><ins>+                       revisions.settings.selectedRevision = to;
</ins><span class="cx">           }
</span><span class="cx">  });
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>