Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add event.currentTarget on delegation #329

Merged
merged 2 commits into from
Jan 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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