Skip to content

Commit

Permalink
Slider: change event is too greedy with mouse drag
Browse files Browse the repository at this point in the history
  • Loading branch information
cgack committed Sep 4, 2014
1 parent 7e9209e commit dc6ba5f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
2 changes: 1 addition & 1 deletion js/widgets/forms/slider.js
Expand Up @@ -514,7 +514,7 @@ $.widget( "mobile.slider", $.extend( {

// update control"s value
if ( isInput ) {
valueChanged = control.val() !== newval;
valueChanged = parseFloat( control.val() ) !== newval;
control.val( newval );
} else {
valueChanged = control[ 0 ].selectedIndex !== newval;
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/slider/index.html
Expand Up @@ -132,6 +132,10 @@
<input type="range" name="disable-input-test" id="disable-input-test" value="17" min="0" max="100" />
</label>

<div data-role="fieldcontain">
<input type="range" name="slider-change-event" id="slider-change-event" value="2" min="0" max="4" step="1" />
</div>

</div>

<div id="enhancetest">
Expand Down
11 changes: 0 additions & 11 deletions tests/unit/slider/slider_core.js
Expand Up @@ -95,17 +95,6 @@
testDisabled( "After setting option 'disabled' to true a second time: ", true );
});

test( "refresh is triggered on mouseup", function() {
expect( 1 );
var slider = $( "#mouseup-refresh" );

slider.val( parseInt(slider.val(), 10) + 10 );
slider.change(function() {
ok( true, "slider changed" );
});
slider.trigger( "mouseup" );
});

test( "slider tooltip & button values should match after input value changes", function() {
var slider = $("#tooltip-test-both");
var sliderHandle = slider.siblings(".ui-slider-track").children(".ui-slider-handle");
Expand Down
26 changes: 26 additions & 0 deletions tests/unit/slider/slider_events.js
Expand Up @@ -459,6 +459,32 @@
], 500);
});

test( "mouse move only triggers the change event when the value changes", function() {
var control = $( "#slider-change-event" ),
widget = control.data( "mobile-slider" ),
slider = widget.slider,
handle = widget.handle,
changeCount = 0,
actualChanges = 0,
changeFunc = function( e ) {
++changeCount;
if ( control.val() !== currentValue ) {
++actualChanges;
}
},
offset = handle.offset(),
currentValue = control.val();

control.bind( "change", changeFunc );

slider.trigger( createEvent( "mousedown", handle[ 0 ], offset.left + 10, offset.top + 10 ) );
slider.trigger( createEvent( "mouseup", handle[ 0 ], offset.left + 10, offset.top + 10 ) );

control.unbind( "change", changeFunc );

ok( changeCount === actualChanges, "change events match actual changes in value" );
});

// NOTE this test isn't run because the event data isn't easily accessible
// and with the advent of the widget _on method we are actually testing the
// widget from UI which has it's own test suite for these sorts of things
Expand Down

0 comments on commit dc6ba5f

Please sign in to comment.