From 1b4b8e72452143e6a0b4d1cd4925f735f99fe84e Mon Sep 17 00:00:00 2001 From: Nicolas Gryman Date: Fri, 15 Mar 2013 19:01:13 -0400 Subject: [PATCH 1/2] fixed multiple targets for drag. --- src/jquery.finger.js | 7 +++++++ test/jquery.finger_test.js | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/jquery.finger.js b/src/jquery.finger.js index 6625b87..c7274e8 100644 --- a/src/jquery.finger.js +++ b/src/jquery.finger.js @@ -60,6 +60,13 @@ } } + // 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) { + 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..69e09b3 100644 --- a/test/jquery.finger_test.js +++ b/test/jquery.finger_test.js @@ -339,6 +339,20 @@ }, 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) { + console.log(event.target); + 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() { From b57494f9f4b6f33fe7bd3cb055d77657866901ea Mon Sep 17 00:00:00 2001 From: Nicolas Gryman Date: Fri, 15 Mar 2013 19:45:21 -0400 Subject: [PATCH 2/2] fixed wrong target for end drag event. --- src/jquery.finger.js | 1 + test/jquery.finger_test.js | 9 +++------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/jquery.finger.js b/src/jquery.finger.js index c7274e8..c7e7bad 100644 --- a/src/jquery.finger.js +++ b/src/jquery.finger.js @@ -63,6 +63,7 @@ // 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; } diff --git a/test/jquery.finger_test.js b/test/jquery.finger_test.js index 69e09b3..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() { @@ -343,7 +341,6 @@ it('should correctly stop at the edge of an element for delegated events', function(done) { var targets = []; $('body').on('drag', '.touchme', function(event) { - console.log(event.target); if (-1 == targets.indexOf(event.target)) { targets.push(event.target); }