<!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>[24667] trunk/wp-admin: Revisions: Loading indicator, cleanup, bug fixes.</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/24667">24667</a></dd>
<dt>Author</dt> <dd>markjaquith</dd>
<dt>Date</dt> <dd>2013-07-12 05:11:56 +0000 (Fri, 12 Jul 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>Revisions: Loading indicator, cleanup, bug fixes.

* Loading indicator when the user is waiting for a trip to the server.
* Bug fixes for diff priming.
* Fix the date display.
* Forget about local comparator, instead order by `modified` on the server.
* Initialize the frame model before the view (this was the source of a LOT of heartache).</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadmincsswpadmincss">trunk/wp-admin/css/wp-admin.css</a></li>
<li><a href="#trunkwpadminincludesajaxactionsphp">trunk/wp-admin/includes/ajax-actions.php</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 (24666 => 24667)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/css/wp-admin.css  2013-07-12 05:11:50 UTC (rev 24666)
+++ trunk/wp-admin/css/wp-admin.css     2013-07-12 05:11:56 UTC (rev 24667)
</span><span class="lines">@@ -3538,6 +3538,39 @@
</span><span class="cx">  height: 140px;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+.revisions .loading-indicator {
+       position: absolute;
+       text-align: center;
+       vertical-align: middle;
+       opacity: 0;
+       margin: 0 auto;
+       width: 100%;
+       height: 32px;
+       top: 3em;
+       background: #fff url(../images/wpspin_light-2x.gif) no-repeat center top;
+       -webkit-transition: opacity 0.5s;
+       -moz-transition:    opacity 0.5s;
+       -ms-transition:     opacity 0.5s;
+       -o-transition:      opacity 0.5s;
+       transition:         opacity 0.5s;
+}
+
+.revisions.loading .loading-indicator {
+       opacity: 1;
+}
+
+.revisions .diff {
+       -webkit-transition: opacity 0.5s;
+       -moz-transition:    opacity 0.5s;
+       -ms-transition:     opacity 0.5s;
+       -o-transition:      opacity 0.5s;
+       transition:         opacity 0.5s;
+}
+
+.revisions.loading .diff {
+       opacity: 0.5;
+}
+
</ins><span class="cx"> .revisions-meta {
</span><span class="cx">  margin-top: 15px;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkwpadminincludesajaxactionsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/ajax-actions.php (24666 => 24667)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/ajax-actions.php 2013-07-12 05:11:50 UTC (rev 24666)
+++ trunk/wp-admin/includes/ajax-actions.php    2013-07-12 05:11:56 UTC (rev 24667)
</span><span class="lines">@@ -2092,8 +2092,6 @@
</span><span class="cx"> function wp_ajax_get_revision_diffs() {
</span><span class="cx">  require ABSPATH . 'wp-admin/includes/revision.php';
</span><span class="cx"> 
</span><del>-       // check_ajax_referer( 'revisions-ajax-nonce', 'nonce' );
-
</del><span class="cx">   if ( ! $post = get_post( (int) $_REQUEST['post_id'] ) )
</span><span class="cx">          wp_send_json_error();
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpadminincludesrevisionphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/revision.php (24666 => 24667)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/revision.php     2013-07-12 05:11:50 UTC (rev 24666)
+++ trunk/wp-admin/includes/revision.php        2013-07-12 05:11:56 UTC (rev 24667)
</span><span class="lines">@@ -66,11 +66,12 @@
</span><span class="cx">  $revisions = array();
</span><span class="cx">  $now_gmt = time();
</span><span class="cx"> 
</span><del>-       $revisions = wp_get_post_revisions( $post->ID );
</del><ins>+        $revisions = wp_get_post_revisions( $post->ID, array( 'order' => 'ASC', 'orderby' => 'modified' ) );
</ins><span class="cx"> 
</span><span class="cx">  cache_users( wp_list_pluck( $revisions, 'post_author' ) );
</span><span class="cx"> 
</span><span class="cx">  foreach ( $revisions as $revision ) {
</span><ins>+               $modified = strtotime( $revision->post_modified );
</ins><span class="cx">           $modified_gmt = strtotime( $revision->post_modified_gmt );
</span><span class="cx">          $restore_link = wp_nonce_url(
</span><span class="cx">                  add_query_arg(
</span><span class="lines">@@ -88,9 +89,8 @@
</span><span class="cx">                          'avatar' => get_avatar( $revision->post_author, 24 ),
</span><span class="cx">                          'name'   => get_the_author_meta( 'display_name', $revision->post_author ),
</span><span class="cx">                  ),
</span><del>-                       'date'         => date_i18n( __( 'M j, Y @ G:i' ), $modified_gmt ),
-                       'dateShort'    => date_i18n( _x( 'j M @ G:i', 'revision date short format' ), $modified_gmt ),
-                       'dateUnix'     => $modified_gmt,
</del><ins>+                        'date'         => date_i18n( __( 'M j, Y @ G:i' ), $modified ),
+                       'dateShort'    => date_i18n( _x( 'j M @ G:i', 'revision date short format' ), $modified ),
</ins><span class="cx">                   'timeAgo'      => sprintf( __( '%s ago' ), human_time_diff( $modified_gmt, $now_gmt ) ),
</span><span class="cx">                  'autosave'     => wp_is_post_autosave( $revision ),
</span><span class="cx">                  'current'      => $revision->post_modified_gmt === $post->post_modified_gmt,
</span><span class="lines">@@ -99,16 +99,13 @@
</span><span class="cx">  }
</span><span class="cx"> 
</span><span class="cx">  // Now, grab the initial diff
</span><del>-       if ( ! $from ) { // Single mode
-               $initial_revisions = array_reverse( array_keys( array_slice( $revisions, array_search( $selected_revision_id, array_keys( $revisions ) ), 2, true ) ) );
-               $compare_two_mode = false;
-       } else { // Compare two
-               $compare_two_mode = true;
-               $initial_revisions = array( $from, $selected_revision_id );
-       }
</del><ins>+        $compare_two_mode = (bool) $from;
+       if ( ! $from ) // Single mode
+               $from = array_keys( array_slice( $revisions, array_search( $selected_revision_id, array_keys( $revisions ) ) - 1, 1, true ) )[0];
+
</ins><span class="cx">   $diffs = array( array(
</span><del>-               'id' => $initial_revisions[0] . ':' . $initial_revisions[1],
-               'fields' => wp_get_revision_ui_diff( $post->ID, $initial_revisions[0], $initial_revisions[1] ),
</del><ins>+                'id' => $from . ':' . $selected_revision_id,
+               'fields' => wp_get_revision_ui_diff( $post->ID, $from, $selected_revision_id ),
</ins><span class="cx">   ));
</span><span class="cx"> 
</span><span class="cx">  return array(
</span><span class="lines">@@ -120,5 +117,6 @@
</span><span class="cx">          'diffData'         => $diffs,
</span><span class="cx">          'baseUrl'          => parse_url( admin_url( 'revision.php' ), PHP_URL_PATH ),
</span><span class="cx">          'compareTwoMode'   => absint( $compare_two_mode ), // Apparently booleans are not allowed
</span><ins>+               'revisionIds'      => array_keys( $revisions ),
</ins><span class="cx">   );
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkwpadminjsrevisionsjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/js/revisions.js (24666 => 24667)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/js/revisions.js   2013-07-12 05:11:50 UTC (rev 24666)
+++ trunk/wp-admin/js/revisions.js      2013-07-12 05:11:56 UTC (rev 24667)
</span><span class="lines">@@ -129,15 +129,6 @@
</span><span class="cx">                  _.bindAll( this, 'next', 'prev' );
</span><span class="cx">          },
</span><span class="cx"> 
</span><del>-               comparator: function( a, b ) {
-                       var a_ = a.get('dateUnix');
-                       var b_ = b.get('dateUnix');
-                       var cmp = (a_ > b_) - (a_ < b_);
-                       if (cmp === 0 && a.id != b.id)
-                               cmp = a.id < b.id ? -1 : 1;
-                       return cmp;
-               },
-
</del><span class="cx">           next: function( revision ) {
</span><span class="cx">                  var index = this.indexOf( revision );
</span><span class="cx"> 
</span><span class="lines">@@ -335,23 +326,24 @@
</span><span class="cx">                  // Set the initial diffs collection provided through the settings
</span><span class="cx">                  this.diffs.set( revisions.settings.diffData );
</span><span class="cx"> 
</span><ins>+                       // Set up internal listeners
+                       this.listenTo( this, 'change:from', this.changeRevisionHandler );
+                       this.listenTo( this, 'change:to', this.changeRevisionHandler );
+                       this.listenTo( this, 'update:revisions', this.loadSurrounding );
+                       this.listenTo( this, 'change:compareTwoMode', this.changedMode );
+                       this.listenTo( this.diffs, 'ensure:load', this.updateLoadingStatus );
+                       this.listenTo( this, 'update:diff', this.updateLoadingStatus );
+
</ins><span class="cx">                   // Set the initial revisions, baseUrl, and mode as provided through settings
</span><span class="cx">                  properties.to = this.revisions.get( revisions.settings.to );
</span><del>-                       properties.from = this.revisions.get( revisions.settings.from ) || this.revisions.prev( properties.to );
</del><ins>+                        properties.from = this.revisions.get( revisions.settings.from );
</ins><span class="cx">                   properties.compareTwoMode = revisions.settings.compareTwoMode;
</span><span class="cx">                  properties.baseUrl = revisions.settings.baseUrl;
</span><del>-                       this.set( properties );
</del><ins>+                        this.set( properties, { silent: true } );
</ins><span class="cx"> 
</span><del>-                       // Start the router. This will trigger a navigate event and ensure that
-                       // the `from` and `to` revisions accurately reflect the hash.
</del><ins>+                        // Start the router
</ins><span class="cx">                   this.router = new revisions.Router({ model: this });
</span><span class="cx">                  Backbone.history.start({ pushState: true });
</span><del>-
-                       // Set up internal listeners
-                       this.listenTo( this, 'change:from', this.changeRevisionHandler );
-                       this.listenTo( this, 'change:to', this.changeRevisionHandler );
-                       this.listenTo( this, 'update:revisions', this.loadSurrounding );
-                       this.listenTo( this, 'change:compareTwoMode', this.changedMode );
</del><span class="cx">           },
</span><span class="cx"> 
</span><span class="cx">          changedMode: function() {
</span><span class="lines">@@ -359,6 +351,10 @@
</span><span class="cx">                  this.loadSurrounding( this.get( 'from' ), this.get( 'to' ) );
</span><span class="cx">          },
</span><span class="cx"> 
</span><ins>+               updateLoadingStatus: function() {
+                       this.set( 'loading', ! this.diff() );
+               },
+
</ins><span class="cx">           loadSurrounding: function( from, to ) {
</span><span class="cx">                  // Different strategies for single and compare-two models
</span><span class="cx">                  if ( this.get( 'compareTwoMode' ) ) {
</span><span class="lines">@@ -441,13 +437,9 @@
</span><span class="cx">          template: wp.template('revisions-frame'),
</span><span class="cx"> 
</span><span class="cx">          initialize: function() {
</span><del>-                       // Generate the frame model.
-                       this.model = new revisions.model.FrameState({}, {
-                               revisions: this.collection
-                       });
-
</del><span class="cx">                   this.listenTo( this.model, 'update:diff', this.renderDiff );
</span><span class="cx">                  this.listenTo( this.model, 'change:compareTwoMode', this.updateCompareTwoMode );
</span><ins>+                       this.listenTo( this.model, 'change:loading', this.updateLoadingStatus );
</ins><span class="cx"> 
</span><span class="cx">                  this.views.set( '.revisions-control-frame', new revisions.view.Controls({
</span><span class="cx">                          model: this.model
</span><span class="lines">@@ -455,6 +447,7 @@
</span><span class="cx">          },
</span><span class="cx"> 
</span><span class="cx">          render: function() {
</span><ins>+                       console.log( 'diff', this.model.diff() );
</ins><span class="cx">                   this.model.updateDiff({ immediate: true }).done( _.bind( function() {
</span><span class="cx">                          wp.Backbone.View.prototype.render.apply( this, arguments );
</span><span class="cx"> 
</span><span class="lines">@@ -472,6 +465,10 @@
</span><span class="cx">                  }) );
</span><span class="cx">          },
</span><span class="cx"> 
</span><ins>+               updateLoadingStatus: function() {
+                       this.$el.toggleClass( 'loading', this.model.get('loading') );
+               },
+
</ins><span class="cx">           updateCompareTwoMode: function() {
</span><span class="cx">                  this.$el.toggleClass( 'comparing-two-revisions', this.model.get('compareTwoMode') );
</span><span class="cx">          }
</span><span class="lines">@@ -1013,7 +1010,9 @@
</span><span class="cx">  // Initialize the revisions UI.
</span><span class="cx">  revisions.init = function() {
</span><span class="cx">          revisions.view.frame = new revisions.view.Frame({
</span><del>-                       collection: new revisions.model.Revisions( revisions.settings.revisionData )
</del><ins>+                        model: new revisions.model.FrameState({}, {
+                               revisions: new revisions.model.Revisions( revisions.settings.revisionData )
+                       })
</ins><span class="cx">           }).render();
</span><span class="cx">  };
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpadminrevisionphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/revision.php (24666 => 24667)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/revision.php      2013-07-12 05:11:50 UTC (rev 24666)
+++ trunk/wp-admin/revision.php 2013-07-12 05:11:56 UTC (rev 24667)
</span><span class="lines">@@ -185,10 +185,13 @@
</span><span class="cx"> </script>
</span><span class="cx"> 
</span><span class="cx"> <script id="tmpl-revisions-diff" type="text/html">
</span><ins>+       <div class="loading-indicator"></div>
+       <div class="diff">
</ins><span class="cx">   <# _.each( data.fields, function( field ) { #>
</span><span class="cx">          <h3>{{{ field.name }}}</h3>
</span><span class="cx">          {{{ field.diff }}}
</span><span class="cx">  <# }); #>
</span><ins>+       </div>
</ins><span class="cx"> </script>
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>