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
5 changes: 4 additions & 1 deletion 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>
<!--[if IE]><script type="text/javascript" src="excanvas.js"></script><![endif]-->
<script src="dist/jquery.knob.min.js"></script>
<script src="js/jquery.knob.js"></script>
<script>
$(function($) {

Expand All @@ -16,6 +16,9 @@
//console.log(this.$.attr('value'));
console.log("release : " + value);
},
tick : function (value) {
console.log("tick : " + value);
},
cancel : function () {
console.log("cancel : ", this);
},
Expand Down
22 changes: 17 additions & 5 deletions js/jquery.knob.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
this.g = null; // deprecated 2D graphics context for 'pre-rendering'
this.v = null; // value ; mixed array or integer
this.cv = null; // change value ; not commited value
this.tv = null; // tick value ; integer
this.x = 0; // canvas x position
this.y = 0; // canvas y position
this.w = 0; // canvas width
Expand Down Expand Up @@ -126,6 +127,7 @@
change: null, // function (value) {}
cancel: null, // function () {}
release: null, // function (value) {}
tick: null, // function (value) {}

// Output formatting, allows to add unit: %, ms ...
format: function(v) {
Expand Down Expand Up @@ -159,21 +161,20 @@
function () {
var val = {};
val[k] = $this.val();
s.val(s._validate(val));
s.change(s._validate(val));
}
);
});
this.$.find('legend').remove();
} else {

// input = integer
this.i = this.$;
this.v = this.o.parse(this.$.val());
this.v === '' && (this.v = this.o.min);
this.$.bind(
'change blur',
function () {
s.val(s._validate(s.o.parse(s.$.val())));
s.change(s._validate(s.o.parse(s.$.val())));
}
);

Expand Down Expand Up @@ -467,6 +468,7 @@
this.val = function (v) {}; // on release
this.xy2val = function (x, y) {}; //
this.draw = function () {}; // on change / on release
this.tick = function () {}; // on value change
this.clear = function () { this._clear(); };

// Utils
Expand Down Expand Up @@ -525,6 +527,7 @@
&& this.rH(v) === false) { return; }

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();
Expand Down Expand Up @@ -726,10 +729,19 @@
};

this.change = function (v) {
this.cv = v;
this.cv = v;
this.tick(v);
this.$.val(this.o.format(v));
};

this.tick = function (v) {
var fv = this.o.format(v);
if (this.tv != fv) {
this.tv = fv;
if (typeof(this.o.tick) === typeof(Function)){
this.o.tick(fv);
}
}
}
this.angle = function (v) {
return (v - this.o.min) * this.angleArc / (this.o.max - this.o.min);
};
Expand Down