From bb8ffc75003f5ae0ebb907fa746bbb37e865259a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Abel=20Mui=C3=B1o?=
Date: Thu, 14 Nov 2013 14:25:37 +0100
Subject: [PATCH 01/41] Make change event always fire as the user interacts
with the knob: - touch - wheel - typing (by binding to the "input" event)
Previously, typing did not update the knob until focus was lost (and
no change event was fired), and
using the keyboard arrows did not fire any change events.
Also move event triggering to val() and change() so it works always
in the same way and less duplication exists.
---
js/jquery.knob.js | 39 ++++++++++++++-------------------------
1 file changed, 14 insertions(+), 25 deletions(-)
diff --git a/js/jquery.knob.js b/js/jquery.knob.js
index d6fa7b7..a7f5453 100755
--- a/js/jquery.knob.js
+++ b/js/jquery.knob.js
@@ -141,7 +141,7 @@
s.v[k] = $this.val();
$this.bind(
- 'change'
+ 'change input'
, function () {
var val = {};
val[k] = $this.val();
@@ -159,7 +159,7 @@
(this.v == '') && (this.v = this.o.min);
this.$.bind(
- 'change'
+ 'change input'
, function () {
s.val(s._validate(s.$.val()));
}
@@ -302,15 +302,6 @@
e.originalEvent.touches[s.t].pageX,
e.originalEvent.touches[s.t].pageY
);
-
- if (v == s.cv) return;
-
- if (
- s.cH
- && (s.cH(v) === false)
- ) return;
-
-
s.change(s._validate(v));
s._draw();
};
@@ -345,13 +336,6 @@
var mouseMove = function (e) {
var v = s.xy2val(e.pageX, e.pageY);
- if (v == s.cv) return;
-
- if (
- s.cH
- && (s.cH(v) === false)
- ) return;
-
s.change(s._validate(v));
s._draw();
};
@@ -516,7 +500,13 @@
this.val = function (v) {
if (null != v) {
- this.cv = this.o.stopper ? max(min(v, this.o.max), this.o.min) : v;
+ var newValue = this.o.stopper ? max(min(v, this.o.max), this.o.min) : v;
+ if (newValue == this.cv) return;
+ this.cv = newValue;
+ if (
+ this.cH
+ && (this.cH(this.cv) === false)
+ ) return;
this.v = this.cv;
this.$.val(this.v);
this._draw();
@@ -558,12 +548,6 @@
,deltaX = ori.detail || ori.wheelDeltaX
,deltaY = ori.detail || ori.wheelDeltaY
,v = parseInt(s.$.val()) + (deltaX>0 || deltaY>0 ? s.o.step : deltaX<0 || deltaY<0 ? -s.o.step : 0);
-
- if (
- s.cH
- && (s.cH(v) === false)
- ) return;
-
s.val(v);
}
, kval, to, m = 1, kv = {37:-s.o.step, 38:s.o.step, 39:s.o.step, 40:-s.o.step};
@@ -691,7 +675,12 @@
};
this.change = function (v) {
+ if (v == this.cv) return;
this.cv = v;
+ if (
+ this.cH
+ && (this.cH(v) === false)
+ ) return;
this.$.val(v);
};
From ec052922f12517cda89217fe86e2761b11d6b5e5 Mon Sep 17 00:00:00 2001
From: aterrien
Date: Wed, 20 Nov 2013 00:08:03 +0100
Subject: [PATCH 02/41] Revert fix regression since #140
---
js/jquery.knob.js | 41 ++++++++++++++++++++++++++---------------
1 file changed, 26 insertions(+), 15 deletions(-)
diff --git a/js/jquery.knob.js b/js/jquery.knob.js
index 091a52b..376a138 100755
--- a/js/jquery.knob.js
+++ b/js/jquery.knob.js
@@ -141,7 +141,7 @@
s.v[k] = $this.val();
$this.bind(
- 'change input'
+ 'change'
, function () {
var val = {};
val[k] = $this.val();
@@ -159,7 +159,7 @@
(this.v == '') && (this.v = this.o.min);
this.$.bind(
- 'change input'
+ 'change'
, function () {
s.val(s._validate(s.$.val()));
}
@@ -302,6 +302,15 @@
e.originalEvent.touches[s.t].pageX,
e.originalEvent.touches[s.t].pageY
);
+
+ if (v == s.cv) return;
+
+ if (
+ s.cH
+ && (s.cH(v) === false)
+ ) return;
+
+
s.change(s._validate(v));
s._draw();
};
@@ -336,6 +345,13 @@
var mouseMove = function (e) {
var v = s.xy2val(e.pageX, e.pageY);
+ if (v == s.cv) return;
+
+ if (
+ s.cH
+ && (s.cH(v) === false)
+ ) return;
+
s.change(s._validate(v));
s._draw();
};
@@ -500,13 +516,7 @@
this.val = function (v) {
if (null != v) {
- var newValue = this.o.stopper ? max(min(v, this.o.max), this.o.min) : v;
- if (newValue == this.cv) return;
- this.cv = newValue;
- if (
- this.cH
- && (this.cH(this.cv) === false)
- ) return;
+ this.cv = this.o.stopper ? max(min(v, this.o.max), this.o.min) : v;
this.v = this.cv;
this.$.val(this.v);
this._draw();
@@ -548,6 +558,12 @@
,deltaX = ori.detail || ori.wheelDeltaX
,deltaY = ori.detail || ori.wheelDeltaY
,v = parseInt(s.$.val()) + (deltaX>0 || deltaY>0 ? s.o.step : deltaX<0 || deltaY<0 ? -s.o.step : 0);
+
+ if (
+ s.cH
+ && (s.cH(v) === false)
+ ) return;
+
s.val(v);
}
, kval, to, m = 1, kv = {37:-s.o.step, 38:s.o.step, 39:s.o.step, 40:-s.o.step};
@@ -675,12 +691,7 @@
};
this.change = function (v) {
- if (v == this.cv) return;
this.cv = v;
- if (
- this.cH
- && (this.cH(v) === false)
- ) return;
this.$.val(v);
};
@@ -746,4 +757,4 @@
).parent();
};
-})(jQuery);
+})(jQuery);
\ No newline at end of file
From 1d82b10c54b3252bcfbc9fbac8099757cfdfaa97 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Abel=20Mui=C3=B1o?=
Date: Wed, 20 Nov 2013 10:53:09 +0100
Subject: [PATCH 03/41] Make change event always fire as the user interacts
with the knob
That is, when using:
- touch
- wheel
- typing (by binding to the "input" event)
Previously, typing did not update the knob until focus was lost (and
no change event was fired), and
using the keyboard arrows did not fire any change events.
Also move event triggering to val() and change() so it works always
in the same way and less duplication exists.
Similar to #130 but fixes an issue with `diplayPrevious`
---
index.html | 5 +++--
js/jquery.knob.js | 43 +++++++++++++++----------------------------
2 files changed, 18 insertions(+), 30 deletions(-)
diff --git a/index.html b/index.html
index 7184b74..9352ab0 100755
--- a/index.html
+++ b/index.html
@@ -60,7 +60,8 @@
return false;
}
- }
+ },
+ change: function (val) { console.log("Change: " + val) }
});
// Example of infinite knob, iPod click wheel
@@ -309,4 +310,4 @@ jQuery Knob
jQuery Knob is © 2012 Anthony Terrien and dual licensed under the MIT or GPL licenses.