From 13c63d211a84466409fe126c313718c6e868bc65 Mon Sep 17 00:00:00 2001 From: Mark Jaquith Date: Mon, 22 Jul 2013 05:05:45 +0000 Subject: [PATCH] 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 --- wp-admin/css/colors-classic.css | 19 ++++-- wp-admin/css/colors-fresh.css | 18 +++-- wp-admin/css/wp-admin-rtl.css | 36 +++++++--- wp-admin/css/wp-admin.css | 115 ++++++++++++++++++++------------ wp-admin/includes/revision.php | 11 ++- wp-admin/js/revisions.js | 74 +++++++++++++++----- wp-admin/revision.php | 68 +++++++++++-------- 7 files changed, 231 insertions(+), 110 deletions(-) diff --git a/wp-admin/css/colors-classic.css b/wp-admin/css/colors-classic.css index 703beef660..2dbbb30a50 100644 --- a/wp-admin/css/colors-classic.css +++ b/wp-admin/css/colors-classic.css @@ -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)); diff --git a/wp-admin/css/colors-fresh.css b/wp-admin/css/colors-fresh.css index a5733d4189..92d8332daf 100644 --- a/wp-admin/css/colors-fresh.css +++ b/wp-admin/css/colors-fresh.css @@ -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 { diff --git a/wp-admin/css/wp-admin-rtl.css b/wp-admin/css/wp-admin-rtl.css index 2c2272aaad..f0145a805c 100644 --- a/wp-admin/css/wp-admin-rtl.css +++ b/wp-admin/css/wp-admin-rtl.css @@ -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; diff --git a/wp-admin/css/wp-admin.css b/wp-admin/css/wp-admin.css index f975612f61..d3f33f4e1c 100644 --- a/wp-admin/css/wp-admin.css +++ b/wp-admin/css/wp-admin.css @@ -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, diff --git a/wp-admin/includes/revision.php b/wp-admin/includes/revision.php index 638edeff9e..ec9e7dc24e 100644 --- a/wp-admin/includes/revision.php +++ b/wp-admin/includes/revision.php @@ -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 ) { diff --git a/wp-admin/js/revisions.js b/wp-admin/js/revisions.js index d122f535b7..1f08acac03 100644 --- a/wp-admin/js/revisions.js +++ b/wp-admin/js/revisions.js @@ -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() { diff --git a/wp-admin/revision.php b/wp-admin/revision.php index 602adc9dfd..181a4b89bc 100644 --- a/wp-admin/revision.php +++ b/wp-admin/revision.php @@ -122,20 +122,23 @@ require_once( './admin-header.php' );