Skip to content

added update event listener #242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
37 changes: 33 additions & 4 deletions js/jquery.knob.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
this.relativeWidth = false;
this.relativeHeight = false;
this.$div = null; // component div
this.scrubbing = false; // the user is currently scrubbing the dial

this.run = function () {
var cf = function (e, conf) {
Expand Down Expand Up @@ -176,7 +177,13 @@
s.val(s._validate(s.o.parse(s.$.val())));
}
);


this.$.bind(
'update',
function () {
s.val(s._validate(s.o.parse(s.$.val())), false);
}
);
}

!this.o.displayInput && this.$.hide();
Expand Down Expand Up @@ -333,14 +340,18 @@

// First touch
touchMove(e);

// scrubbing has started
s.scrubbing = true;

// Touch events listeners
k.c.d
.bind("touchmove.k", touchMove)
.bind(
"touchend.k",
function () {
k.c.d.unbind('touchmove.k touchend.k');
// scrubbing has ended
s.scrubbing = false;
s.val(s.cv);
}
);
Expand All @@ -362,6 +373,8 @@

// First click
mouseMove(e);
// scrubbing has started
s.scrubbing = true;

// Mouse events listeners
k.c.d
Expand All @@ -377,12 +390,17 @@
return;

s.cancel();

// scrubbing has ended
s.scrubbing = false;
}
}
)
.bind(
"mouseup.k",
function (e) {
// scrubbing has ended
s.scrubbing = false;
k.c.d.unbind('mousemove.k mouseup.k keyup.k');
s.val(s.cv);
}
Expand Down Expand Up @@ -523,9 +541,17 @@
&& v != this.v
&& this.rH
&& this.rH(v) === false) { return; }

if(!this.scrubbing)
{
this.cv = this.o.stopper ? max(min(v, this.o.max), this.o.min) : v;
this.v = this.cv;
}
else if(triggerRelease === false)
{
this.v = this.o.stopper ? max(min(v, this.o.max), this.o.min) : v;
}

this.cv = this.o.stopper ? max(min(v, this.o.max), this.o.min) : v;
this.v = this.cv;
this.$.val(this.o.format(this.v));
this._draw();
} else {
Expand Down Expand Up @@ -580,6 +606,9 @@

v = max(min(v, s.o.max), s.o.min);

// trigger change handler
if (s.cH && (s.cH(v) === false)) return;

s.val(v, false);

if (s.rH) {
Expand Down