Ticket #23935: 23935-improved-tick-marks.diff
File 23935-improved-tick-marks.diff, 11.1 KB (added by , 12 years ago) |
---|
-
wp-admin/js/revisions.js
44 44 slider: null, // the slider instance 45 45 46 46 constructor: function() { 47 var self = this; 47 48 this.slider = new revisions.view.Slider(); 49 48 50 if ( null === this.revisions ) { 49 51 this.revisions = new Revisions(); // set up collection 50 52 this.startRightModelLoading(); 51 53 52 var self = this;53 54 this.revisions.fetch({ // load revision data 54 55 success: function() { 55 56 self.stopRightModelLoading(); … … 62 63 loadDiffs: function( models ) { 63 64 var self = this, 64 65 revisionsToLoad = models.where( { completed: false } ), 65 delay = 0; 66 delay = 0, 67 totalChanges; 66 68 67 69 // match slider to passed revision_id 68 70 _.each( revisionsToLoad, function( revision ) { … … 85 87 86 88 self.tickmarkView.render(); 87 89 88 vartotalChanges = model.get( 'linesAdded' ) + model.get( 'linesDeleted' ),90 totalChanges = model.get( 'linesAdded' ) + model.get( 'linesDeleted' ), 89 91 scopeOfChanges = 'vsmall'; 90 92 91 93 // Note: hard coded scope of changes … … 195 197 self.slider.refresh({ 196 198 'max': self.revisions.length 197 199 }); 198 // ensure right handle not beyond length, in particular if viewing autosaves is switched from on to off 199 // the number of models in the collection might get shorter, this ensures right handle is not beyond last model 200 // ensure right handle not beyond length 200 201 if ( self.rightDiff > self.revisions.length ) 201 202 self.rightDiff = self.revisions.length; 202 203 }, … … 411 412 refresh: function( options, slide ) { 412 413 $( '#diff-slider' ).slider( 'option', options ); 413 414 414 // reset all of the slider tooltips during a refresh, but not on prev/next button actions415 if ( ! slide )416 $( 'a.ui-slider-handle' ).html( '<span class="ui-slider-tooltip ui-widget-content ui-corner-all"></span>' );417 418 415 // Triggers the slide event 419 416 if ( slide ) 420 417 $( '#diff-slider' ).trigger( 'slide' ); … … 451 448 model: Revision, 452 449 453 450 resetTicks: function() { 454 var sliderMax = Diff.slider.option( 'max' ); 455 var sliderWidth = Diff.slider.width(); 456 var adjustMax = Diff.singleRevision ? 0 : 1; 457 var tickWidth = Math.floor( sliderWidth / ( sliderMax - adjustMax ) ); 451 var sliderMax, sliderWidth, adjustMax, tickWidth, tickCount = 0, aTickWidth, tickMargin, self = this; 452 sliderMax = Diff.slider.option( 'max' ); 453 sliderWidth = Diff.slider.width(); 454 adjustMax = Diff.singleRevision ? 0 : 1; 455 tickWidth = Math.floor( sliderWidth / ( sliderMax - adjustMax ) ); 456 tickWidth = (tickWidth > 50 ) ? 50 : tickWidth; // set minimum and maximum widths for tick marks 457 tickWidth = (tickWidth < 10 ) ? 10 : tickWidth; 458 sliderWidth = tickWidth * (sliderMax - adjustMax ) + 2; //calculate the slider width 459 aTickWidth = $( '.revision-tick' ).width(); 458 460 459 // TODO: adjust right margins for wider ticks so they stay centered on handle stop point 461 if ( tickWidth !== aTickWidth ) { // is the width already set correctly? 462 $( '.revision-tick' ).each( function() { 463 tickMargin = Math.floor( ( tickWidth - $( this ).width() ) / 2 ) + 1; 464 $( this ).css( 'border-left', tickMargin + 'px solid #f7f7f7'); // space the ticks out using margins 465 $( this ).css( 'border-right', ( tickWidth - tickMargin - $( this ).width() ) + 'px solid #f7f7f7'); // space the ticks out using margins 466 }); 467 sliderWidth = sliderWidth + 1; // one extra pixel so it all fits 468 $( '.revision-tick' ).last().css( 'border-right', 'none' ); // last tick gets no right border 469 $( '.revision-tick' ).first().css( 'border-left', 'none' ); // first tick gets no left border 470 } 460 471 461 // set minimum and maximum widths for tick marks 462 tickWidth = (tickWidth > 50 ) ? 50 : tickWidth; 463 tickWidth = (tickWidth < 10 ) ? 10 : tickWidth; 464 465 sliderWidth = tickWidth * (sliderMax - adjustMax ) + 1; 466 472 /** 473 * reset the slider width 474 */ 467 475 Diff.slider.setWidth( sliderWidth ); 468 476 $( '.diff-slider-ticks-wrapper' ).width( sliderWidth ); 469 477 $( '#diff-slider-ticks' ).width( sliderWidth ); 470 478 471 var aTickWidth = $( '.revision-tick' ).width(); 479 /** 480 * go through all ticks, add hover and click interactions 481 */ 482 $( '.revision-tick' ).each( function() { 483 Diff.slider.addTooltip ( $( this ), Diff.revisions.at( tickCount++ ).get( 'titleTooltip' ) ); 484 $( this ).hover( 485 function() { 486 $( this ).find( '.ui-slider-tooltip' ).show(); 487 }, 488 function() { 489 $( this ).find( '.ui-slider-tooltip' ).hide(); 490 } 491 ); 472 492 473 if ( tickWidth !== aTickWidth ) { // is the width already set correctly? 474 $( '.revision-tick' ).each( function( ) { 475 $(this).css( 'margin-right', tickWidth - 1 + 'px'); // space the ticks out using right margin 476 }); 477 478 $( '.revision-tick' ).last().css( 'margin-right', '0' ); // last tick gets no right margin 479 } 480 493 /** 494 * move the slider handle when the tick marks are clicked 495 */ 496 $( this ).on( 'click', 497 { tickCount: tickCount }, // //pass the tick through so we know where to move the handle 498 function( event ) { 499 if ( Diff.slider.singleRevision ) { //single handle mode 500 Diff.rightDiff = event.data.tickCount; //reposition the right handle 501 Diff.slider.refresh({ 502 value: Diff.rightDiff - 1 503 } ); 504 } else { //compare two mode 505 if ( event.data.tickCount < Diff.leftDiff || 506 isRtl && event.data.tickCount > Diff.leftDiff ) { // click was on the 'left' side 507 Diff.leftDiff = event.data.tickCount; // set the left handle location 508 Diff.reloadRight(); //reload the right handle comparison models 509 } else { //middle or 'right' clicks 510 Diff.rightDiff = event.data.tickCount; // set the right handle location 511 Diff.reloadLeft(); //reload left handle models 512 } 513 Diff.slider.refresh( { // set the slider handle positions 514 values: [ Diff.leftDiff, Diff.rightDiff ] 515 } ); 516 } 517 Diff.revisionView.render(); // render the main view 518 } ); 519 } ); 481 520 }, 482 521 483 // render the tick mark view522 // render the tick mark view 484 523 render: function() { 485 var self = this ;524 var self = this, addHtml; 486 525 487 526 if ( null !== self.model ) { 488 varaddHtml = "";527 addHtml = ""; 489 528 _.each ( self.model.models, function( theModel ) { 490 529 addHtml = addHtml + self.template ( theModel.toJSON() ); 491 530 }); … … 495 534 self.resetTicks(); 496 535 return self; 497 536 } 498 } );537 } ); 499 538 500 539 /** 501 540 * wp.revisions.view.Interact … … 514 553 }, 515 554 516 555 render: function() { 556 var modelcount; 517 557 this.$el.html( this.template ); 518 558 519 varmodelcount = Diff.revisions.length;559 modelcount = Diff.revisions.length; 520 560 521 561 Diff.slider.singleRevision = Diff.singleRevision; 522 562 Diff.slider.render(); … … 590 630 591 631 // render the revisions 592 632 render: function() { 593 var addHtml = ''; 594 var thediff; 633 var addHtml = '', thediff; 595 634 596 635 // compare two revisions mode? 597 636 if ( ! Diff.singleRevision ) { … … 618 657 $( '.diff-slider-ticks-wrapper' ).hide(); 619 658 } 620 659 621 // add tooltips to the handles622 if ( ! Diff.singleRevision ) {623 Diff.slider.addTooltip ( $( 'a.ui-slider-handle.left-handle' ),624 ( Diff.leftDiff < 0 ) ? '' : Diff.revisions.at( Diff.leftDiff - 1 ).get( 'titleTooltip' ) );625 Diff.slider.addTooltip ( $( 'a.ui-slider-handle.right-handle' ),626 ( Diff.rightDiff > Diff.revisions.length ) ? '' : Diff.revisions.at( Diff.rightDiff - 1 ).get( 'titleTooltip' ) );627 } else {628 Diff.slider.addTooltip ( $( 'a.ui-slider-handle' ),629 ( Diff.rightDiff > Diff.revisions.length ) ? '' : Diff.revisions.at( Diff.rightDiff - 1 ).get( 'titleTooltip' ) );630 }631 632 660 this.toggleCompareTwoCheckbox(); 633 661 634 662 // hide the restore button when on the last sport/current post data -
wp-admin/revision.php
102 102 <h2 class="long-header"><?php echo $h2; ?></h2> 103 103 104 104 <div id="loading-status" class="updated message"> 105 <p><span class="spinner" ></span> <?php _e( 'Calculating revision diffs' ); ?></p>105 <p><span class="spinner" ></span> <?php _e( 'Calculating revision comparisons' ); ?></p> 106 106 </div> 107 107 108 108 <div class="diff-slider-ticks-wrapper"> … … 161 161 </script> 162 162 163 163 <script id="tmpl-revision-ticks" type="text/html"> 164 <div class="revision-tick completed-{{{ data.completed }}} scope-of-changes-{{{ data.scopeOfChanges }}}"></div> 164 <div class="revision-tick completed-{{{ data.completed }}} scope-of-changes-{{{ data.scopeOfChanges }}}"> 165 <span class="ui-slider-tooltip ui-widget-content ui-corner-all hidden"></span> 166 </div> 165 167 </script> 166 168 <?php 167 169 require_once( './admin-footer.php' ); -
wp-admin/css/colors-fresh.css
1376 1376 border: 1px solid #dfdfdf; 1377 1377 } 1378 1378 1379 #diff-slider .ui-slider-tooltip { 1379 #diff-slider .ui-slider-tooltip, 1380 #diff-slider-ticks .ui-slider-tooltip { 1380 1381 border-color: #d7d7d7; 1381 1382 background-color: #fff; 1382 1383 } … … 1400 1401 background-image: none; 1401 1402 } 1402 1403 1403 .revision-tick.scope-of-changes- vsmall{1404 .revision-tick.scope-of-changes-none { 1404 1405 background-color: #d7d7d7; 1405 1406 } 1406 1407 1407 .revision-tick.scope-of-changes- small {1408 .revision-tick.scope-of-changes-vsmall { 1408 1409 background-color: #c3c3c3; 1409 1410 } 1410 1411 1411 .revision-tick.scope-of-changes- med{1412 .revision-tick.scope-of-changes-small { 1412 1413 background-color: #b0b0b0; 1413 1414 } 1414 1415 1415 .revision-tick.scope-of-changes- large{1416 .revision-tick.scope-of-changes-med { 1416 1417 background-color: #9c9c9c; 1417 1418 } 1418 1419 1419 .revision-tick.scope-of-changes- vlarge {1420 .revision-tick.scope-of-changes-large { 1420 1421 background-color: #898989; 1421 1422 } 1422 1423 1424 .revision-tick.scope-of-changes-vlarge { 1425 background-color: #696969; 1426 } 1427 1423 1428 .diff-label { 1424 1429 color: #666; 1425 1430 } -
wp-admin/css/wp-admin.css
3618 3618 width: 95%; 3619 3619 } 3620 3620 3621 #diff-slider .ui-slider-tooltip { 3621 #diff-slider .ui-slider-tooltip, 3622 #diff-slider-ticks .ui-slider-tooltip { 3622 3623 display: none; 3623 3624 position: absolute; 3624 3625 bottom: 20px; … … 3709 3710 .revision-tick { 3710 3711 width: 1px; 3711 3712 float: left; 3712 margin: 1px 15px0 0;3713 margin: 1px 0 0 0; 3713 3714 height: .8em; 3714 3715 padding: 0; 3715 3716 margin-left: 0px; 3717 cursor: hand; cursor: pointer; 3716 3718 } 3717 3719 3718 .revision-tick.scope-of-changes-vsmall { 3720 .revision-tick.scope-of-changes-vsmall, 3721 .revision-tick.scope-of-changes-none { 3719 3722 width: 1px; 3720 3723 } 3721 3724 3722 3725 .revision-tick.scope-of-changes-small { 3723 3726 width: 2px; 3724 margin-left: -1px;3725 3727 } 3726 3728 3727 3729 .revision-tick.scope-of-changes-med { 3728 3730 width: 3px; 3729 margin-left: -2px;3730 3731 } 3731 3732 3732 3733 .revision-tick.scope-of-changes-large { 3733 3734 width: 4px; 3734 margin-left: -3px;3735 3735 } 3736 3736 3737 3737 .revision-tick.scope-of-changes-vlarge { 3738 margin-left: -3px;3739 3738 width: 4px; 3740 left: 1;3741 3739 } 3742 3740 3743 3741 .diff-loading {