<!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>[24549] trunk/wp-admin: Revisions UI update:</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/24549">24549</a></dd>
<dt>Author</dt> <dd>ocean90</dd>
<dt>Date</dt> <dd>2013-07-03 20:27:19 +0000 (Wed, 03 Jul 2013)</dd>
</dl>
<h3>Log Message</h3>
<pre>Revisions UI update:
* Restore Compare two mode
* Restore tooltips
* RTL support
* First pass for URL routing and history
props adamsilverstein, see <a href="http://core.trac.wordpress.org/ticket/24425">#24425</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadmincsscolorsfreshcss">trunk/wp-admin/css/colors-fresh.css</a></li>
<li><a href="#trunkwpadmincsswpadminrtlcss">trunk/wp-admin/css/wp-admin-rtl.css</a></li>
<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>
<li><a href="#trunkwpadminrevisionphp">trunk/wp-admin/revision.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadmincsscolorsfreshcss"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/css/colors-fresh.css (24548 => 24549)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/css/colors-fresh.css 2013-07-03 20:23:48 UTC (rev 24548)
+++ trunk/wp-admin/css/colors-fresh.css 2013-07-03 20:27:19 UTC (rev 24549)
</span><span class="lines">@@ -1379,8 +1379,8 @@
</span><span class="cx"> border: 1px solid #dfdfdf;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-#diff-slider .ui-slider-tooltip,
-#diff-slider-ticks .ui-slider-tooltip {
</del><ins>+.ui-slider-tooltip,
+.ui-slider-tooltip {
</ins><span class="cx"> border-color: #d7d7d7;
</span><span class="cx"> background-color: #fff;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkwpadmincsswpadminrtlcss"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/css/wp-admin-rtl.css (24548 => 24549)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/css/wp-admin-rtl.css 2013-07-03 20:23:48 UTC (rev 24548)
+++ trunk/wp-admin/css/wp-admin-rtl.css 2013-07-03 20:27:19 UTC (rev 24549)
</span><span class="lines">@@ -975,17 +975,17 @@
</span><span class="cx"> left: 6px;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-#toggle-revision-compare-mode {
</del><ins>+.revision-toggle-compare-mode {
</ins><span class="cx"> right: auto;
</span><span class="cx"> left: 0;
</span><span class="cx"> padding: 9px 0 0 9px;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-#diff-next-revision {
</del><ins>+.revisions-next {
</ins><span class="cx"> float: left;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-#diff-previous-revision {
</del><ins>+.revisions-previous {
</ins><span class="cx"> float: right;
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkwpadmincsswpadmincss"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/css/wp-admin.css (24548 => 24549)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/css/wp-admin.css 2013-07-03 20:23:48 UTC (rev 24548)
+++ trunk/wp-admin/css/wp-admin.css 2013-07-03 20:27:19 UTC (rev 24549)
</span><span class="lines">@@ -3498,10 +3498,14 @@
</span><span class="cx"> .revisions-controls {
</span><span class="cx"> height: 60px;
</span><span class="cx"> padding: 40px 0 20px;
</span><del>- border-bottom: 1px solid #dfdfdf;
</del><ins>+ border-bottom: none;
</ins><span class="cx"> margin-bottom: 10px;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+.comparing-two-revisions .revisions-controls {
+ height: 90px;
+}
+
</ins><span class="cx"> .revisions-meta {
</span><span class="cx"> margin-top: 15px;
</span><span class="cx"> }
</span><span class="lines">@@ -3510,6 +3514,10 @@
</span><span class="cx"> top: 0;
</span><span class="cx"> right: 0;
</span><span class="cx"> }
</span><ins>+.comparing-two-revisions .revisions-previous,
+.comparing-two-revisions .revisions-next {
+ display: none;
+}
</ins><span class="cx">
</span><span class="cx"> .revisions-previous {
</span><span class="cx"> float: left;
</span><span class="lines">@@ -3532,6 +3540,7 @@
</span><span class="cx">
</span><span class="cx"> table.diff {
</span><span class="cx"> width: 100%;
</span><ins>+ white-space: pre-wrap;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> table.diff col.content {
</span><span class="lines">@@ -3590,20 +3599,13 @@
</span><span class="cx"> width: 95%;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-#diff-slider .ui-slider-tooltip,
-#diff-slider-ticks .ui-slider-tooltip {
- display: none;
</del><ins>+.revisions .ui-slider-tooltip {
</ins><span class="cx"> position: absolute;
</span><del>- bottom: 21px;
- margin-left: -74px;
</del><ins>+ bottom: 86px;
+ margin-left: -70px;
+ line-height: 28px;
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-#diff-slider .ui-state-active .ui-slider-tooltip,
-#diff-slider .ui-state-focus .ui-slider-tooltip,
-#diff-slider .ui-state-hover .ui-slider-tooltip {
- display: block;
-}
-
</del><span class="cx"> #diff-title-to strong {
</span><span class="cx"> display: inline;
</span><span class="cx"> }
</span><span class="lines">@@ -3655,8 +3657,8 @@
</span><span class="cx"> margin-top: 20px;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-.comparing-two-revisions #diff-previous-revision,
-.comparing-two-revisions #diff-next-revision,
</del><ins>+#diff-previous-revision,
+#diff-next-revision,
</ins><span class="cx"> #diff-header-from {
</span><span class="cx"> display: none;
</span><span class="cx"> }
</span><span class="lines">@@ -3668,6 +3670,9 @@
</span><span class="cx"> display: block;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+.comparing-two-revisions .revisions-tooltip div {
+ margin-bottom: 30px;
+}
</ins><span class="cx"> .diff-slider-ticks-wrapper {
</span><span class="cx"> margin: 0 auto;
</span><span class="cx"> text-align: left;
</span><span class="lines">@@ -3740,7 +3745,9 @@
</span><span class="cx"> .ui-slider-tooltip img {
</span><span class="cx"> float: left;
</span><span class="cx"> margin-right: 5px;
</span><del>- margin-top: 5px;
</del><ins>+ margin-top: 2px;
+ padding: 0;
+ vertical-align: middle;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx">
</span><span class="lines">@@ -3748,7 +3755,7 @@
</span><span class="cx">
</span><span class="cx"> .ui-tooltip,
</span><span class="cx"> .ui-slider-tooltip {
</span><del>- padding: 8px;
</del><ins>+ padding: 4px;
</ins><span class="cx"> position: absolute;
</span><span class="cx"> z-index: 9999;
</span><span class="cx"> max-width: 300px;
</span><span class="lines">@@ -3768,18 +3775,22 @@
</span><span class="cx">
</span><span class="cx"> .ui-tooltip,
</span><span class="cx"> .ui-slider-tooltip {
</span><del>- padding: 5px 10px;
</del><ins>+ padding: 4px 4px;
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+.revisions-tooltip {
+ display: none;
+}
+
</ins><span class="cx"> .arrow {
</span><span class="cx"> width: 70px;
</span><span class="cx"> height: 16px;
</span><span class="cx"> overflow: hidden;
</span><span class="cx"> position: absolute;
</span><del>- left: 50%;
</del><ins>+ left: 0;
</ins><span class="cx"> margin-left: -35px;
</span><del>- bottom: -16px;
- z-index: 99999;
</del><ins>+ bottom: 71px;
+ z-index: 10000;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> .arrow.top {
</span><span class="lines">@@ -3871,6 +3882,7 @@
</span><span class="cx">
</span><span class="cx"> .wp-slider.ui-slider-horizontal {
</span><span class="cx"> height: .8em;
</span><ins>+ z-index: 10001;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> .wp-slider.ui-slider-horizontal .ui-slider-handle {
</span></span></pre></div>
<a id="trunkwpadminjsrevisionsjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/js/revisions.js (24548 => 24549)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/js/revisions.js 2013-07-03 20:23:48 UTC (rev 24548)
+++ trunk/wp-admin/js/revisions.js 2013-07-03 20:27:19 UTC (rev 24549)
</span><span class="lines">@@ -3,7 +3,7 @@
</span><span class="cx"> (function($) {
</span><span class="cx"> var revisions;
</span><span class="cx">
</span><del>- revisions = wp.revisions = { model: {}, view: {}, controller: {} };
</del><ins>+ revisions = wp.revisions = { model: {}, view: {}, controller: {}, router: {} };
</ins><span class="cx">
</span><span class="cx"> // Link settings.
</span><span class="cx"> revisions.settings = typeof _wpRevisionsSettings === 'undefined' ? {} : _wpRevisionsSettings;
</span><span class="lines">@@ -30,7 +30,7 @@
</span><span class="cx">
</span><span class="cx"> comparator: function( revision ) {
</span><span class="cx"> return revision.id;
</span><del>- },
</del><ins>+ }
</ins><span class="cx"> });
</span><span class="cx">
</span><span class="cx"> revisions.model.Field = Backbone.Model.extend({});
</span><span class="lines">@@ -101,7 +101,6 @@
</span><span class="cx"> return this.fetch({ data: { compare: comparisons }, remove: false });
</span><span class="cx"> },
</span><span class="cx">
</span><del>-/**/
</del><span class="cx"> loadLast: function( num ) {
</span><span class="cx"> num = num || 1;
</span><span class="cx"> var ids = this.getProximalDiffIds();
</span><span class="lines">@@ -194,14 +193,21 @@
</span><span class="cx"> initialize: function( attributes, options ) {
</span><span class="cx"> this.revisions = options.revisions;
</span><span class="cx"> this.diffs = new revisions.model.Diffs( [], {revisions: this.revisions} );
</span><del>-
- this.listenTo( this, 'change:from change:to', this.updateDiffId );
</del><ins>+ this.listenTo( this, 'change:from', this.updateDiffFrom );
+ this.listenTo( this, 'change:to', this.updateDiffTo );
+ this.revisionsRouter = new revisions.router.Router();
+ this.revisionsRouter.model = this;
</ins><span class="cx"> },
</span><span class="cx">
</span><del>- updateDiffId: function() {
</del><ins>+ updateDiffTo: function() {
</ins><span class="cx"> var from = this.get( 'from' );
</span><span class="cx"> var to = this.get( 'to' );
</span><del>- this.set( 'diffId', (from ? from.id : '0') + ':' + to.id );
</del><ins>+ this.set( 'diffId', (from ? from.id : '0' ) + ':' + to.id );
+ },
+
+ updateDiffFrom: function() {
+ if ( this.get( 'compareTwoMode' ) )
+ this.updateDiffTo();
</ins><span class="cx"> }
</span><span class="cx"> });
</span><span class="cx">
</span><span class="lines">@@ -243,6 +249,7 @@
</span><span class="cx"> this.model.diffs.loadAllBy( 50 );
</span><span class="cx"> }, this ) );
</span><span class="cx"> }
</span><ins>+ Backbone.history.start();
</ins><span class="cx"> },
</span><span class="cx">
</span><span class="cx"> render: function() {
</span><span class="lines">@@ -266,17 +273,26 @@
</span><span class="cx"> });
</span><span class="cx">
</span><span class="cx"> // The control view.
</span><del>- // This contains the revision slider, previous/next buttons, and the compare checkbox.
</del><ins>+ // This contains the revision slider, previous/next buttons, the meta info and the compare checkbox.
</ins><span class="cx"> revisions.view.Controls = wp.Backbone.View.extend({
</span><span class="cx"> tagName: 'div',
</span><span class="cx"> className: 'revisions-controls',
</span><span class="cx">
</span><span class="cx"> initialize: function() {
</span><span class="cx"> // Add the button view
</span><del>- this.views.add( new revisions.view.Buttons({
</del><ins>+ this.views.add( new revisions.view.Buttons({
</ins><span class="cx"> model: this.model
</span><span class="cx"> }));
</span><span class="cx">
</span><ins>+ // Add the checkbox view
+ this.views.add( new revisions.view.Checkbox({
+ model: this.model
+ }));
+
+ // Add the tooltip view
+ this.views.add( new revisions.view.Tooltip({
+ model: this.model
+ }));
</ins><span class="cx"> // Add the Slider view
</span><span class="cx"> this.views.add( new revisions.view.Slider({
</span><span class="cx"> model: this.model
</span><span class="lines">@@ -296,14 +312,14 @@
</span><span class="cx"> className: 'revisions-meta',
</span><span class="cx"> template: wp.template('revisions-meta'),
</span><span class="cx">
</span><ins>+ events: {
+ 'click #restore-revision': 'restoreRevision'
+ },
+
</ins><span class="cx"> initialize: function() {
</span><span class="cx"> this.listenTo( this.model, 'change:diffId', this.updateMeta );
</span><span class="cx"> },
</span><span class="cx">
</span><del>- events: {
- 'click #restore-revision': 'restoreRevision'
- },
-
</del><span class="cx"> restoreRevision: function() {
</span><span class="cx"> var restoreUrl = this.model.get('to').attributes.restoreUrl.replace(/&/g, '&');
</span><span class="cx"> document.location = restoreUrl;
</span><span class="lines">@@ -312,99 +328,200 @@
</span><span class="cx"> updateMeta: function() {
</span><span class="cx"> this.$el.html( this.template( this.model.toJSON() ) );
</span><span class="cx"> if( this.model.get( 'to' ).attributes.current ) {
</span><del>- $( '#restore-revision' ).prop( 'disabled', true);
</del><ins>+ $( '#restore-revision' ).prop( 'disabled', true );
</ins><span class="cx"> } else {
</span><del>- $( '#restore-revision' ).prop( 'disabled', false)
</del><ins>+ $( '#restore-revision' ).prop( 'disabled', false );
</ins><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx"> });
</span><span class="cx">
</span><ins>+ // The checkbox view.
+ // Encapsulates all of the configuration for the compare checkbox.
+ revisions.view.Checkbox = wp.Backbone.View.extend({
+ tagName: 'div',
+ className: 'revisions-checkbox',
+ template: wp.template( 'revisions-checkbox' ),
</ins><span class="cx">
</span><ins>+ events: {
+ 'click .compare-two-revisions': 'compareTwoToggle'
+ },
+
+ initialize: function() {
+ this.$el.html( this.template() );
+ this.listenTo( this.model, 'change:compareTwoMode', this.updateCompareTwoMode );
+ },
+
+ updateCompareTwoMode: function() {
+ if ( this.model.get( 'compareTwoMode' ) ) {
+ $( '.compare-two-revisions' ).parent().css('border', '1px solid #f00;').prop( 'checked', true );
+ $( '.revisions-control-frame' ).addClass( 'comparing-two-revisions' );
+ // in RTL mode the 'left handle' is the second in the slider, 'right' is first
+ $( '.wp-slider a.ui-slider-handle' ).first().addClass( isRtl ? 'right-handle' : 'left-handle' );
+ $( '.wp-slider a.ui-slider-handle' ).last().addClass( isRtl ? 'left-handle' : 'right-handle' );
+ } else {
+ $( '.compare-two-revisions' ).prop( 'checked', false );
+ $( '.revisions-control-frame' ).removeClass( 'comparing-two-revisions' );
+ $( '.wp-slider a.ui-slider-handle' ).removeClass( 'left-handle' ).removeClass( 'right-handle' );
+ }
+
+ },
+
+ // Toggle the compare two mode feature when the compare two checkbox is checked.
+ compareTwoToggle: function( event ) {
+ // Activate compare two mode?
+ if ( $( '.compare-two-revisions' ).is( ':checked' ) ) {
+ this.model.set( { compareTwoMode: true } );
+ } else {
+ this.model.set( { compareTwoMode: false } );
+ }
+
+ // Update route
+ this.model.revisionsRouter.navigateRoute( this.model.get( 'to').id, this.model.get( 'from' ).id );
+ },
+
+ ready: function() {
+ // Hide compare two mode toggle when fewer than three revisions.
+ if ( this.model.revisions.length < 3 )
+ $( '.revision-toggle-compare-mode' ).hide();
+ }
+
+ });
+
+ // The tooltip view.
+ // Encapsulates the tooltip.
+ revisions.view.Tooltip = wp.Backbone.View.extend({
+ tagName: 'div',
+ className: 'revisions-tooltip',
+ template: wp.template( 'revisions-tooltip' ),
+
+ initialize: function() {
+ this.listenTo( this.model, 'change:sliderHovering', this.sliderHoveringChanged );
+ this.listenTo( this.model, 'change:tooltipPosition', this.tooltipPositionChanged );
+ },
+
+ ready: function() {
+ },
+
+ // Show or hide tooltip based on sliderHovering is true
+ sliderHoveringChanged: function() {
+ if ( this.model.get( 'sliderHovering' ) ) {
+ this.$el.show();
+ } else {
+ this.$el.hide();
+ }
+ },
+
+ tooltipPositionChanged: function() {
+ this.$el.html( this.template( this.model.revisions.at( this.model.get( 'hoveringAt') ).toJSON() ) );
+
+ this.setTooltip( this.model.get( 'tooltipPosition' ) );
+ },
+
+ setTooltip: function( tooltipPosition ) {
+ var offset = $( '.revisions-buttons' ).offset().left,
+ calculatedX = tooltipPosition - offset;
+
+
+ this.$el.find( '.ui-slider-tooltip' ).css( 'left', calculatedX );
+ this.$el.find( '.arrow' ).css( 'left', calculatedX );
+ }
+ });
+
</ins><span class="cx"> // The buttons view.
</span><del>- // Encapsulates all of the configuration for the previous/next buttons, and the compare checkbox.
</del><ins>+ // Encapsulates all of the configuration for the previous/next buttons.
</ins><span class="cx"> revisions.view.Buttons = wp.Backbone.View.extend({
</span><span class="cx"> tagName: 'div',
</span><span class="cx"> className: 'revisions-buttons',
</span><del>- template: wp.template('revisions-controls'),
</del><ins>+ template: wp.template( 'revisions-buttons' ),
</ins><span class="cx">
</span><del>- initialize: function() {
- this.$el.html( this.template() )
- },
-
</del><span class="cx"> events: {
</span><span class="cx"> 'click #next': 'nextRevision',
</span><span class="cx"> 'click #previous': 'previousRevision'
</span><span class="cx"> },
</span><del>-
</del><ins>+
+ initialize: function() {
+ this.$el.html( this.template() );
+ },
+
+ ready: function() {
+ this.listenTo( this.model, 'change:diffId', this.disabledButtonCheck );
+ },
+
+ // Go to a specific modelindex, taking into account RTL mode.
</ins><span class="cx"> gotoModel: function( toIndex ) {
</span><span class="cx"> var attributes = {
</span><del>- to: this.model.revisions.at( isRtl ? this.model.revisions.length - toIndex - 1 : toIndex ) // Reverse directions for Rtl
</del><ins>+ to: this.model.revisions.at( isRtl ? this.model.revisions.length - toIndex - 1 : toIndex ) // Reverse directions for RTL.
</ins><span class="cx"> };
</span><span class="cx"> // If we're at the first revision, unset 'from'.
</span><del>- if ( isRtl ? this.model.revisions.length - toIndex - 1 : toIndex ) // Reverse directions for Rtl
</del><ins>+ if ( isRtl ? this.model.revisions.length - toIndex - 1 : toIndex ) // Reverse directions for RTL
</ins><span class="cx"> attributes.from = this.model.revisions.at( isRtl ? this.model.revisions.length - toIndex - 2 : toIndex - 1 );
</span><span class="cx"> else
</span><span class="cx"> this.model.unset('from', { silent: true });
</span><span class="cx">
</span><span class="cx"> this.model.set( attributes );
</span><ins>+
+ // Update route
+ this.model.revisionsRouter.navigateRoute( attributes.to.id, attributes.from ? attributes.from.id : 0 );
</ins><span class="cx"> },
</span><span class="cx">
</span><ins>+ // Go to the 'next' revision, direction takes into account RTL mode.
</ins><span class="cx"> nextRevision: function() {
</span><del>- var toIndex = this.model.revisions.indexOf( this.model.get( 'to' ) );
</del><ins>+ var toIndex = isRtl ? this.model.revisions.length - this.model.revisions.indexOf( this.model.get( 'to' ) ) - 1 : this.model.revisions.indexOf( this.model.get( 'to' ) );
</ins><span class="cx"> toIndex = isRtl ? toIndex - 1 : toIndex + 1;
</span><span class="cx"> this.gotoModel( toIndex );
</span><span class="cx"> },
</span><del>-
</del><ins>+
+ // Go to the 'previous' revision, direction takes into account RTL mode.
</ins><span class="cx"> previousRevision: function() {
</span><del>- var toIndex = this.model.revisions.indexOf( this.model.get('to') );
</del><ins>+ var toIndex = isRtl ? this.model.revisions.length - this.model.revisions.indexOf( this.model.get( 'to' ) ) - 1 : this.model.revisions.indexOf( this.model.get( 'to' ) );
</ins><span class="cx"> toIndex = isRtl ? toIndex + 1 : toIndex - 1;
</span><span class="cx"> this.gotoModel( toIndex );
</span><span class="cx"> },
</span><span class="cx">
</span><del>- ready: function() {
- this.listenTo( this.model, 'change:diffId', this.disabledButtonCheck );
- },
-
- // Check to see if the Previous or Next buttons need to be disabled or enabled
</del><ins>+ // Check to see if the Previous or Next buttons need to be disabled or enabled.
</ins><span class="cx"> disabledButtonCheck: function() {
</span><del>- var maxVal = isRtl ? 0 : this.model.revisions.length - 1,
- minVal = isRtl ? this.model.revisions.length - 1 : 0,
- next = $( '.revisions-next .button' ),
</del><ins>+ var maxVal = this.model.revisions.length - 1,
+ minVal = 0,
+ next = $( '.revisions-next .button' ),
</ins><span class="cx"> previous = $( '.revisions-previous .button' ),
</span><del>- val = this.model.revisions.indexOf( this.model.get( 'to' ) );
</del><ins>+ val = this.model.revisions.indexOf( this.model.get( 'to' ) );
</ins><span class="cx">
</span><del>- // Disable "Next" button if you're on the last node
</del><ins>+ // Disable "Next" button if you're on the last node.
</ins><span class="cx"> if ( maxVal === val )
</span><span class="cx"> next.prop( 'disabled', true );
</span><span class="cx"> else
</span><span class="cx"> next.prop( 'disabled', false );
</span><span class="cx">
</span><del>- // Disable "Previous" button if you're on the first node
</del><ins>+ // Disable "Previous" button if you're on the first node.
</ins><span class="cx"> if ( minVal === val )
</span><span class="cx"> previous.prop( 'disabled', true );
</span><span class="cx"> else
</span><span class="cx"> previous.prop( 'disabled', false );
</span><del>- },
</del><ins>+ }
+ });
</ins><span class="cx">
</span><span class="cx">
</span><del>- });
-
</del><span class="cx"> // The slider view.
</span><span class="cx"> // Encapsulates all of the configuration for the jQuery UI slider into a view.
</span><span class="cx"> revisions.view.Slider = wp.Backbone.View.extend({
</span><span class="cx"> tagName: 'div',
</span><span class="cx"> className: 'wp-slider',
</span><span class="cx">
</span><ins>+ events: {
+ 'mousemove' : 'mousemove',
+ 'mouseenter' : 'mouseenter',
+ 'mouseleave' : 'mouseleave'
+ },
+
</ins><span class="cx"> initialize: function() {
</span><span class="cx"> _.bindAll( this, 'start', 'slide', 'stop' );
</span><span class="cx">
</span><span class="cx"> // Create the slider model from the provided collection data.
</span><del>- // TODO: This should actually pull from the model's `to` key.
</del><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><del>- this.model.revisions.indexOf(
</del><ins>+ this.model.revisions.indexOf(
</ins><span class="cx"> this.model.revisions.findWhere( { id: Number( revisions.settings.selectedRevision ) } ) );
</span><span class="cx">
</span><span class="cx"> this.settings = new revisions.model.Slider({
</span><span class="lines">@@ -418,57 +535,168 @@
</span><span class="cx">
</span><span class="cx"> ready: function() {
</span><span class="cx"> this.$el.slider( this.settings.toJSON() );
</span><ins>+
+ // Listen for changes in Compare Two Mode setting
+ this.listenTo( this.model, 'change:compareTwoMode', this.updateSliderSettings );
+
</ins><span class="cx"> this.settings.on( 'change', function( model, options ) {
</span><del>- // Apply changes to slider settings here.
- this.$el.slider( { value: this.model.revisions.indexOf( this.model.get( 'to' ) ) } ); // Set handle to current to model
</del><ins>+ this.updateSliderSettings();
</ins><span class="cx"> }, this );
</span><del>- // Reset to the initially selected revision
- this.slide( '', this.settings.attributes );
</del><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><ins>+ // Reset to the initially selected revision
+ this.slide( '', this.settings.attributes );
+
</ins><span class="cx"> },
</span><span class="cx">
</span><ins>+ mousemove: function( e ) {
+ var sliderLeft = Math.ceil( this.$el.offset().left ),
+ sliderWidth = Math.ceil( this.$el.width() ) + 2,
+ tickWidth = Math.ceil( ( sliderWidth ) / this.model.revisions.length ),
+ actualX = e.clientX - sliderLeft,
+ hoveringAt = Math.floor( actualX / tickWidth );
+
+ // Reverse direction in Rtl mode.
+ if ( isRtl )
+ hoveringAt = this.model.revisions.length - hoveringAt - 1;
+
+ // Ensure sane value for hoveringAt.
+ if ( hoveringAt < 0 )
+ hoveringAt = 0;
+ else if ( hoveringAt >= this.model.revisions.length )
+ hoveringAt = this.model.revisions.length - 1;
+
+ // Update the model
+ this.model.set( 'hoveringAt', hoveringAt );
+ this.model.set( 'tooltipPosition', e.clientX );
+
+ },
+
+ mouseenter: function( e ) {
+ this.model.set( 'sliderHovering', true );
+ },
+
+ mouseleave: function( e ) {
+ this.model.set( 'sliderHovering', false );
+ },
+
+ updateSliderSettings: function() {
+ if ( isRtl ) {
+ this.$el.slider( { // Order reversed in RTL mode
+ value: this.model.revisions.length - this.model.revisions.indexOf( this.model.get( 'to' ) ) - 1
+ } );
+ } else {
+ if ( this.model.get( 'compareTwoMode' ) ) {
+ this.$el.slider( { // Set handles to current from/to models
+ values: [
+ this.model.revisions.indexOf( this.model.get( 'from' ) ),
+ this.model.revisions.indexOf( this.model.get( 'to' ) )
+ ],
+ value: null,
+ range: true // Range mode ensures handles can't cross
+ } );
+ } else {
+ this.$el.slider( { // Set handle to current to model
+ value: this.model.revisions.indexOf( this.model.get( 'to' ) ),
+ values: null, // Clear existing two handled values
+ range: false
+ } );
+ }
+ }
+ if ( this.model.get( 'compareTwoMode' ) ){
+ $( '.revisions' ).addClass( 'comparing-two-revisions' );
+
+ // in RTL mode the 'left handle' is the second in the slider, 'right' is first
+ $( 'a.ui-slider-handle', this.$el )
+ .first()
+ .addClass( isRtl ? 'right-handle' : 'left-handle' )
+ .removeClass( isRtl ? 'left-handle' : 'right-handle' );
+ $( 'a.ui-slider-handle', this.$el )
+ .last()
+ .addClass( isRtl ? 'left-handle' : 'right-handle' )
+ .removeClass( isRtl ? 'right-handle' : 'left-handle' );
+ } else {
+ $( '.revisions' ).removeClass( 'comparing-two-revisions' );
+ }
+ },
+
</ins><span class="cx"> diffIdChanged: function() {
</span><span class="cx"> // Reset the view settings when diffId is changed
</span><del>- this.settings.set( { 'value': this.model.revisions.indexOf( this.model.get( 'to' ) ) } );
</del><ins>+ if ( this.model.get( 'compareTwoMode' ) ) {
+ this.settings.set( { 'values': [
+ this.model.revisions.indexOf( this.model.get( 'from' ) ),
+ this.model.revisions.indexOf( this.model.get( 'to' ) )
+ ] } );
+ } else {
+ this.settings.set( { 'value': this.model.revisions.indexOf( this.model.get( 'to' ) ) } );
+ }
</ins><span class="cx"> },
</span><span class="cx">
</span><ins>+ getSliderPosition: function( ui ){
+ return isRtl ? this.model.revisions.length - ui.value - 1 : ui.value;
+ },
+
</ins><span class="cx"> start: function( event, ui ) {
</span><del>- // Track the mouse position to enable smooth dragging, overrides default jquery ui step behaviour
- $( window ).mousemove( function( e ) {
- var sliderLeft = $( '.wp-slider' ).offset().left,
- sliderRight = sliderLeft + $( '.wp-slider' ).width();
</del><ins>+ if ( ! this.model.get( 'compareTwoMode' ) )
+ return;
</ins><span class="cx">
</span><del>- // Follow mouse movements, as long as handle remains inside slider
</del><ins>+ // 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.
</ins><span class="cx"> if ( e.clientX < sliderLeft ) {
</span><del>- $( ui.handle ).css( 'left', 0 ); // Mouse to left of slider
</del><ins>+ $( ui.handle ).css( 'left', 0 ); // Mouse to left of slider.
</ins><span class="cx"> } else if ( e.clientX > sliderRight ) {
</span><del>- $( ui.handle ).css( 'left', sliderRight - sliderLeft); // Mouse to right of slider
</del><ins>+ $( ui.handle ).css( 'left', sliderRight - sliderLeft); // Mouse to right of slider.
</ins><span class="cx"> } else {
</span><del>- $( ui.handle ).css( 'left', e.clientX - sliderLeft ); // Mouse in slider
</del><ins>+ $( ui.handle ).css( 'left', e.clientX - sliderLeft ); // Mouse in slider.
</ins><span class="cx"> }
</span><del>- } ); // End mousemove
</del><ins>+ } ); // End mousemove.
</ins><span class="cx"> },
</span><span class="cx">
</span><span class="cx"> slide: function( event, ui ) {
</span><del>- var attributes = {
- to: this.model.revisions.at( isRtl ? this.model.revisions.length - ui.value - 1 : ui.value ) // Reverse directions for Rtl
- };
</del><ins>+ var attributes;
+ // Compare two revisions mode
+ if ( 'undefined' !== typeof ui.values && this.model.get( 'compareTwoMode' ) ) {
+ // Prevent sliders from occupying same spot
+ if ( ui.values[1] === ui.values[0] )
+ return false;
</ins><span class="cx">
</span><del>- // If we're at the first revision, unset 'from'.
- if ( isRtl ? this.model.revisions.length - ui.value - 1 : ui.value ) // Reverse directions for Rtl
- attributes.from = this.model.revisions.at( isRtl ? this.model.revisions.length - ui.value - 2 : ui.value - 1 );
- else
- this.model.unset('from', { silent: true });
</del><ins>+ attributes = {
+ to: this.model.revisions.at( isRtl ? this.model.revisions.length - ui.values[1] - 1 : ui.values[1] ), // Reverse directions for RTL.
+ from: this.model.revisions.at( isRtl ? this.model.revisions.length - ui.values[0] - 1 : ui.values[0] ) // Reverse directions for RTL.
+ };
+ } else {
+ // Compare single revision mode
+ var sliderPosition = this.getSliderPosition( ui );
+ attributes = {
+ to: this.model.revisions.at( sliderPosition )
+ };
</ins><span class="cx">
</span><ins>+ // If we're at the first revision, unset 'from'.
+ if ( sliderPosition ) // Reverse directions for RTL.
+ attributes.from = this.model.revisions.at( sliderPosition - 1 );
+ else
+ this.model.unset('from', { silent: true });
+ }
</ins><span class="cx"> this.model.set( attributes );
</span><ins>+
+ // Maintain state history when dragging
+ this.model.revisionsRouter.navigateRoute( attributes.to.id, ( attributes.from ? attributes.from.id : 0 ) );
</ins><span class="cx"> },
</span><span class="cx">
</span><span class="cx"> stop: function( event, ui ) {
</span><del>- $( window ).unbind( 'mousemove' ); // Stop tracking the mouse
- // Reset settings pops handle back to the step position
</del><ins>+ if ( ! this.model.get( 'compareTwoMode' ) )
+ return;
+
+ // Stop tracking the mouse.
+ $( window ).unbind( 'mousemove' );
+
+ // Reset settings pops 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">@@ -486,6 +714,45 @@
</span><span class="cx"> }
</span><span class="cx"> });
</span><span class="cx">
</span><ins>+ // The revisions router
+ // takes URLs with #hash fragments and routes them
+ revisions.router.Router = Backbone.Router.extend({
+ model: null,
+
+ 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 = navigateTo + '2';
+ } else {
+ navigateTo = navigateTo + '1';
+ }
+ this.navigate( navigateTo );
+ },
+
+ gotoRevisionId: function( from, to, handles ) {
+ if ( '2' === handles ) {
+ this.model.set( { compareTwoMode: true } );
+ } else {
+ this.model.set( { compareTwoMode: false } );
+ }
+
+ if ( 'undefined' !== typeof this.model ) {
+ var selectedToRevision =
+ this.model.revisions.findWhere( { 'id': Number( to ) } ),
+ selectedFromRevision =
+ this.model.revisions.findWhere( { 'id': Number( from ) } );
+
+ this.model.set( {
+ to: selectedToRevision,
+ from: selectedFromRevision } );
+ }
+ }
+ });
+
</ins><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></span></pre></div>
<a id="trunkwpadminrevisionphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/revision.php (24548 => 24549)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/revision.php 2013-07-03 20:23:48 UTC (rev 24548)
+++ trunk/wp-admin/revision.php 2013-07-03 20:27:19 UTC (rev 24549)
</span><span class="lines">@@ -115,20 +115,11 @@
</span><span class="cx"> </div>
</span><span class="cx">
</span><span class="cx"> <script id="tmpl-revisions-frame" type="text/html">
</span><del>- <span class="spinner"></span>
</del><span class="cx"> <div class="revisions-control-frame"></div>
</span><span class="cx"> <div class="revisions-diff-frame"></div>
</span><span class="cx"> </script>
</span><span class="cx">
</span><del>-<script id="tmpl-revisions-controls" type="text/html">
-
- <div class="revision-toggle-compare-mode">
- <label>
- <input type="checkbox" class="compare-two-revisions" />
- <?php esc_attr_e( 'Compare two revisions' ); ?>
- </label>
- </div>
-
</del><ins>+<script id="tmpl-revisions-buttons" type="text/html">
</ins><span class="cx"> <div class="revisions-previous">
</span><span class="cx"> <input class="button" type="button" id="previous" value="<?php echo esc_attr_x( 'Previous', 'Button label for a previous revision' ); ?>" />
</span><span class="cx"> </div>
</span><span class="lines">@@ -138,19 +129,42 @@
</span><span class="cx"> </div>
</span><span class="cx"> </script>
</span><span class="cx">
</span><ins>+<script id="tmpl-revisions-tooltip" type="text/html">
+ <div class="ui-slider-tooltip ui-widget-content ui-corner-all ">
+ <# if ( 'undefined' !== typeof data && 'undefined' !== typeof data.author ) { #>
+ {{{ data.author.avatar }}} {{{ data.author.name }}},
+ {{{ data.timeAgo }}} <?php _e( 'ago' ); ?>
+ ({{{ data.dateShort }}})
+ <# } #>
+ </div>
+ <div class="arrow"></div>
+</script>
</ins><span class="cx">
</span><ins>+<script id="tmpl-revisions-checkbox" type="text/html">
+ <div class="revision-toggle-compare-mode">
+ <label>
+ <input type="checkbox" class="compare-two-revisions"
+ <#
+ if ( 'undefined' !== typeof data && data.model.attributes.compareTwoMode ) {
+ #> checked="checked"<#
+ }
+ #>
+ />
+ <?php esc_attr_e( 'Compare two revisions' ); ?>
+ </label>
+ </div>
+</script>
+
</ins><span class="cx"> <script id="tmpl-revisions-meta" type="text/html">
</span><span class="cx"> <div id="diff-header">
</span><span class="cx"> <div id="diff-header-from" class="diff-header">
</span><span class="cx"> <div id="diff-title-from" class="diff-title">
</span><del>- <strong>
- <?php _ex( 'From:', 'Followed by post revision info' ); ?></strong>
- <# if ( 'undefined' !== typeof data.from ) { #>
- {{{ data.from.attributes.author.avatar }}} {{{ data.from.attributes.author.name }}},
- {{{ data.from.attributes.timeAgo }}} <?php _e( 'ago' ); ?>
- ({{{ data.from.attributes.dateShort }}})
- <# } #>
-
</del><ins>+ <strong><?php _ex( 'From:', 'Followed by post revision info' ); ?></strong>
+ <# if ( 'undefined' !== typeof data.from ) { #>
+ {{{ data.from.attributes.author.avatar }}} {{{ data.from.attributes.author.name }}},
+ {{{ data.from.attributes.timeAgo }}} <?php _e( 'ago' ); ?>
+ ({{{ data.from.attributes.dateShort }}})
+ <# } #>
</ins><span class="cx"> </div>
</span><span class="cx"> <div class="clear"></div>
</span><span class="cx"> </div>
</span><span class="lines">@@ -158,12 +172,12 @@
</span><span class="cx"> <div id="diff-header-to" class="diff-header">
</span><span class="cx"> <div id="diff-title-to" class="diff-title">
</span><span class="cx"> <strong><?php _ex( 'To:', 'Followed by post revision info' ); ?></strong>
</span><del>- <# if ( 'undefined' !== typeof data.to ) { #>
- {{{ data.to.attributes.author.avatar }}} {{{ data.to.attributes.author.name }}},
- {{{ data.to.attributes.timeAgo }}} <?php _e( 'ago' ); ?>
- ({{{ data.to.attributes.dateShort }}})
- <# } #>
- </div>
</del><ins>+ <# if ( 'undefined' !== typeof data.to ) { #>
+ {{{ data.to.attributes.author.avatar }}} {{{ data.to.attributes.author.name }}},
+ {{{ data.to.attributes.timeAgo }}} <?php _e( 'ago' ); ?>
+ ({{{ data.to.attributes.dateShort }}})
+ <# } #>
+ </div>
</ins><span class="cx">
</span><span class="cx"> <input type="button" id="restore-revision" class="button button-primary" data-restore-link="{{{ data.restoreLink }}}" value="<?php esc_attr_e( 'Restore This Revision' )?>" />
</span><span class="cx"> </div>
</span><span class="lines">@@ -177,50 +191,6 @@
</span><span class="cx"> <# }); #>
</span><span class="cx"> </script>
</span><span class="cx">
</span><del>-<script id="tmpl-revisions-diff-old" type="text/html">
- <div id="toggle-revision-compare-mode">
- <label>
- <input type="checkbox" id="compare-two-revisions" />
- <?php esc_attr_e( 'Compare two revisions' ); ?>
- </label>
- </div>
</del><span class="cx">
</span><del>- <div id="diff-header">
- <div id="diff-header-from" class="diff-header">
- <div id="diff-title-from" class="diff-title">
- <strong><?php _ex( 'From:', 'Followed by post revision info' ); ?></strong> {{{ data.titleFrom }}}
- </div>
- <div class="clear"></div>
- </div>
-
- <div id="diff-header-to" class="diff-header">
- <div id="diff-title-to" class="diff-title">
- <strong><?php _ex( 'To:', 'Followed by post revision info' ); ?></strong> {{{ data.titleTo }}}
- </div>
-
- <input type="button" id="restore-revision" class="button button-primary" data-restore-link="{{{ data.restoreLink }}}" value="<?php esc_attr_e( 'Restore This Revision' )?>" />
- <div class="clear"></div>
- </div>
- </div>
-
- <div id="diff-table">{{{ data.diff }}}</div>
-</script>
-
-<script id="tmpl-revision-interact-old" type="text/html">
- <div id="diff-previous-revision">
- <input class="button" type="button" id="previous" value="<?php echo esc_attr_x( 'Previous', 'Button label for a previous revision' ); ?>" />
- </div>
-
- <div id="diff-next-revision">
- <input class="button" type="button" id="next" value="<?php echo esc_attr_x( 'Next', 'Button label for a next revision' ); ?>" />
- </div>
-
-</script>
-
-<script id="tmpl-revision-ticks" type="text/html">
- <div class="revision-tick completed-{{{ data.completed }}} scope-of-changes-{{{ data.scopeOfChanges }}}">
- <span class="ui-slider-tooltip ui-widget-content ui-corner-all hidden"></span>
- </div>
-</script>
</del><span class="cx"> <?php
</span><span class="cx"> require_once( './admin-footer.php' );
</span></span></pre>
</div>
</div>
</body>
</html>