Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions tests/unit/slider/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ common.testWidget( "slider", {
step: 1,
value: 0,
values: null,
allowCrossingHandles: false,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate of #

// Callbacks
create: null,
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/slider/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,4 +401,24 @@ QUnit.test( "range", function( assert ) {
element.slider( "destroy" );

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

} );

QUnit.test( "allowCrossingHandles", function( assert ) {
assert.expect( 1 );

element = $( "<div></div>" ).slider( {
range: true,
min: 0,
max: 100,
values: [ 25, 75 ],
allowCrossingHandles: true
} );

assert.deepEqual( element.slider( "values" ), [ 25, 75 ], "values" );

// var handles = element.find( ".ui-slider-handle" );
// handles.eq( 0 ).simulate( "drag", { dx: 1000 } );

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1853
Duplicate of #

// assert.deepEqual( element.slider( "values" ), [ 100, 75 ], "values" );

element.slider( "destroy" );
} );

} );
48 changes: 34 additions & 14 deletions ui/widgets/slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ return $.widget( "ui.slider", $.ui.mouse, {
min: 0,
orientation: "horizontal",
range: false,
allowCrossingHandles: false,
step: 1,
value: 0,
values: null,
Expand Down Expand Up @@ -330,11 +331,14 @@ return $.widget( "ui.slider", $.ui.mouse, {
newValues = this.values();

if ( this._hasMultipleValues() ) {
otherVal = this.values( index ? 0 : 1 );
currentValue = this.values( index );
if ( !this.options.allowCrossingHandles ) {
otherVal = this.values( index ? 0 : 1 );
currentValue = this.values( index );

if ( this.options.values.length === 2 && this.options.range === true ) {
newVal = index === 0 ? Math.min( otherVal, newVal ) : Math.max( otherVal, newVal );
if ( this.options.values.length === 2 && this.options.range === true ) {
newVal = index === 0 ? Math.min( otherVal, newVal )
: Math.max( otherVal, newVal );
}
}

newValues[ index ] = newVal;
Expand Down Expand Up @@ -473,6 +477,7 @@ return $.widget( "ui.slider", $.ui.mouse, {
this._animateOff = false;
break;
case "range":
case "allowCrossingHandles":
this._animateOff = true;
this._refresh();
this._animateOff = false;
Expand Down Expand Up @@ -590,7 +595,9 @@ return $.widget( "ui.slider", $.ui.mouse, {
},

_refreshValue: function() {
var lastValPercent, valPercent, value, valueMin, valueMax,
var valPercent, value, valueMin, valueMax,
rangeStartIndex = 0,
rangeStopIndex = 1,
oRange = this.options.range,
o = this.options,
that = this,
Expand All @@ -599,42 +606,55 @@ return $.widget( "ui.slider", $.ui.mouse, {

if ( this._hasMultipleValues() ) {
this.handles.each( function( i ) {
valPercent = ( that.values( i ) - that._valueMin() ) / ( that._valueMax() -
that._valueMin() ) * 100;
if ( that.values( i ) > that.values( rangeStopIndex ) ) {
rangeStopIndex = i;
}
if ( that.values( i ) < that.values( rangeStartIndex ) ) {
rangeStartIndex = i;
}
} );
this.handles.each( function( i ) {
var valPercentStart;
var computeValPercent = function( idx ) {
return ( that.values( idx ) - that._valueMin() ) / ( that._valueMax() -
that._valueMin() ) * 100;
};
valPercent = computeValPercent( i );
_set[ that.orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%";
$( this ).stop( 1, 1 )[ animate ? "animate" : "css" ]( _set, o.animate );
if ( that.options.range === true ) {
if ( that.orientation === "horizontal" ) {
if ( i === 0 ) {
if ( i === rangeStartIndex ) {
that.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( {
left: valPercent + "%"
}, o.animate );
}
if ( i === 1 ) {
if ( i === rangeStopIndex ) {
valPercentStart = computeValPercent( rangeStartIndex );
that.range[ animate ? "animate" : "css" ]( {
width: ( valPercent - lastValPercent ) + "%"
width: Math.abs ( valPercent - valPercentStart ) + "%"
}, {
queue: false,
duration: o.animate
} );
}
} else {
if ( i === 0 ) {
if ( i === rangeStartIndex ) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( {
bottom: ( valPercent ) + "%"
}, o.animate );
}
if ( i === 1 ) {
if ( i === rangeStopIndex ) {
valPercentStart = computeValPercent( rangeStartIndex );
that.range[ animate ? "animate" : "css" ]( {
height: ( valPercent - lastValPercent ) + "%"
height: Math.abs ( valPercent - valPercentStart ) + "%"
}, {
queue: false,
duration: o.animate
} );
}
}
}
lastValPercent = valPercent;
} );
} else {
value = this.value();
Expand Down