Slider: fixed change event to be triggered by keyup and value and values option setters. Fixes #5367 - slider change event not triggered by keypress

This commit is contained in:
Richard Worth 2010-03-17 17:39:29 +00:00
parent e84a318e46
commit 0604e11052
2 changed files with 13 additions and 3 deletions

View File

@ -20,7 +20,7 @@ test( "slide", function() {
// value (even if same as previous value), via mouse(mouseup) or keyboard(keyup) // value (even if same as previous value), via mouse(mouseup) or keyboard(keyup)
// or value method/option" // or value method/option"
test( "change", function() { test( "change", function() {
expect(7); expect(8);
var handle; var handle;
// Test mouseup at end of handle slide (mouse) // Test mouseup at end of handle slide (mouse)
@ -48,7 +48,7 @@ test( "change", function() {
el.find( ".ui-slider-handle" ).eq( 0 ) el.find( ".ui-slider-handle" ).eq( 0 )
.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ) .simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } )
.simulate( "keypress", { keyCode: $.ui.keyCode.LEFT } ) .simulate( "keypress", { keyCode: $.ui.keyCode.LEFT } )
.simulate( "keyup", { charCode: $.ui.keyCode.LEFT } ); .simulate( "keyup", { keyCode: $.ui.keyCode.LEFT } );
reset(); reset();
// Test value method // Test value method

View File

@ -193,9 +193,9 @@ $.widget("ui.slider", $.ui.mouse, {
var index = $(this).data("index.ui-slider-handle"); var index = $(this).data("index.ui-slider-handle");
if (self._keySliding) { if (self._keySliding) {
self._keySliding = false;
self._stop(event, index); self._stop(event, index);
self._change(event, index); self._change(event, index);
self._keySliding = false;
$(this).removeClass("ui-state-active"); $(this).removeClass("ui-state-active");
} }
@ -479,6 +479,12 @@ $.widget("ui.slider", $.ui.mouse, {
}, },
_setOption: function(key, value) { _setOption: function(key, value) {
var i,
valsLength = 0;
if ( jQuery.isArray(this.options.values) ) {
valsLength = this.options.values.length;
};
$.Widget.prototype._setOption.apply(this, arguments); $.Widget.prototype._setOption.apply(this, arguments);
@ -505,11 +511,15 @@ $.widget("ui.slider", $.ui.mouse, {
case 'value': case 'value':
this._animateOff = true; this._animateOff = true;
this._refreshValue(); this._refreshValue();
this._change(null, 0);
this._animateOff = false; this._animateOff = false;
break; break;
case 'values': case 'values':
this._animateOff = true; this._animateOff = true;
this._refreshValue(); this._refreshValue();
for (i = 0; i < valsLength; i++) {
this._change(null, i);
}
this._animateOff = false; this._animateOff = false;
break; break;
} }