Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slider: Improve behaviour on overlapping ranges #2180

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Slider: Improve behaviour on overlapping ranges
Improve the handle detection when they overlap in slider ranges.
zalito12 committed Jul 29, 2023
commit a50e2af383ca76750f0e0c97883c318ffc4aae7a
34 changes: 24 additions & 10 deletions ui/widgets/slider.js
Original file line number Diff line number Diff line change
@@ -198,17 +198,31 @@ return $.widget( "ui.slider", $.ui.mouse, {

position = { x: event.pageX, y: event.pageY };
normValue = this._normValueFromMouse( position );
distance = this._valueMax() - this._valueMin() + 1;
this.handles.each( function( i ) {
var thisDistance = Math.abs( normValue - that.values( i ) );
if ( ( distance > thisDistance ) ||
( distance === thisDistance &&
( i === that._lastChangedValue || that.values( i ) === o.min ) ) ) {
distance = thisDistance;
closestHandle = $( this );
index = i;

if ( this.options.range === true && this.values( 0 ) === this.values( 1 ) ) {
if ( this.values( 0 ) === this._valueMin() ) {
index = 1;
} else if ( this.values( 0 ) === this._valueMax() ) {
index = 0;
} else {
index = normValue === this.values( 0 ) ?
this._lastChangedValue :
Number( normValue > this.values( 0 ) );
}
} );
closestHandle = $( this.handles[ index ] );
} else {
distance = this._valueMax() - this._valueMin() + 1;
this.handles.each( function( i ) {
var thisDistance = Math.abs( normValue - that.values( i ) );
if ( ( distance > thisDistance ) ||
( distance === thisDistance &&
( i === that._lastChangedValue || that.values( i ) === o.min ) ) ) {
distance = thisDistance;
closestHandle = $( this );
index = i;
}
} );
}

allowed = this._start( event, index );
if ( allowed === false ) {