- fixed propagation of change event within _slide (fixes #4005 - slider and change callback with range: true)
- normalized all ui hash information
This commit is contained in:
Paul Bakaus 2009-02-17 12:21:42 +00:00
parent 77043b9bf2
commit 9c4b8a9141

View File

@ -101,7 +101,7 @@ $.widget("ui.slider", $.extend({}, $.ui.mouse, {
if (!self._keySliding) { if (!self._keySliding) {
self._keySliding = true; self._keySliding = true;
$(this).addClass("ui-state-active"); $(this).addClass("ui-state-active");
self._start(event); self._start(event, index);
} }
break; break;
} }
@ -138,9 +138,11 @@ $.widget("ui.slider", $.extend({}, $.ui.mouse, {
}).keyup(function(event) { }).keyup(function(event) {
var index = $(this).data("index.ui-slider-handle");
if (self._keySliding) { if (self._keySliding) {
self._stop(event); self._stop(event, index);
self._change(event); self._change(event, index);
self._keySliding = false; self._keySliding = false;
$(this).removeClass("ui-state-active"); $(this).removeClass("ui-state-active");
} }
@ -177,8 +179,6 @@ $.widget("ui.slider", $.extend({}, $.ui.mouse, {
if (o.disabled) if (o.disabled)
return false; return false;
this._start(event);
this.elementSize = { this.elementSize = {
width: this.element.outerWidth(), width: this.element.outerWidth(),
height: this.element.outerHeight() height: this.element.outerHeight()
@ -206,6 +206,8 @@ $.widget("ui.slider", $.extend({}, $.ui.mouse, {
closestHandle = $(this.handles[++index]); closestHandle = $(this.handles[++index]);
} }
this._start(event, index);
self._handleIndex = index; self._handleIndex = index;
closestHandle closestHandle
@ -247,8 +249,8 @@ $.widget("ui.slider", $.extend({}, $.ui.mouse, {
_mouseStop: function(event) { _mouseStop: function(event) {
this.handles.removeClass("ui-state-active"); this.handles.removeClass("ui-state-active");
this._stop(event); this._stop(event, this._handleIndex);
this._change(event); this._change(event, this._handleIndex);
this._handleIndex = null; this._handleIndex = null;
this._clickOffset = null; this._clickOffset = null;
@ -289,10 +291,8 @@ $.widget("ui.slider", $.extend({}, $.ui.mouse, {
}, },
_start: function(event) { _start: function(event, index) {
this._trigger("start", event, { this._trigger("start", event, this._uiHash(index));
value: this.value()
});
}, },
_slide: function(event, index, newVal) { _slide: function(event, index, newVal) {
@ -310,14 +310,10 @@ $.widget("ui.slider", $.extend({}, $.ui.mouse, {
var newValues = this.values(); var newValues = this.values();
newValues[index] = newVal; newValues[index] = newVal;
// A slide can be canceled by returning false from the slide callback // A slide can be canceled by returning false from the slide callback
var allowed = this._trigger("slide", event, { var allowed = this._trigger("slide", event, this._uiHash(index, newVal, newValues));
handle: handle,
value: newVal,
values: newValues
});
var otherVal = this.values(index ? 0 : 1); var otherVal = this.values(index ? 0 : 1);
if (allowed !== false) { if (allowed !== false) {
this.values(index, newVal, ( event.type == 'mousedown' && this.options.animate )); this.values(index, newVal, ( event.type == 'mousedown' && this.options.animate ), true);
} }
} }
@ -325,10 +321,7 @@ $.widget("ui.slider", $.extend({}, $.ui.mouse, {
if (newVal != this.value()) { if (newVal != this.value()) {
// A slide can be canceled by returning false from the slide callback // A slide can be canceled by returning false from the slide callback
var allowed = this._trigger("slide", event, { var allowed = this._trigger("slide", event, this._uiHash(index, newVal));
handle: handle,
value: newVal
});
if (allowed !== false) { if (allowed !== false) {
this._setData('value', newVal, ( event.type == 'mousedown' && this.options.animate )); this._setData('value', newVal, ( event.type == 'mousedown' && this.options.animate ));
} }
@ -339,35 +332,31 @@ $.widget("ui.slider", $.extend({}, $.ui.mouse, {
}, },
_stop: function(event) { _stop: function(event, index) {
this._trigger("stop", event, { this._trigger("stop", event, this._uiHash(index));
value: this.value()
});
}, },
_change: function(event) { _change: function(event, index) {
this._trigger("change", event, { this._trigger("change", event, this._uiHash(index));
value: this.value()
});
}, },
value: function(newValue) { value: function(newValue) {
if (arguments.length) { if (arguments.length) {
this._setData("value", newValue); this._setData("value", newValue);
this._change(); this._change(null, 0);
} }
return this._value(); return this._value();
}, },
values: function(index, newValue, animated) { values: function(index, newValue, animated, noPropagation) {
if (arguments.length > 1) { if (arguments.length > 1) {
this.options.values[index] = newValue; this.options.values[index] = newValue;
this._refreshValue(animated); this._refreshValue(animated);
this._change(); if(!noPropagation) this._change(null, index);
} }
if (arguments.length) { if (arguments.length) {
@ -479,6 +468,17 @@ $.widget("ui.slider", $.extend({}, $.ui.mouse, {
(oRange == "max") && (this.orientation == "vertical") && this.range[animate ? 'animate' : 'css']({ bottom: valPercent + '%', height: (100 - valPercent) + '%' }, { queue: false, duration: o.animate }); (oRange == "max") && (this.orientation == "vertical") && this.range[animate ? 'animate' : 'css']({ bottom: valPercent + '%', height: (100 - valPercent) + '%' }, { queue: false, duration: o.animate });
} }
},
_uiHash: function(index, value, values) {
var multiple = this.options.values && this.options.values.length;
return {
handle: this.handles[index],
value: value || (multiple ? this.values(index) : this.value()),
values: values || (multiple && this.values())
};
} }
})); }));