Skip to content

Commit

Permalink
Pass the correct event.currentTarget on delegation
Browse files Browse the repository at this point in the history
Removes data.el from the event data payload
Fixes #290
  • Loading branch information
giuseppeg authored and Tom Ashworth committed Jan 14, 2015
1 parent 414411b commit bbbefc7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 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 = parent[0];
return rules[selector].apply(this, [e, data]);
}
}, this);
Expand Down
15 changes: 11 additions & 4 deletions test/spec/utils_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ define(['lib/component', 'lib/utils', 'lib/debug'], function (defineComponent, u
});
})();

it('should pass event, and data (inc. el property) to its callbacks', function () {
it('should pass event, and data to its callbacks', function () {
var instance = (new Component).initialize(document, {'bodySelector': 'body'});
var myData = {blah: 'blah'};

Expand All @@ -255,12 +255,19 @@ define(['lib/component', 'lib/utils', 'lib/debug'], function (defineComponent, u

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

myData.el = document.body;
expect(spy).toHaveBeenCalledWith(jasmine.any($.Event), myData);
});

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

expect(spy).toHaveBeenCalledWith(jasmine.any($.Event), myData);
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 bbbefc7

Please sign in to comment.