Skip to content
Permalink
Browse files

slider:

- fixed propagation of change event within _slide (fixes #4005 - slider and change callback with range: true)
- normalized all ui hash information
  • Loading branch information...
Paul Bakaus
Paul Bakaus committed Feb 17, 2009
1 parent 77043b9 commit 9c4b8a9141db4718126f7d383267b22f4eb5df71
Showing with 32 additions and 32 deletions.
  1. +32 −32 ui/ui.slider.js
@@ -101,7 +101,7 @@ $.widget("ui.slider", $.extend({}, $.ui.mouse, {
if (!self._keySliding) {
self._keySliding = true;
$(this).addClass("ui-state-active");
self._start(event);
self._start(event, index);
}
break;
}
@@ -138,9 +138,11 @@ $.widget("ui.slider", $.extend({}, $.ui.mouse, {

}).keyup(function(event) {

var index = $(this).data("index.ui-slider-handle");

if (self._keySliding) {
self._stop(event);
self._change(event);
self._stop(event, index);
self._change(event, index);
self._keySliding = false;
$(this).removeClass("ui-state-active");
}
@@ -177,8 +179,6 @@ $.widget("ui.slider", $.extend({}, $.ui.mouse, {
if (o.disabled)
return false;

this._start(event);

this.elementSize = {
width: this.element.outerWidth(),
height: this.element.outerHeight()
@@ -206,6 +206,8 @@ $.widget("ui.slider", $.extend({}, $.ui.mouse, {
closestHandle = $(this.handles[++index]);
}

this._start(event, index);

self._handleIndex = index;

closestHandle
@@ -247,8 +249,8 @@ $.widget("ui.slider", $.extend({}, $.ui.mouse, {
_mouseStop: function(event) {

this.handles.removeClass("ui-state-active");
this._stop(event);
this._change(event);
this._stop(event, this._handleIndex);
this._change(event, this._handleIndex);
this._handleIndex = null;
this._clickOffset = null;

@@ -289,10 +291,8 @@ $.widget("ui.slider", $.extend({}, $.ui.mouse, {

},

_start: function(event) {
this._trigger("start", event, {
value: this.value()
});
_start: function(event, index) {
this._trigger("start", event, this._uiHash(index));
},

_slide: function(event, index, newVal) {
@@ -310,25 +310,18 @@ $.widget("ui.slider", $.extend({}, $.ui.mouse, {
var newValues = this.values();
newValues[index] = newVal;
// A slide can be canceled by returning false from the slide callback
var allowed = this._trigger("slide", event, {
handle: handle,
value: newVal,
values: newValues
});
var allowed = this._trigger("slide", event, this._uiHash(index, newVal, newValues));
var otherVal = this.values(index ? 0 : 1);
if (allowed !== false) {
this.values(index, newVal, ( event.type == 'mousedown' && this.options.animate ));
this.values(index, newVal, ( event.type == 'mousedown' && this.options.animate ), true);
}
}

} else {

if (newVal != this.value()) {
// A slide can be canceled by returning false from the slide callback
var allowed = this._trigger("slide", event, {
handle: handle,
value: newVal
});
var allowed = this._trigger("slide", event, this._uiHash(index, newVal));
if (allowed !== false) {
this._setData('value', newVal, ( event.type == 'mousedown' && this.options.animate ));
}
@@ -339,35 +332,31 @@ $.widget("ui.slider", $.extend({}, $.ui.mouse, {

},

_stop: function(event) {
this._trigger("stop", event, {
value: this.value()
});
_stop: function(event, index) {
this._trigger("stop", event, this._uiHash(index));
},

_change: function(event) {
this._trigger("change", event, {
value: this.value()
});
_change: function(event, index) {
this._trigger("change", event, this._uiHash(index));
},

value: function(newValue) {

if (arguments.length) {
this._setData("value", newValue);
this._change();
this._change(null, 0);
}

return this._value();

},

values: function(index, newValue, animated) {
values: function(index, newValue, animated, noPropagation) {

if (arguments.length > 1) {
this.options.values[index] = newValue;
this._refreshValue(animated);
this._change();
if(!noPropagation) this._change(null, index);
}

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 });
}

},

_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())
};

}

}));

0 comments on commit 9c4b8a9

Please sign in to comment.
You can’t perform that action at this time.