Revisions: Pinned controls, layout tweaks, copy tweaks, misc.

* When you scroll down the diff view, the controls will pin to the top.
* The revisions meta view was cleaned up. Copy changes.
* Loading indicator in the center of the screen (so it follows as you scroll).
* Tooltips "flip" when you cross the center line, so that they don't hit the container edge and wrap for later revisions.
* The "Restore" button's inactive state is handled on render, instead of after.
* Make sure we always have a current revision, even if the timestamp doesn't work out on the most recent one.

See #24804. Props markjaquith, nacin, ocean90, aaroncampbell.

git-svn-id: http://core.svn.wordpress.org/trunk@24761 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Mark Jaquith 2013-07-22 05:05:45 +00:00
parent 062928d842
commit 13c63d211a
7 changed files with 231 additions and 110 deletions

View File

@ -164,7 +164,7 @@ textarea.disabled {
color: #fff;
}
#diff-header,
.revisions-meta,
.widget .widget-top,
.postbox h3,
.stuffbox h3,
@ -1481,24 +1481,32 @@ table.diff .diff-addedline ins {
background-color: #afa;
}
#diff-header {
.revisions-meta {
border: 1px solid #d1e5ee;
}
.revisions-controls {
background: #fff;
background: -webkit-gradient(linear, left bottom, left top, color-stop(0%,rgba(255,255,255,1)), color-stop(30px,rgba(255,255,255,1)), color-stop(100%,rgba(255,255,255,1)));
background: -webkit-linear-gradient(bottom, rgba(255,255,255,0) 0%, rgba(255,255,255,1) 30px, rgba(255,255,255,1) 100%);
background: -moz-linear-gradient(bottom, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 30px, rgba(255,255,255,1) 100%);
background: -o-linear-gradient(bottom, rgba(255,255,255,0) 0%, rgba(255,255,255,1) 30px, rgba(255,255,255,1) 100%);
background: linear-gradient(to top, rgba(255,255,255,0) 0%, rgba(255,255,255,1) 30px, rgba(255,255,255,1) 100%);
}
.revisions-tooltip,
.revisions-tooltip-arrow span {
border-color: #d1e5ee;
background-color: #fff;
}
#diff-title-to strong {
color: #08a;
.revisions-tickmarks > div {
border-color: #d1e5ee;
}
/* jQuery UI Slider */
.wp-slider.ui-slider {
border-color: #d1e5ee;
background: #eff8ff;
}
.wp-slider .ui-slider-handle {
@ -1507,7 +1515,6 @@ table.diff .diff-addedline ins {
}
.wp-slider .ui-slider-handle {
border-color: #ccc;
border-color: #d0dfe9;
background: #eff8ff;
background-image: -webkit-gradient(linear, left bottom, left top, from(#eff8ff), to(#fff));

View File

@ -164,7 +164,7 @@ textarea.disabled {
color: #fff;
}
#diff-header,
.revisions-meta,
.widget .widget-top,
.postbox h3,
.stuffbox h3,
@ -1375,10 +1375,19 @@ table.diff .diff-addedline ins {
background-color: #afa;
}
#diff-header {
.revisions-meta {
border: 1px solid #dfdfdf;
}
.revisions-controls {
background: #fff;
background: -webkit-gradient(linear, left bottom, left top, color-stop(0%,rgba(255,255,255,1)), color-stop(30px,rgba(255,255,255,1)), color-stop(100%,rgba(255,255,255,1)));
background: -webkit-linear-gradient(bottom, rgba(255,255,255,0) 0%, rgba(255,255,255,1) 30px, rgba(255,255,255,1) 100%);
background: -moz-linear-gradient(bottom, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 30px, rgba(255,255,255,1) 100%);
background: -o-linear-gradient(bottom, rgba(255,255,255,0) 0%, rgba(255,255,255,1) 30px, rgba(255,255,255,1) 100%);
background: linear-gradient(to top, rgba(255,255,255,0) 0%, rgba(255,255,255,1) 30px, rgba(255,255,255,1) 100%);
}
.revisions-tooltip,
.revisions-tooltip-arrow span {
border-color: #d7d7d7;
@ -1389,14 +1398,9 @@ table.diff .diff-addedline ins {
border-color: #aaa;
}
#diff-title-to strong {
color: #08a;
}
/* jQuery UI Slider */
.wp-slider.ui-slider {
border-color: #d7d7d7;
background: transparent;
}
.wp-slider .ui-slider-handle {

View File

@ -976,6 +976,14 @@ th.sorted a span {
padding: 9px 0 0 9px;
}
.revisions .loading-indicator {
margin-right: -90px;
}
body.folded .revisions .loading-indicator {
margin-right: -32px;
}
.revisions-next {
float: left;
}
@ -984,10 +992,6 @@ th.sorted a span {
float: right;
}
#diff-header {
padding: 5px 5px 5px 200px;
}
.diff-title {
float: right;
}
@ -1004,7 +1008,7 @@ th.sorted a span {
margin-right: 5px;
}
.diff-header > input.restore-revision {
.diff-meta > input.restore-revision {
margin-left: 0;
margin-right: 10px;
}
@ -1027,11 +1031,11 @@ th.sorted a span {
.revisions-tooltip {
margin-left: 0;
margin-right: -70px;
-webkit-transition: right 15ms;
-moz-transition: right 15ms;
-ms-transition: right 15ms;
-o-transition: right 15ms;
transition: right 15ms;
}
.revisions-tooltip.flipped {
margin-right: 0;
margin-left: -70px;
}
.ie8 .revisions-tooltip {
@ -1044,10 +1048,22 @@ th.sorted a span {
margin-right: 35px;
}
.revisions-tooltip.flipped .revisions-tooltip-arrow {
margin-right: 0;
margin-left: 35px;
right: auto;
left: 0;
}
.revisions-tooltip-arrow > span {
right: 20px;
}
.revisions-tooltip.flipped .revisions-tooltip-arrow > span {
right: auto;
left: 20px;
}
.revisions-tooltip img {
float: right;
margin: 2px 0 0 5px;

View File

@ -3519,6 +3519,7 @@ td.plugin-title p {
.revisions-controls {
padding-top: 40px;
height: 100px;
z-index: 1;
}
.revisions-controls input[type="checkbox"] {
@ -3527,6 +3528,12 @@ td.plugin-title p {
vertical-align: text-bottom;
}
.revisions.pinned .revisions-controls {
position: fixed;
top: 0;
padding-bottom: 10px;
}
.revisions-tickmarks {
position: relative;
margin: 0 auto;
@ -3571,11 +3578,12 @@ td.plugin-title p {
}
.revisions .loading-indicator {
position: absolute;
position: fixed;
vertical-align: middle;
opacity: 0;
width: 100%;
top: 3em;
top: 50%;
margin-left: -90px;
-webkit-transition: opacity 0.5s;
-moz-transition: opacity 0.5s;
-ms-transition: opacity 0.5s;
@ -3584,6 +3592,10 @@ td.plugin-title p {
filter: alpha(opacity=0); /* ie8 and earlier */
}
body.folded .revisions .loading-indicator {
margin-left: -32px;
}
.revisions .loading-indicator span.spinner {
display: block;
margin: 0 auto;
@ -3623,10 +3635,22 @@ td.plugin-title p {
}
.comparing-two-revisions .revisions-previous,
.comparing-two-revisions .revisions-next {
.comparing-two-revisions .revisions-next,
.revisions-meta .diff-meta-to strong {
display: none;
}
.revisions-controls .author-card .date {
color: #777;
}
.revisions-controls .author-card .author-name {
font-weight: bold;
}
.comparing-two-revisions .diff-meta-to strong {
display: block;
}
.revisions-previous,
.revisions-next {
position: relative;
@ -3689,49 +3713,50 @@ table.diff .diff-addedline ins {
text-decoration: none;
}
#diff-title-to strong {
display: inline;
}
#diff-header {
.diff-meta {
-webkit-border-radius: 3px;
border-radius: 3px;
padding: 5px;
clear: both;
}
.diff-header {
min-height: 35px;
line-height: 35px;
}
.diff-title {
float: left;
min-height: 32px;
}
.diff-title strong {
font-size: 14px;
width: 60px;
line-height: 32px;
min-width: 60px;
text-align: right;
float: left;
margin-right: 5px;
}
.diff-title img {
.revisions-controls .author-card .avatar,
.revisions-controls .author-card .author-info {
float: left;
margin-left: 6px;
margin-right: 6px;
}
.revisions-controls .author-card .byline {
display: block;
font-size: 12px;
}
.revisions-controls .author-card .avatar {
vertical-align: middle;
margin-left: 5px;
}
.diff-header > input.restore-revision {
margin-left: 10px;
.diff-meta input.restore-revision {
float: right;
margin-left: 6px;
margin-right: 6px;
margin-top: 4px;
}
#diff-header-from {
.diff-meta-from {
display: none;
}
.comparing-two-revisions #diff-title-from,
.comparing-two-revisions #diff-header-from {
.comparing-two-revisions .diff-meta-from {
display: block;
}
@ -3740,31 +3765,27 @@ table.diff .diff-addedline ins {
bottom: 105px;
margin-right: 0;
margin-left: -70px;
line-height: 28px;
z-index: 1;
max-width: 350px;
min-width: 130px;
padding: 4px;
padding: 8px 4px;
display: none;
opacity: 0;
-webkit-transition: left 15ms;
-moz-transition: left 15ms;
-ms-transition: left 15ms;
-o-transition: left 15ms;
transition: left 15ms;
}
.revisions-tooltip.flipped {
margin-left: 0;
margin-right: -70px;
}
.revisions.pinned .revisions-tooltip {
display: none !important;
}
.comparing-two-revisions .revisions-tooltip {
bottom: 145px;
}
.revisions-tooltip img {
float: left;
margin: 2px 5px 0 0;
padding: 0;
vertical-align: middle;
}
.revisions-tooltip-arrow {
width: 70px;
height: 15px;
@ -3776,6 +3797,13 @@ table.diff .diff-addedline ins {
z-index: 10000;
}
.revisions-tooltip.flipped .revisions-tooltip-arrow {
margin-left: 0;
margin-right: 35px;
left: auto;
right: 0;
}
.revisions-tooltip-arrow > span {
content: "";
position: absolute;
@ -3790,10 +3818,15 @@ table.diff .diff-addedline ins {
tranform: rotate(45deg);
}
.revisions-tooltip.flipped .revisions-tooltip-arrow > span {
left: auto;
right: 20px;
}
.ie8 .revisions-tooltip-arrow > span {
left: 14px;
top: -25px;
-ms-filter: "progid:DXImageTransform.Microsoft.Matrix(SizingMethod='auto expand', M11=0.7071067811865476, M12=-0.7071067811865475, M21=0.7071067811865475, M22=0.7071067811865476)"; /* IE8 */
-ms-filter: "progid:DXImageTransform.Microsoft.Matrix(SizingMethod='auto expand', M11=0.7071067811865476, M12=-0.7071067811865475, M21=0.7071067811865475, M22=0.7071067811865476)";
}
.revisions-tooltip,

View File

@ -99,19 +99,19 @@ function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null
foreach ( $revisions as $revision ) {
$modified = strtotime( $revision->post_modified );
$modified_gmt = strtotime( $revision->post_modified_gmt );
$restore_link = wp_nonce_url(
$restore_link = str_replace( '&', '&', wp_nonce_url(
add_query_arg(
array( 'revision' => $revision->ID,
'action' => 'restore' ),
admin_url( 'revision.php' )
),
"restore-post_{$revision->ID}"
);
) );
if ( ! isset( $authors[ $revision->post_author ] ) ) {
$authors[ $revision->post_author ] = array(
'id' => (int) $revision->post_author,
'avatar' => $show_avatars ? get_avatar( $revision->post_author, 24 ) : '',
'avatar' => $show_avatars ? get_avatar( $revision->post_author, 32 ) : '',
'name' => get_the_author_meta( 'display_name', $revision->post_author ),
);
}
@ -142,6 +142,11 @@ function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null
);
}
// If a post has been saved since the last revision (no revisioned fields were changed)
// we may not have a "current" revision. Mark the latest revision as "current".
if ( empty( $current_id ) )
$revisions[ $revision->ID ]['current'] = true;
// Now, grab the initial diff
$compare_two_mode = is_numeric( $from );
if ( ! $compare_two_mode ) {

View File

@ -531,6 +531,8 @@ window.wp = window.wp || {};
className: 'revisions-controls',
initialize: function() {
_.bindAll( this, 'setWidth' );
// Add the button view
this.views.add( new revisions.view.Buttons({
model: this.model
@ -573,7 +575,40 @@ window.wp = window.wp || {};
this.views.add( new revisions.view.Meta({
model: this.model
}) );
},
ready: function() {
this.top = this.$el.offset().top;
this.window = $(window);
this.window.on( 'scroll.wp.revisions', {controls: this}, function(e) {
var controls = e.data.controls;
var container = controls.$el.parent();
var scrolled = controls.window.scrollTop();
var frame = controls.views.parent;
if ( scrolled >= controls.top ) {
if ( ! frame.$el.hasClass('pinned') ) {
controls.setWidth();
container.css('height', container.height() + 'px' );
controls.window.on('resize.wp.revisions.pinning click.wp.revisions.pinning', {controls: controls}, function(e) {
e.data.controls.setWidth();
});
}
frame.$el.addClass('pinned');
} else if ( frame.$el.hasClass('pinned') ) {
controls.window.off('.wp.revisions.pinning');
controls.$el.css('width', 'auto');
frame.$el.removeClass('pinned');
container.css('height', 'auto');
controls.top = controls.$el.offset().top;
} else {
controls.top = controls.$el.offset().top;
}
});
},
setWidth: function() {
this.$el.css('width', this.$el.parent().width() + 'px');
}
});
@ -592,15 +627,18 @@ window.wp = window.wp || {};
tick = this.$('div:nth-of-type(' + index + ')');
offset = tick.allPositions();
elWidth = tick.outerWidth();
// adjust
_.extend( offset, {
right: offset.right + elWidth + 1,
left: offset.left + elWidth + 1
rightPlusWidth: offset.right,
leftPlusWidth: offset.left
});
} else {
// Normal tick
tick = this.$('div:nth-of-type(' + (index + 1) + ')');
offset = tick.allPositions();
_.extend( offset, {
leftPlusWidth: offset.left + tick.outerWidth() + 1,
rightPlusWidth: offset.right + tick.outerWidth() + 1
});
}
this.model.set({ offset: offset });
},
@ -626,20 +664,15 @@ window.wp = window.wp || {};
},
initialize: function() {
this.listenTo( this.model, 'update:revisions', this.ready );
this.listenTo( this.model, 'update:revisions', this.render );
},
prepare: function() {
return this.model.toJSON();
},
ready: function() {
this.$('.restore-revision').prop( 'disabled', this.model.get('to').get('current') );
},
restoreRevision: function() {
var restoreUrl = this.model.get('to').attributes.restoreUrl.replace(/&/g, '&');
document.location = restoreUrl;
document.location = this.model.get('to').attributes.restoreUrl;
}
});
@ -677,7 +710,6 @@ window.wp = window.wp || {};
revisions.view.Tooltip = wp.Backbone.View.extend({
className: 'revisions-tooltip',
template: wp.template('revisions-tooltip'),
direction: isRtl ? 'right' : 'left',
initialize: function( options ) {
this.listenTo( this.model, 'change:offset', this.render );
@ -690,10 +722,20 @@ window.wp = window.wp || {};
},
render: function() {
var css = {};
var direction, directionVal, flipped, css = {}, position = this.model.revisions.indexOf( this.model.get('revision') ) + 1;
flipped = ( position / this.model.revisions.length ) > 0.5;
if ( isRtl ) {
direction = flipped ? 'left' : 'right';
directionVal = flipped ? 'leftPlusWidth' : direction;
} else {
direction = flipped ? 'right' : 'left';
directionVal = flipped ? 'rightPlusWidth' : direction;
}
otherDirection = 'right' === direction ? 'left': 'right';
wp.Backbone.View.prototype.render.apply( this, arguments );
css[this.direction] = this.model.get('offset')[this.direction] + 'px';
this.$el.css( css );
css[direction] = this.model.get('offset')[directionVal] + 'px';
css[otherDirection] = '';
this.$el.toggleClass( 'flipped', flipped ).css( css );
},
visible: function() {
@ -716,8 +758,8 @@ window.wp = window.wp || {};
template: wp.template('revisions-buttons'),
events: {
'click #next': 'nextRevision',
'click #previous': 'previousRevision'
'click .revisions-next .button': 'nextRevision',
'click .revisions-previous .button': 'previousRevision'
},
initialize: function() {

View File

@ -122,20 +122,23 @@ require_once( './admin-header.php' );
<script id="tmpl-revisions-buttons" type="text/html">
<div class="revisions-previous">
<input class="button" type="button" id="previous" value="<?php echo esc_attr_x( 'Previous', 'Button label for a previous revision' ); ?>" />
<input class="button" type="button" value="<?php echo esc_attr_x( 'Previous', 'Button label for a previous revision' ); ?>" />
</div>
<div class="revisions-next">
<input class="button" type="button" id="next" value="<?php echo esc_attr_x( 'Next', 'Button label for a next revision' ); ?>" />
<input class="button" type="button" value="<?php echo esc_attr_x( 'Next', 'Button label for a next revision' ); ?>" />
</div>
</script>
<script id="tmpl-revisions-tooltip" type="text/html">
<div class="revisions-tooltip-content">
<div class="author-card">
<# if ( 'undefined' !== typeof data && 'undefined' !== typeof data.author ) { #>
{{{ data.author.avatar }}} {{ data.author.name }},
{{ data.timeAgo }}
({{ data.dateShort }})
{{{ data.author.avatar }}}
<div class="author-info">
<span class="byline">Edit by <span class="author-name">{{ data.author.name }}</span></span>
<span class="time-ago">{{ data.timeAgo }}</span>
<span class="date">({{ data.dateShort }})</span>
</div>
<# } #>
</div>
<div class="revisions-tooltip-arrow"><span></span></div>
@ -157,30 +160,41 @@ require_once( './admin-header.php' );
</script>
<script id="tmpl-revisions-meta" type="text/html">
<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>
<# if ( 'undefined' !== typeof data.from ) { #>
{{{ data.from.attributes.author.avatar }}} {{ data.from.attributes.author.name }},
{{ data.from.attributes.timeAgo }}
({{ data.from.attributes.dateShort }})
<# } #>
<div class="diff-meta diff-meta-from">
<div class="diff-title">
<strong><?php _ex( 'From:', 'Followed by post revision info' ); ?></strong>
<# if ( 'undefined' !== typeof data.from ) { #>
<div class="author-card">
{{{ data.from.attributes.author.avatar }}}
<div class="author-info">
<span class="byline"><?php printf( __( 'Revision by %s' ),
'<span class="author-name">{{ data.to.attributes.author.name }}</span>' ); ?></span>
<span class="time-ago">{{ data.from.attributes.timeAgo }}</span>
<span class="date">({{ data.from.attributes.dateShort }})</span>
</div>
</div>
<div class="clear"></div>
<# } #>
</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>
<# if ( 'undefined' !== typeof data.to ) { #>
{{{ data.to.attributes.author.avatar }}} {{ data.to.attributes.author.name }},
{{ data.to.attributes.timeAgo }}
({{ data.to.attributes.dateShort }})
<# } #>
</div>
<input type="button" class="restore-revision button button-primary" data-restore-link="{{{ data.restoreLink }}}" value="<?php esc_attr_e( 'Restore This Revision' )?>" />
<div class="diff-meta diff-meta-to">
<div class="diff-title">
<strong><?php _ex( 'To:', 'Followed by post revision info' ); ?></strong>
<# if ( 'undefined' !== typeof data.to ) { #>
<div class="author-card">
{{{ data.to.attributes.author.avatar }}}
<div class="author-info">
<span class="byline"><?php printf( __( 'Revision by %s' ),
'<span class="author-name">{{ data.to.attributes.author.name }}</span>' ); ?></span>
<span class="time-ago">{{ data.to.attributes.timeAgo }}</span>
<span class="date">({{ data.to.attributes.dateShort }})</span>
</div>
<# } #>
<input
<# if ( data.to.attributes.current ) { #>
disabled="disabled"
<# } #>
type="button" class="restore-revision button button-primary" data-restore-link="{{{ data.restoreLink }}}" value="<?php esc_attr_e( 'Restore This Revision' ); ?>" />
</div>
</div>
</script>