Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Added support for the slider to step for step values under 1 #963

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions js/jquery.mobile.forms.slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ $.widget( "mobile.slider", $.mobile.widget, {
self.refresh( self.beforeStart === 0 ? 1 : 0 );
}
var curval = val();
var snapped = Math.round( curval / (max - min) * 100 );
if (step >= 1) {
var snapped = Math.round( curval / (max - min) * 100 );
} else {
var snapped = Math.round( curval / (max - min) * (100*1/step)) / (1/step);
}
handle
.addClass("ui-slider-handle-snapping")
.css("left", snapped + "%")
Expand Down Expand Up @@ -208,6 +212,7 @@ $.widget( "mobile.slider", $.mobile.widget, {
|| data.pageX > this.slider.offset().left + this.slider.width() + tol ) {
return;
}

percent = Math.round( ((data.pageX - this.slider.offset().left) / this.slider.width() ) * 100 );
} else {
if ( val == null ) {
Expand All @@ -219,8 +224,7 @@ $.widget( "mobile.slider", $.mobile.widget, {
if ( isNaN(percent) ) { return; }
if ( percent < 0 ) { percent = 0; }
if ( percent > 100 ) { percent = 100; }

var newval = Math.round( (percent / 100) * (max - min) ) + min;
var newval = ( (percent / 100) * (max - min) ) + min;
if ( newval < min ) { newval = min; }
if ( newval > max ) { newval = max; }

Expand Down
2 changes: 1 addition & 1 deletion themes/default/jquery.mobile.forms.slider.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Dual licensed under the MIT (MIT-LICENSE.txt) or GPL (GPL-LICENSE.txt) licenses.
*/
label.ui-slider { display: block; }
input.ui-slider-input, .min-width-480px input.ui-slider-input { display: inline-block; width: 50px; }
input.ui-slider-input, .min-width-480px input.ui-slider-input { display: inline-block; width: 70px; }
select.ui-slider-switch { display: none; }
div.ui-slider { position: relative; display: inline-block; overflow: visible; height: 15px; padding: 0; margin: 0 2% 0 20px; top: 4px; width: 66%; }
a.ui-slider-handle { position: absolute; z-index: 10; top: 50%; width: 28px; height: 28px; margin-top: -15px; margin-left: -15px; }
Expand Down