Skip to content

Commit a50e2af

Browse files
committed
Slider: Improve behaviour on overlapping ranges
Improve the handle detection when they overlap in slider ranges.
1 parent 1be4538 commit a50e2af

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

ui/widgets/slider.js

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -198,17 +198,31 @@ return $.widget( "ui.slider", $.ui.mouse, {
198198

199199
position = { x: event.pageX, y: event.pageY };
200200
normValue = this._normValueFromMouse( position );
201-
distance = this._valueMax() - this._valueMin() + 1;
202-
this.handles.each( function( i ) {
203-
var thisDistance = Math.abs( normValue - that.values( i ) );
204-
if ( ( distance > thisDistance ) ||
205-
( distance === thisDistance &&
206-
( i === that._lastChangedValue || that.values( i ) === o.min ) ) ) {
207-
distance = thisDistance;
208-
closestHandle = $( this );
209-
index = i;
201+
202+
if ( this.options.range === true && this.values( 0 ) === this.values( 1 ) ) {
203+
if ( this.values( 0 ) === this._valueMin() ) {
204+
index = 1;
205+
} else if ( this.values( 0 ) === this._valueMax() ) {
206+
index = 0;
207+
} else {
208+
index = normValue === this.values( 0 ) ?
209+
this._lastChangedValue :
210+
Number( normValue > this.values( 0 ) );
210211
}
211-
} );
212+
closestHandle = $( this.handles[ index ] );
213+
} else {
214+
distance = this._valueMax() - this._valueMin() + 1;
215+
this.handles.each( function( i ) {
216+
var thisDistance = Math.abs( normValue - that.values( i ) );
217+
if ( ( distance > thisDistance ) ||
218+
( distance === thisDistance &&
219+
( i === that._lastChangedValue || that.values( i ) === o.min ) ) ) {
220+
distance = thisDistance;
221+
closestHandle = $( this );
222+
index = i;
223+
}
224+
} );
225+
}
212226

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

0 commit comments

Comments
 (0)