I have this simple jQuery UI Slider setup with a range and a two default values that overlap. The entire thing (with a few bells and whistles) can be found in this jsfiddle: http://jsfiddle.net/yijiang/XeyGS/
$('#slider').slider({
min: 1,
max: 11,
range: true,
values: [4, 4]
});
The problem with this is that when you attempt the drag the single visible handle to the right, it fails, because jQuery UI always places the minimum handle on top. This is obviously bad, for a number of reasons.
Is there a way to allow jQuery UI to choose which handle to drag depending on which direction the user starts dragging?
Another solution: Test for both values and if they are the same, return to the last step.
With apologies to Ivo there, whose excellent answer there I'm sure took a lot of effort to create. The problem is that I couldn't apply that solution, because I'm already on 1.8.6, I can't find the 1.8.5 sources anywhere to apply it to, and somehow I just couldn't get the patch to work for 1.8.6, even when I tried adding in the lines manually.
The following is my solution to the problem. It is simpler than Ivo's, but that might be because of differences between the two point releases. The solution is as follows:
_handleIndex
) around, causing the maximum handle to be used for reference for the internal_slide
function instead of the first.The
diff
is as follows:The first part should be inserted into the initialising area, where the variables are declared, the second into the
_mouseCapture
function right before the call to_slide
, and the last part into the_mouseDrag
function, also right before the call to_slide
.Here's a working example with the patch: http://www.jsfiddle.net/HcGXZ/
A copy of the patched jQuery UI 1.8.6 Slider file can be found here: http://dl.dropbox.com/u/1722364/jQuery%20UI%20Slider%20Patch/jquery.ui.slider.patched.js
As always, this patch has not been extensively tested and is not guaranteed to work for all scenarios.
Put this into the initialising area, where the variables are declared:
Put this into the
_mouseCapture
function right before the call to_slide
:And this into the
_mouseDrag
function, also right before the call to_slide
I just added an
else if
to the above code; it's working fine in jQuery 1.8.14 for both left and right button handlers.Here's a new version for jQuery UI 1.10.2
Patch file: http://pastebin.com/Dsxw8NYR
Complete file: http://pastebin.com/ibSpAAX1
Ah, I like it to eat through 11k libs, don't you too? :)
Note: The following is for jQuery UI 1.8.5
Anyways, here's a pretty clean solution:
And that's all there is to it, oh how it works, of course:
And for your pleasure here's a
diff
:Save it to
ui.diff
then dopatch -i ui.diff jquery-ui.js
.I tried Yi Jiang's solution with 1.8.12 and it broke on a slider with a single handle, but worked perfectly after I changed
to