Skip to content

Commit

Permalink
fixing bug with limited values
Browse files Browse the repository at this point in the history
  • Loading branch information
eskimoblood committed May 11, 2012
1 parent 0eb05f5 commit 2c9b1b8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion index.html
Expand Up @@ -36,7 +36,7 @@
data-width="250"
data-min="-100"
</pre>
<input class="knob"data-width="250" data-min="-100" value="44">
<input class="knob"data-width="250" data-min="-100" data-max="100"value="44">
</div>
<div style="float:left;width:320px">
<pre>
Expand Down
16 changes: 11 additions & 5 deletions js/jquery.knob-1.0.1.js
Expand Up @@ -120,10 +120,12 @@ $(function() {
k = new Knob( c, opt );
k.onRelease = opt.release;
k.val( parseInt($this.val()) || 0 );
k.onChange = function(v) {
$this.val(v);
opt.change(v);
};

k.onChange = function(v){
var limitedValue = limitValue(v);
$this.val(limitedValue);
opt.change(limitedValue);
}

if( !opt.readOnly ){
c.bind(
Expand Down Expand Up @@ -169,9 +171,13 @@ $(function() {

function setVal(dir){
if(dir){
k.val( parseInt($this.val()) + dir );
k.val( (limitValue(parseInt($this.val()) + dir) ));
}
}

function limitValue(v){
return limitedValue = Math.max(Math.min(v, opt.max), opt.min);
}
}
).parent();
}
Expand Down

0 comments on commit 2c9b1b8

Please sign in to comment.