Skip to content

Commit 735be83

Browse files
committed
added event propagation when outside bounds
added a few functions to allow stacking of knobs without the upper ones interfering with the ones underneath
1 parent 5ce9ff5 commit 735be83

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

js/jquery.knob.js

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,12 @@
370370
s.change(s._validate(v));
371371
s._draw();
372372
};
373-
373+
374+
if(!s.bounds(e))
375+
{
376+
s._propagate(e);
377+
return;
378+
}
374379
// First click
375380
mouseMove(e);
376381
// scrubbing has started
@@ -476,6 +481,16 @@
476481
var val = (~~ (((v < 0) ? -0.5 : 0.5) + (v/this.o.step))) * this.o.step;
477482
return Math.round(val * 100) / 100;
478483
};
484+
485+
// propagate event to element underneath
486+
this._propagate = function(e)
487+
{
488+
s.$div.css("pointer-events", "none");
489+
var ne = jQuery.Event( e.type, { which:1, pageX: e.pageX, pageY: e.pageY } );
490+
var nt = document.elementFromPoint(e.pageX, e.pageY);
491+
$(nt).trigger(ne);
492+
s.$div.css("pointer-events", "auto");
493+
}
479494

480495
// Abstract methods
481496
this.listen = function () {}; // on start, one time
@@ -815,6 +830,37 @@
815830
c.stroke();
816831
};
817832

833+
this.bounds = function(e)
834+
{
835+
if(e.type == "mousedown")
836+
{
837+
var x = e.pageX;
838+
var y = e.pageY;
839+
}
840+
if(e.type == "touchstart")
841+
{
842+
var touch = e.originalEvent.touches[0];
843+
var x = touch.pageX;
844+
var y = touch.pageY;
845+
}
846+
847+
/*
848+
TODO: fix issues with this.xy and this.radius
849+
seeming incorrect when emulating mobile devices
850+
*/
851+
var ox = x - this.x - this.xy;
852+
var oy = y - this.y - this.xy;
853+
854+
if(Math.sqrt((ox*ox) + (oy*oy)) < this.xy)
855+
{
856+
return true;
857+
}
858+
else
859+
{
860+
return false;
861+
}
862+
}
863+
818864
this.cancel = function () {
819865
this.val(this.v);
820866
};

0 commit comments

Comments
 (0)