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 @@ -39,6 +39,7 @@ Behaviors :
* angleArc : arc size in degrees | default=360.
* stopper : stop at min & max on keydown/mousewheel | default=true.
* readOnly : disable input and events | default=false.
* allowFractions : do not round the output to the nearest integer. | default=false

UI :
* cursor : display mode "cursor" | default=gauge.
Expand Down
39 changes: 27 additions & 12 deletions js/jquery.knob.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
var k = {}, // kontrol
max = Math.max,
min = Math.min;

k.c = {};
k.c.d = $(document);
k.c.t = function (e) {
Expand Down Expand Up @@ -64,7 +64,11 @@
this.eH = null; // cancel hook
this.rH = null; // release hook

this.run = function () {
this.run = function (o) {

if (!o) // for backwards compatibility, although if you don't pass o you can run into problems
o = this.o;

var cf = function (e, conf) {
var k;
for (k in conf) {
Expand All @@ -82,8 +86,8 @@
this.o = $.extend(
{
// Config
min : this.$.data('min') || 0,
max : this.$.data('max') || 100,
min : this.$.data('min') || this.$.attr('min') || 0,
max : this.$.data('max') || this.$.attr('max') || 100,
stopper : true,
readOnly : this.$.data('readonly'),

Expand All @@ -104,9 +108,17 @@
change : null, // function (value) {}
cancel : null, // function () {}
release : null // function (value) {}
}, this.o
}, o
);

// extirpate the source of all frustration
this.o.max = parseFloat(this.o.max);
this.o.min = parseFloat(this.o.min);

if (Math.abs(this.o.max - this.o.min) <= 1) {
this.o.allowFractions = true;
}

// routing value
if(this.$.is('fieldset')) {

Expand Down Expand Up @@ -151,7 +163,7 @@
this.c = this.$c[0].getContext("2d");

this.$
.wrap($('<div style="' + (this.o.inline ? 'display:inline;' : '') +
.wrap($('<div class="jKnob" style="' + (this.o.inline ? 'display:inline;' : '') +
'width:' + this.o.width + 'px;height:' +
this.o.height + 'px;"></div>'))
.before(this.$c);
Expand Down Expand Up @@ -434,8 +446,11 @@
a += this.PI2;
}

ret = ~~ (0.5 + (a * (this.o.max - this.o.min) / this.angleArc))
+ this.o.min;
ret = (a * (this.o.max - this.o.min) / this.angleArc);
if (!this.o.allowFractions) {
ret = ~~(0.5 + ret);
}
ret += this.o.min;

this.o.stopper
&& (ret = max(min(ret, this.o.max), this.o.min));
Expand Down Expand Up @@ -543,10 +558,10 @@
this.radius = this.xy - this.lineWidth / 2;

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

this.o.angleArc
&& (this.o.angleArc = isNaN(this.o.angleArc) ? this.PI2 : this.o.angleArc);
|| (this.o.angleArc = isNaN(this.o.angleArc) ? 360 : this.o.angleArc);

// deg to rad
this.angleOffset = this.o.angleOffset * Math.PI / 180;
Expand Down Expand Up @@ -642,9 +657,9 @@
return this.each(
function () {
var d = new k.Dial();
d.o = o;
d.$ = $(this);
d.run();

d.run(o);
}
).parent();
};
Expand Down