Skip to content

Commit

Permalink
Merge branch 'fix/drag' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ngryman committed Mar 15, 2013
2 parents 553b7cd + b57494f commit b1299f1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
8 changes: 8 additions & 0 deletions src/jquery.finger.js
Expand Up @@ -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);
}
Expand Down
21 changes: 16 additions & 5 deletions test/jquery.finger_test.js
Expand Up @@ -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);
Expand Down Expand Up @@ -112,7 +110,7 @@

describe('jquery.finger', function() {
beforeEach(function() {
this.$elems = $('#fixtures .touchme');
this.$elems = $('#fixtures').find('.touchme');
});

afterEach(function() {
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit b1299f1

Please sign in to comment.