Slider: Improve behaviour on overlapping ranges

Improve the handle detection when they overlap in slider ranges.
This commit is contained in:
Gon GArce 2023-07-29 02:31:49 +02:00
parent 1be4538817
commit a50e2af383

View File

@ -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 ) {