From bbbefc71f15f11c0891399993e635b7f0d2219d4 Mon Sep 17 00:00:00 2001 From: Giuseppe Gurgone Date: Thu, 18 Sep 2014 11:07:12 +0200 Subject: [PATCH] Pass the correct event.currentTarget on delegation Removes data.el from the event data payload Fixes #290 --- lib/utils.js | 2 +- test/spec/utils_spec.js | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index 6b48cb8c..1f94772a 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -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); diff --git a/test/spec/utils_spec.js b/test/spec/utils_spec.js index 6e15e383..ceb49a61 100644 --- a/test/spec/utils_spec.js +++ b/test/spec/utils_spec.js @@ -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'}; @@ -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 () {