Browse files

fixed multiple targets for drag.

  • Loading branch information...
1 parent 553b7cd commit 1b4b8e72452143e6a0b4d1cd4925f735f99fe84e @ngryman committed Mar 15, 2013
Showing with 21 additions and 0 deletions.
  1. +7 −0 src/jquery.finger.js
  2. +14 −0 test/jquery.finger_test.js
View
7 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);
}
View
14 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() {

0 comments on commit 1b4b8e7

Please sign in to comment.