Skip to content

Commit

Permalink
fixed #10, drag across children.
Browse files Browse the repository at this point in the history
  • Loading branch information
ngryman committed Oct 1, 2014
1 parent cc1fae7 commit dc7ea18
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
10 changes: 6 additions & 4 deletions src/jquery.finger.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@

// for delegated events, the target may change over time
// this ensures we notify the right target and simulates the mouseleave behavior
while (event.target && event.target !== start.target)
event.target = event.target.parentNode;
if (event.target !== start.target) {
event.target = start.target;
stopHandler.call(this, $.Event(stopEvent + '.' + namespace, event));
Expand All @@ -138,18 +140,18 @@
// always clears press timeout
clearTimeout(timeout);

// ensures start target and end target are the same
if (event.target !== start.target) return;

// tap-like events
if (!motion && !cancel) {
// triggered only if targets match
if (!motion && !cancel && event.target === start.target) {
var doubleTap = prevEl === event.target && timeStamp - prevTime < Finger.doubleTapInterval;
evtName = doubleTap ? 'doubletap' : 'tap';
prevEl = doubleTap ? null : start.target;
prevTime = timeStamp;
}
// motion events
else {
// ensure last target is set the initial one
event.target = start.target;
if (dt < Finger.flickDuration) trigger(event, 'flick');
move.end = true;
evtName = 'drag';
Expand Down
4 changes: 3 additions & 1 deletion test/jquery.finger.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

<!-- test styles -->
<style>
body { -webkit-user-select: none; }
#fixtures { position: fixed; top: 0; left: 0; }
.touchme {
width: 100px;
Expand All @@ -34,7 +35,8 @@
mocha.setup({
ui: 'bdd',
slow: 100,
bail: true
bail: true,
ignoreLeaks: true
});
</script>

Expand Down
16 changes: 7 additions & 9 deletions test/jquery.finger_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,23 +386,21 @@
});
});

xit('should correctly fire if binded to an element that has child and target changes', function(done) {
var targets = [], end = false;
$('body').on('drag', function(e) {
if (!~targets.indexOf(e.target)) {
targets.push(e.target);
}
it('should correctly fire if binded to an element that has child and target changes', function(done) {
var end = false, y = 0;
$('#fixtures').css('padding', 10).on('drag', function(e) {
y = e.y;
end = e.end;
});
this.pointer.drag(0, 200, function() {
targets.length.should.equal(2);
this.pointer.drag(0, 300, function() {
y.should.be.greaterThan(200);
end.should.be.truthy;
done();
});
});
});

describe('flick event', function() {
xdescribe('flick event', function() {
it('should work with direct events', function(done) {
var handler = sinon.spy();
this.$elems.on('flick', handler);
Expand Down

0 comments on commit dc7ea18

Please sign in to comment.