Make WordPress Core

Ticket #24425: 24425.5.diff

File 24425.5.diff, 1.4 KB (added by adamsilverstein, 10 years ago)

track mouse when dragging handles, snap to step when stopping

  • wp-admin/js/revisions.js

     
    302302                                value: 0,
    303303                                min: 0,
    304304                                max: 1,
    305                                 step: 1
     305                                animate: true // enables click to slide
    306306                        });
    307307                },
    308308
     
    344344                 * also swaps in the appropriate models - left handled or right handled
    345345                 */
    346346                start: function( event, ui ) {
     347                        // track the mouse position to enable smooth dragging, overrides default jquery ui step behaviour
     348                        $( window ).mousemove( function( e ) {
     349                                $( ui.handle ).css( 'left', e.clientX - $( '#diff-slider' ).offset().left ); // subtract offset of container
     350                        });
     351
    347352                        // Not needed in one mode
    348353                        if ( this.singleRevision )
    349354                                return;
     
    387392                 * the other handle compares to this handle's position, so if it changes they need to be recalculated
    388393                 */
    389394                stop: function( event, ui ) {
     395                        $( window ).unbind( 'mousemove' ); // stop tracking the mouse
     396                        /**
     397                         * pop the handle back to the step position by resetting the value(s)
     398                         */
     399                        if ( Diff.slider.singleRevision ) {
     400                                Diff.slider.refresh({
     401                                        value: Diff.rightDiff - 1
     402                                } );
     403                        } else {
     404                                Diff.slider.refresh( {
     405                                        values: [ isRtl ? Diff.rightDiff : Diff.leftDiff, isRtl ? Diff.leftDiff : Diff.rightDiff ]
     406                                } );
     407                        }
     408
    390409                        // Not needed in one mode
    391410                        if ( this.singleRevision )
    392411                                return;