From 1625538224f2659182ceafb39a1b9d0e84d0442e Mon Sep 17 00:00:00 2001
From: odbol
Date: Mon, 3 Dec 2012 20:24:39 -0800
Subject: [PATCH 1/5] added support for HTML input attributes like min, max.
added allowFractions option to avoid rounding the result for higher-precision
results
---
README.md | 1 +
js/jquery.knob.js | 20 ++++++++++++++++----
2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
index c8a4c3f..2be0a1e 100644
--- a/README.md
+++ b/README.md
@@ -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.
diff --git a/js/jquery.knob.js b/js/jquery.knob.js
index d3a6026..eff951b 100644
--- a/js/jquery.knob.js
+++ b/js/jquery.knob.js
@@ -25,7 +25,7 @@
var k = {}, // kontrol
max = Math.max,
min = Math.min;
-
+
k.c = {};
k.c.d = $(document);
k.c.t = function (e) {
@@ -107,6 +107,10 @@
}, this.o
);
+ if (Math.abs(this.o.max - this.o.min) <= 1) {
+ this.o.allowFractions = true;
+ }
+
// routing value
if(this.$.is('fieldset')) {
@@ -434,8 +438,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));
@@ -642,8 +649,13 @@
return this.each(
function () {
var d = new k.Dial();
- d.o = o;
d.$ = $(this);
+
+ // use actual valid HTML defaults if there.
+ if (typeof o.max == 'undefined') o.max = d.$.attr('max');
+ if (typeof o.max == 'undefined') o.min = d.$.attr('min');
+
+ d.o = o;
d.run();
}
).parent();
From 2c88c286a4165320c38bc2d174239278b0d11035 Mon Sep 17 00:00:00 2001
From: odbol
Date: Sun, 20 Jan 2013 21:12:44 -0800
Subject: [PATCH 2/5] fixed max/min defaults being reused for every subsequent
object
---
js/jquery.knob.js | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/js/jquery.knob.js b/js/jquery.knob.js
index eff951b..fb7ef31 100644
--- a/js/jquery.knob.js
+++ b/js/jquery.knob.js
@@ -64,7 +64,7 @@
this.eH = null; // cancel hook
this.rH = null; // release hook
- this.run = function () {
+ this.run = function (o) {
var cf = function (e, conf) {
var k;
for (k in conf) {
@@ -82,8 +82,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'),
@@ -104,7 +104,7 @@
change : null, // function (value) {}
cancel : null, // function () {}
release : null // function (value) {}
- }, this.o
+ }, o
);
if (Math.abs(this.o.max - this.o.min) <= 1) {
@@ -651,12 +651,7 @@
var d = new k.Dial();
d.$ = $(this);
- // use actual valid HTML defaults if there.
- if (typeof o.max == 'undefined') o.max = d.$.attr('max');
- if (typeof o.max == 'undefined') o.min = d.$.attr('min');
-
- d.o = o;
- d.run();
+ d.run(o);
}
).parent();
};
From cbfdb91ebe2a2b7595810e03a6d35de9e9a97d1f Mon Sep 17 00:00:00 2001
From: odbol
Date: Mon, 21 Jan 2013 17:18:49 -0800
Subject: [PATCH 3/5] fixed min/max conversion
---
js/jquery.knob.js | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/js/jquery.knob.js b/js/jquery.knob.js
index fb7ef31..3a055eb 100644
--- a/js/jquery.knob.js
+++ b/js/jquery.knob.js
@@ -107,6 +107,10 @@
}, 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;
}
From 842aa13d24c1875f53dad1e2c03df91929d54dd9 Mon Sep 17 00:00:00 2001
From: odbol
Date: Mon, 25 Feb 2013 22:58:00 -0800
Subject: [PATCH 4/5] added a class to the wrapper element so it can be
identified/styled externally
---
js/jquery.knob.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/js/jquery.knob.js b/js/jquery.knob.js
index 3a055eb..38c729b 100644
--- a/js/jquery.knob.js
+++ b/js/jquery.knob.js
@@ -159,7 +159,7 @@
this.c = this.$c[0].getContext("2d");
this.$
- .wrap($(''))
.before(this.$c);
From c76dfd3fc85fc416882d6cc143fb7147adc66c89 Mon Sep 17 00:00:00 2001
From: odbol
Date: Wed, 13 Mar 2013 00:12:21 -0700
Subject: [PATCH 5/5] fixed anglearc defaults
---
js/jquery.knob.js | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/js/jquery.knob.js b/js/jquery.knob.js
index 38c729b..ba61799 100644
--- a/js/jquery.knob.js
+++ b/js/jquery.knob.js
@@ -65,6 +65,10 @@
this.rH = null; // release hook
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) {
@@ -554,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;