Skip to content

Commit 4e1d48b

Browse files
committed
Added stepping functionality
1 parent 195976e commit 4e1d48b

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ The following options are supported :
3535
Behaviors :
3636
* min : min value | default=0.
3737
* max : max value | default=100.
38+
* step : step size | defaul=1.
3839
* angleOffset : starting angle in degrees | default=0.
3940
* angleArc : arc size in degrees | default=360.
4041
* stopper : stop at min & max on keydown/mousewheel | default=true.

index.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,14 @@ <h1>jQuery Knob</h1>
159159
<input class="knob" data-angleOffset=-125 data-angleArc=250 data-fgColor="#66EE66" value="35">
160160
</div>
161161
<div class="demo" >
162-
<p>&#215; 5-digit values</p>
162+
<p>&#215; 5-digit values, step 1000</p>
163163
<pre>
164+
data-step="1000"
164165
data-min="-15000"
165166
data-max="15000"
167+
data-displayPrevious=true
166168
</pre>
167-
<input class="knob" data-min="-15000" data-max="15000" value="-11000">
169+
<input class="knob" data-min="-15000" data-displayPrevious=true data-max="15000" data-step="1000" value="-11000">
168170
</div>
169171
<div style="clear:both"></div>
170172
<div style="text-align: center">

js/jquery.knob.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
fgColor : this.$.data('fgcolor') || '#87CEEB',
101101
inputColor: this.$.data('inputcolor') || this.$.data('fgcolor') || '#87CEEB',
102102
inline : false,
103+
step : this.$.data('step') || 1,
103104

104105
// Hooks
105106
draw : null, // function () {}
@@ -140,7 +141,7 @@
140141
this.$.bind(
141142
'change'
142143
, function () {
143-
s.val(s.$.val());
144+
s.val(s._validate(s.$.val()));
144145
}
145146
);
146147
}
@@ -220,7 +221,7 @@
220221
) return;
221222

222223

223-
s.change(v);
224+
s.change(s._validate(v));
224225
s._draw();
225226
};
226227

@@ -261,7 +262,7 @@
261262
&& (s.cH(v) === false)
262263
) return;
263264

264-
s.change(v);
265+
s.change(s._validate(v));
265266
s._draw();
266267
};
267268

@@ -359,6 +360,10 @@
359360
this.$c[0].width = this.$c[0].width;
360361
};
361362

363+
this._validate = function(v) {
364+
return (~~ (((v < 0) ? -0.5 : 0.5) + (v/this.o.step))) * this.o.step;
365+
};
366+
362367
// Abstract methods
363368
this.listen = function () {}; // on start, one time
364369
this.extend = function () {}; // each time configure triggered
@@ -450,11 +455,10 @@
450455
var s = this,
451456
mw = function (e) {
452457
e.preventDefault();
453-
454458
var ori = e.originalEvent
455459
,deltaX = ori.detail || ori.wheelDeltaX
456460
,deltaY = ori.detail || ori.wheelDeltaY
457-
,v = parseInt(s.$.val()) + (deltaX>0 || deltaY>0 ? 1 : deltaX<0 || deltaY<0 ? -1 : 0);
461+
,v = parseInt(s.$.val()) + (deltaX>0 || deltaY>0 ? s.o.step : deltaX<0 || deltaY<0 ? -s.o.step : 0);
458462

459463
if (
460464
s.cH
@@ -463,7 +467,7 @@
463467

464468
s.val(v);
465469
}
466-
, kval, to, m = 1, kv = {37:-1, 38:1, 39:1, 40:-1};
470+
, kval, to, m = 1, kv = {37:-s.o.step, 38:s.o.step, 39:s.o.step, 40:-s.o.step};
467471

468472
this.$
469473
.bind(

0 commit comments

Comments
 (0)