Skip to content

Commit f0432c0

Browse files
committed
Better fix for #3467 - Make $.ui.mouse handle direction.x and direction.y options and make the slider use _mouseStart rather than _mouseCapture to respect _mouseDistanceMet
1 parent 049f885 commit f0432c0

File tree

3 files changed

+22
-40
lines changed

3 files changed

+22
-40
lines changed

tests/unit/slider/slider_defaults.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var slider_defaults = {
77
cancel: function() {},
88
delay: 0,
99
disabled: false,
10-
distance: 0,
10+
distance: 1,
1111
max: 100,
1212
min: 0,
1313
orientation: 'horizontal',

ui/jquery.ui.mouse.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,16 @@ $.widget("ui.mouse", {
130130
},
131131

132132
_mouseDistanceMet: function(event) {
133-
return (Math.max(
134-
Math.abs(this._mouseDownEvent.pageX - event.pageX),
135-
Math.abs(this._mouseDownEvent.pageY - event.pageY)
136-
) >= this.options.distance
137-
);
133+
var distance = this.options.distance;
134+
if ( typeof distance !== "object" && !jQuery.isFunction(distance) ) {
135+
return (Math.max(
136+
Math.abs(this._mouseDownEvent.pageX - event.pageX),
137+
Math.abs(this._mouseDownEvent.pageY - event.pageY)
138+
) >= this.options.distance
139+
);
140+
}
141+
return ((distance.x ? Math.abs(this._mouseDownEvent.pageX - event.pageX) >= distance.x : true)
142+
&& (distance.y ? Math.abs(this._mouseDownEvent.pageY - event.pageY) >= distance.y : true));
138143
},
139144

140145
_mouseDelayMet: function(event) {

ui/jquery.ui.slider.js

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ $.widget("ui.slider", $.ui.mouse, {
2323
widgetEventPrefix: "slide",
2424
options: {
2525
animate: false,
26-
distance: 0,
26+
distance: 1,
2727
max: 100,
2828
min: 0,
2929
orientation: 'horizontal',
@@ -53,6 +53,8 @@ $.widget("ui.slider", $.ui.mouse, {
5353
this.element.addClass('ui-slider-disabled ui-disabled');
5454
}
5555

56+
o.distance = o.orientation == 'horizontal' ? {x:o.distance,y:0} : (o.orientation == "vertical" ? {x:0,y:o.distance} : o.distance);
57+
5658
this.range = $([]);
5759

5860
if (o.range) {
@@ -228,7 +230,7 @@ $.widget("ui.slider", $.ui.mouse, {
228230
return this;
229231
},
230232

231-
_mouseCapture: function(event) {
233+
_mouseStart: function(event, orgEvent) {
232234

233235
var o = this.options;
234236

@@ -255,17 +257,13 @@ $.widget("ui.slider", $.ui.mouse, {
255257
}
256258
});
257259

258-
// workaround for bug #3736 (if both handles of a range are at 0,
259-
// the first is always used as the one with least distance,
260-
// and moving it is obviously prevented by preventing negative ranges)
261-
if(o.range == true) {
262-
var vals = this.values()
263-
if (vals[1] == o.min) {
264-
closestHandle = $(this.handles[++index]);
265-
}
266-
if (vals[0] == vals[1]){
267-
this._stackedHandles = true;
268-
}
260+
// workaround for bug #3736 (if both handles of a range are stacked,
261+
// figure out which way they are moving and use that handle)
262+
if (o.range == true && this.values(0) == this.values(1) &&
263+
((o.orientation == 'horizontal' && (event.pageX < orgEvent.pageX))
264+
|| (o.orientation == "vertical" && (event.pageY > orgEvent.pageY))) ) {
265+
index = 1;
266+
closestHandle = $(this.handles[index]);
269267
}
270268

271269
this._start(event, index);
@@ -295,10 +293,6 @@ $.widget("ui.slider", $.ui.mouse, {
295293

296294
},
297295

298-
_mouseStart: function(event) {
299-
return true;
300-
},
301-
302296
_mouseDrag: function(event) {
303297

304298
var position = { x: event.pageX, y: event.pageY };
@@ -374,23 +368,6 @@ $.widget("ui.slider", $.ui.mouse, {
374368
_slide: function(event, index, newVal) {
375369

376370
var handle = this.handles[index];
377-
378-
// Handle the case were range handles are stacked
379-
if (this.options.range == true && this._stackedHandles) {
380-
var values = this.values();
381-
if (values[1] != newVal){
382-
if (values[1] > newVal){
383-
index = 0;
384-
} else if(values[1] < newVal){
385-
index = 1;
386-
}
387-
this._stackedHandles = false;
388-
this.handles.removeClass("ui-state-active");
389-
handle = this.handles[index];
390-
$(handle).addClass("ui-state-active").focus();
391-
this._handleIndex = index;
392-
}
393-
}
394371

395372
if (this.options.values && this.options.values.length) {
396373

0 commit comments

Comments
 (0)