diff --git a/src/jquery.finger.js b/src/jquery.finger.js index 6625b87..c7e7bad 100644 --- a/src/jquery.finger.js +++ b/src/jquery.finger.js @@ -60,6 +60,14 @@ } } + // for delegated events, the target may change over time + // this ensures we notify the right target and simulates the mouseleave behavior + if (event.target !== data.start.target) { + event.target = data.start.target; + stopHandler.call(this, $.Event(stopEvent + '.finger', event)); + return; + } + // fire drag event $.event.trigger($.Event('drag' + $.expando, data.move), null, event.target); } diff --git a/test/jquery.finger_test.js b/test/jquery.finger_test.js index dee7665..c75bc56 100644 --- a/test/jquery.finger_test.js +++ b/test/jquery.finger_test.js @@ -38,10 +38,8 @@ this.tapStart(); (function mv() { - var now = Date.now(), - dt = now - last; - - t += dt; + var now = Date.now(); + t += now - last; if (t >= duration) { self.tapEnd(); callback.call(self); @@ -112,7 +110,7 @@ describe('jquery.finger', function() { beforeEach(function() { - this.$elems = $('#fixtures .touchme'); + this.$elems = $('#fixtures').find('.touchme'); }); afterEach(function() { @@ -339,6 +337,19 @@ }, 100, 100); }, 100, 100); }); + + it('should correctly stop at the edge of an element for delegated events', function(done) { + var targets = []; + $('body').on('drag', '.touchme', function(event) { + if (-1 == targets.indexOf(event.target)) { + targets.push(event.target); + } + }); + this.drag(function() { + targets.length.should.equal(1); + done(); + }, 0, 200); + }); }); describe('flick event', function() {