Permalink
Browse files

slider step, remove round clean up code a bit

  • Loading branch information...
jrowny authored and johnbender committed Aug 12, 2011
1 parent e09374b commit 1597d756d8191c4c77483625aa188b8e025745e5
Showing with 5 additions and 5 deletions.
  1. +5 −5 js/jquery.mobile.forms.slider.js
@@ -255,7 +255,7 @@ $.widget( "mobile.slider", $.mobile.widget, {
cType = control[0].nodeName.toLowerCase(),
min = cType === "input" ? parseFloat( control.attr( "min" ) ) : 0,
max = cType === "input" ? parseFloat( control.attr( "max" ) ) : control.find( "option" ).length - 1,
step = (cType === "input" && parseFloat(control.attr("step"))>0) ? parseFloat(control.attr("step")) : 1;
step = (cType === "input" && parseFloat( control.attr( "step" ) ) > 0) ? parseFloat(control.attr("step")) : 1;
if ( typeof val === "object" ) {
var data = val,
@@ -286,17 +286,17 @@ $.widget( "mobile.slider", $.mobile.widget, {
percent = 100;
}
var newval = Math.round( ( percent / 100 ) * ( max - min ) ) + min;
var newval = ( percent / 100 ) * ( max - min ) + min;
//from jQuery UI slider, the following source will round to the neraest step
var valModStep = (newval - min) % step;
var valModStep = ( newval - min ) % step;
var alignValue = newval - valModStep;
if ( Math.abs(valModStep) * 2 >= step ) {
if ( Math.abs( valModStep ) * 2 >= step ) {
alignValue += ( valModStep > 0 ) ? step : ( -step );
}
// Since JavaScript has problems with large floats, round
// the final value to 5 digits after the decimal point (see jQuery UI: #4124)
// the final value to 5 digits after the decimal point (see jQueryUI: #4124)
newval = parseFloat( alignValue.toFixed(5) );
if ( newval < min ) {

0 comments on commit 1597d75

Please sign in to comment.