Skip to content
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ UI :
* font : font family.
* fontWeight : font weight.
* bgColor : background color.
* unit: unit option for value inside knob e.g. '%', 'px', 'pt' etc.

Hooks
-------
Expand Down
12 changes: 10 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title>jQuery Knob demo</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="js/jquery.knob.js"></script>
<script>
<script type="text/javascript">
$(function($) {

$(".knob").knob({
Expand All @@ -19,7 +19,7 @@
console.log("cancel : ", this);
},
draw : function () {

//append unit if it exists
// "tron" case
if(this.$.data('skin') == 'tron') {

Expand Down Expand Up @@ -122,6 +122,14 @@ <h1>jQuery Knob</h1>
</pre>
<input class="knob" data-width="100" data-displayInput=false value="35">
</div>
<div class="demo">
<p>&#215; display input with unit</p>
<pre>
data-width="100"
data-unit="%"
</pre>
<input class="knob" data-width="100" data-unit="%" value="35">
</div>
<div class="demo">
<p>&#215; 'cursor' mode</p>
<pre>
Expand Down
9 changes: 8 additions & 1 deletion js/jquery.knob.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
fontWeight: this.$.data('font-weight') || 'bold',
inline : false,
step : this.$.data('step') || 1,
unit: this.$.data('unit'),

// Hooks
draw : null, // function () {}
Expand Down Expand Up @@ -294,6 +295,11 @@
&& (d = s.dH());

(d !== false) && s.draw();

if(this.unit != undefined)
{
this.i.val(parseFloat(this.i.val())+this.unit);
}

};

Expand Down Expand Up @@ -548,7 +554,7 @@
var ori = e.originalEvent
,deltaX = ori.detail || ori.wheelDeltaX
,deltaY = ori.detail || ori.wheelDeltaY
,v = s._validate(s.$.val())
,v = s._validate(parseFloat(s.$.val()))
+ (deltaX>0 || deltaY>0 ? s.o.step : deltaX<0 || deltaY<0 ? -s.o.step : 0);

v = max(min(v, s.o.max), s.o.min);
Expand Down Expand Up @@ -651,6 +657,7 @@
this.lineWidth = this.xy * this.o.thickness;
this.lineCap = this.o.lineCap;
this.radius = this.xy - this.lineWidth / 2;
this.unit = this.o.unit;

this.o.angleOffset
&& (this.o.angleOffset = isNaN(this.o.angleOffset) ? 0 : this.o.angleOffset);
Expand Down