Skip to content

Commit 6108ac9

Browse files
author
scottjehl
committed
fixed issues with slider handle positioning when min isn't 0. Fixes jquery-archive#397
1 parent 356308e commit 6108ac9

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

js/jquery.mobile.forms.slider.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ $.widget( "mobile.slider", $.mobile.widget, {
2424
controlID = control.attr('id'),
2525
labelID = controlID + '-label',
2626
label = $('[for='+ controlID +']').attr('id',labelID),
27-
val = (cType == 'input') ? control.val() : control[0].selectedIndex,
27+
val = (cType == 'input') ? parseFloat(control.val()) : control[0].selectedIndex,
2828
min = (cType == 'input') ? parseFloat(control.attr('min')) : 0,
2929
max = (cType == 'input') ? parseFloat(control.attr('max')) : control.find('option').length-1,
30-
percent = val / (max - min) * 100,
30+
percent = ((parseFloat(val) - min) / (max - min)) * 100,
3131
snappedPercent = percent,
3232
slider = $('<div class="ui-slider '+ selectClass +' ui-btn-down-'+o.trackTheme+' ui-btn-corner-all" role="application"></div>'),
3333
handle = $('<a href="#" class="ui-slider-handle"></a>')
@@ -44,6 +44,7 @@ $.widget( "mobile.slider", $.mobile.widget, {
4444
}),
4545
dragging = false;
4646

47+
4748
if(cType == 'select'){
4849
slider.wrapInner('<div class="ui-slider-inneroffset"></div>');
4950
var options = control.find('option');
@@ -70,28 +71,30 @@ $.widget( "mobile.slider", $.mobile.widget, {
7071

7172
function slideUpdate(event, val){
7273
if (val){
73-
percent = parseFloat(val) / (max - min) * 100;
74+
percent = (parseFloat(val) - min) / (max - min) * 100;
7475
} else {
7576
var data = event.originalEvent.touches ? event.originalEvent.touches[ 0 ] : event,
7677
// a slight tolerance helped get to the ends of the slider
77-
tol = 4;
78+
tol = 8;
7879
if( !dragging
7980
|| data.pageX < slider.offset().left - tol
8081
|| data.pageX > slider.offset().left + slider.width() + tol ){
8182
return;
8283
}
8384
percent = Math.round(((data.pageX - slider.offset().left) / slider.width() ) * 100);
8485
}
86+
8587
if( percent < 0 ) { percent = 0; }
8688
if( percent > 100 ) { percent = 100; }
87-
var newval = Math.round( (percent/100) * max );
89+
var newval = Math.round( (percent/100) * (max-min) ) + min;
90+
8891
if( newval < min ) { newval = min; }
8992
if( newval > max ) { newval = max; }
9093
//flip the stack of the bg colors
9194
if(percent > 60 && cType == 'select'){
9295

9396
}
94-
snappedPercent = Math.round( newval / max * 100 );
97+
snappedPercent = Math.round( newval / (max-min) * 100 );
9598
handle.css('left', percent + '%');
9699
handle.attr({
97100
'aria-valuenow': (cType == 'input') ? newval : control.find('option').eq(newval).attr('value'),

0 commit comments

Comments
 (0)