diff --git a/wp-admin/css/colors-fresh.css b/wp-admin/css/colors-fresh.css index c97c067896..ab1551c91e 100644 --- a/wp-admin/css/colors-fresh.css +++ b/wp-admin/css/colors-fresh.css @@ -1385,6 +1385,15 @@ table.diff .diff-addedline ins { background-color: #fff; } + +.revisions-tickmarks { + background-color: #f7f7f7; +} + +.revisions-tickmarks > div { + background-color: #ccc; +} + #diff-title-to strong { color: #08a; } @@ -1392,7 +1401,7 @@ table.diff .diff-addedline ins { /* jQuery UI Slider */ .wp-slider.ui-slider { border-color: #d7d7d7; - background: #f7f7f7; + 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 c4649baf23..4027e818df 100644 --- a/wp-admin/css/wp-admin-rtl.css +++ b/wp-admin/css/wp-admin-rtl.css @@ -1019,12 +1019,20 @@ th.sorted a span { float: left; } -.ui-tooltip-content img { +.revisions img { float: right; margin-right: 0; margin-left: 5px; } +.revisions-tooltip { + margin-left: -185px; +} + +.revisions-tooltip-arrow { + margin-left: 150px; +} + /*------------------------------------------------------------------------------ 11.3 - Featured Images ------------------------------------------------------------------------------*/ diff --git a/wp-admin/css/wp-admin.css b/wp-admin/css/wp-admin.css index dcfd574b0f..f3e0fd60ae 100644 --- a/wp-admin/css/wp-admin.css +++ b/wp-admin/css/wp-admin.css @@ -3505,6 +3505,22 @@ td.plugin-title p { height: 100px; } +.revisions-tickmarks { + position: relative; + margin: 0 auto 0; + height: 0.8em; + z-index: 2; + top: 7px; +} + +.revisions-tickmarks > div { + height: 0.8em; + width: 1px; + float: left; + position: relative; + z-index: 10002; +} + .comparing-two-revisions .revisions-controls { height: 140px; } @@ -3534,7 +3550,8 @@ td.plugin-title p { .wp-slider { width: 70%; - margin: 6px auto 0; + margin: 0 auto 0; + top: -3px; } /* Revision meta box */ diff --git a/wp-admin/js/revisions.js b/wp-admin/js/revisions.js index c1d44256a1..680d487990 100644 --- a/wp-admin/js/revisions.js +++ b/wp-admin/js/revisions.js @@ -280,7 +280,10 @@ window.wp = window.wp || {}; }, updateCompareTwoMode: function() { - this.$el.toggleClass( 'comparing-two-revisions' ); + if ( this.model.get( 'compareTwoMode' ) ) + this.$el.addClass( 'comparing-two-revisions' ); + else + this.$el.removeClass( 'comparing-two-revisions' ); } }); @@ -307,6 +310,11 @@ window.wp = window.wp || {}; }); this.views.add( tooltip ); + // Add the Tickmarks view + this.views.add( new revisions.view.Tickmarks({ + model: this.model + })); + // Add the Slider view with a reference to the tooltip view this.views.add( new revisions.view.Slider({ model: this.model, @@ -317,6 +325,39 @@ window.wp = window.wp || {}; this.views.add( new revisions.view.Meta({ model: this.model }) ); + + } + }); + + // The tickmarks view + // This contains the slider tickmarks. + revisions.view.Tickmarks = wp.Backbone.View.extend({ + tagName: 'div', + className: 'revisions-tickmarks', + template: wp.template('revisions-tickmarks'), + + numberOfTickmarksSet: function() { + var tickCount = this.model.revisions.length - 1, // One tickmark per model + sliderWidth = $( '.wp-slider' ).parent().width() * 0.7, // Width of slider is 70% of container (reset on resize) + tickWidth = Math.floor( sliderWidth / tickCount ), // Divide width by # of tickmarks, round down + newSiderWidth = ( ( tickWidth + 1 ) * tickCount ) + 1, // Calculate the actual width + tickNumber; + + $( '.wp-slider' ).css( 'width', newSiderWidth ); // Reset the slider width to match the calculated tick size + this.$el.css( 'width', newSiderWidth ); // Match the tickmark div width + + for ( tickNumber = 0; tickNumber <= tickCount; tickNumber++ ){ + this.$el.append( '
' ); + } + }, + + ready: function() { + var self = this; + self.numberOfTickmarksSet(); + $( window ).on( 'resize', _.debounce( function() { + self.$el.html( '' ); + self.numberOfTickmarksSet(); + }, 50 ) ); } }); @@ -511,8 +552,8 @@ window.wp = window.wp || {}; events: { 'mousemove' : 'mousemove', - 'mouseenter' : 'mouseenter', - 'mouseleave' : 'mouseleave' + 'mouseleave' : 'mouseleave', + 'mouseenter' : 'mouseenter' }, initialize: function( options ) { @@ -559,35 +600,37 @@ window.wp = window.wp || {}; }, 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 ); + var tickCount = this.model.revisions.length - 1, // One tickmark per model + sliderLeft = Math.ceil( this.$el.offset().left ), // Left edge of slider + sliderWidth = this.$el.width(), // Width of slider + tickWidth = Math.floor( sliderWidth / tickCount ), // Calculated width of tickmark + actualX = e.clientX - sliderLeft, // Offset of mouse position in slider + currentModelIndex = Math.floor( ( actualX + tickWidth / 2 ) / tickWidth ), // Calculate the model index + tooltipPosition = sliderLeft + 2 + currentModelIndex * tickWidth; // Stick tooltip to tickmark // Reverse direction in RTL mode. if ( isRtl ) - hoveringAt = this.model.revisions.length - hoveringAt - 1; + currentModelIndex = this.model.revisions.length - currentModelIndex - 1; - // Ensure sane value for hoveringAt. - if ( hoveringAt < 0 ) - hoveringAt = 0; - else if ( hoveringAt >= this.model.revisions.length ) - hoveringAt = this.model.revisions.length - 1; + // Ensure sane value for currentModelIndex. + if ( currentModelIndex < 0 ) + currentModelIndex = 0; + else if ( currentModelIndex >= this.model.revisions.length ) + currentModelIndex = this.model.revisions.length - 1; // Update the tooltip model - this.tooltip.model.set( 'revision', this.model.revisions.at( hoveringAt ) ); - this.tooltip.model.set( 'position', e.clientX ); - }, - - mouseenter: function( e ) { - this.tooltip.show(); + this.tooltip.model.set( 'revision', this.model.revisions.at( currentModelIndex ) ); + this.tooltip.model.set( 'position', tooltipPosition ); }, mouseleave: function( e ) { this.tooltip.hide(); }, + mouseenter: function( e ) { + this.tooltip.show(); + }, + updateSliderSettings: function() { if ( this.model.get( 'compareTwoMode' ) ) { var leftValue, rightValue; diff --git a/wp-admin/revision.php b/wp-admin/revision.php index bbf751bd67..b7923f7542 100644 --- a/wp-admin/revision.php +++ b/wp-admin/revision.php @@ -152,6 +152,9 @@ require_once( './admin-header.php' ); + +