Skip to content

Commit

Permalink
Fix Divide by Zero bug in translateToPx()
Browse files Browse the repository at this point in the history
Bug that drove me insane hunting down and fixing back in 2010.  Found
the bug is still in the latest version so I applied it to the latest
branch.  If I recall correctly it fails SILENTLY with no errors and
sliders that just don't work. Took days to initially find the problem.
  • Loading branch information
hackerceo committed Jun 18, 2015
1 parent 1e63ff3 commit 5d67466
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/slider.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ Control.Slider = Class.create({
handleIdx || this.activeHandleIdx || 0); handleIdx || this.activeHandleIdx || 0);
}, },
translateToPx: function(value) { translateToPx: function(value) {
if ((this.range.end-this.range.start)==0) { return "0px"; }
return Math.round( return Math.round(
((this.trackLength-this.handleLength)/(this.range.end-this.range.start)) * ((this.trackLength-this.handleLength)/(this.range.end-this.range.start)) *
(value - this.range.start)) + "px"; (value - this.range.start)) + "px";
Expand Down

0 comments on commit 5d67466

Please sign in to comment.