Skip to content

Commit

Permalink
Merge pull request #329 from flightjs/fix-event-currentTarget
Browse files Browse the repository at this point in the history
Add event.currentTarget on delegation
  • Loading branch information
tgvashworth committed Jan 14, 2015
2 parents 414411b + e71062d commit 95bd435
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ define(
Object.keys(rules).forEach(function(selector) {
if (!e.isPropagationStopped() && (parent = target.closest(selector)).length) {
data = data || {};
data.el = parent[0];
e.currentTarget = data.el = parent[0];
return rules[selector].apply(this, [e, data]);
}
}, this);
Expand Down
15 changes: 12 additions & 3 deletions test/spec/utils_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,21 @@ define(['lib/component', 'lib/utils', 'lib/debug'], function (defineComponent, u

$(document.body).trigger('click', myData);

myData.el = document.body;

var callbackArgs = spy.mostRecentCall.args;

expect(spy).toHaveBeenCalledWith(jasmine.any($.Event), myData);
expect(callbackArgs[1].el).toBe(document.body);
});

it('should pass the correct currentTarget', function () {
var instance = (new Component).initialize(document, {'bodySelector': 'body'});

instance.on('click', {
bodySelector: function (event) {
expect(event.currentTarget).toBe(document.body);
}
});

$(window.div).trigger('click');
});

it('makes "this" in delegated function references be the component instance', function () {
Expand Down

0 comments on commit 95bd435

Please sign in to comment.