Skip to content

Commit

Permalink
Only create event proxies when there is a matching delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
sstephenson committed Dec 11, 2010
1 parent 43f66b6 commit a8ad54d
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/event.js
Expand Up @@ -72,11 +72,13 @@
$.fn.delegate = function(selector, event, callback){
return this.each(function(element){
add(element, event, callback, selector, function(e){
var target = e.target, nodes = $$(element, selector), proxy = createProxy(e);
var target = e.target, nodes = $$(element, selector);
while (target && nodes.indexOf(target) < 0) target = target.parentNode;
$.extend(proxy, {currentTarget: target, liveFired: element});
if (target && !(target === element) && !(target === document))
callback.call(target, proxy);
if (target && !(target === element) && !(target === document)) {
callback.call(target, $.extend(createProxy(e), {
currentTarget: target, liveFired: element
}));
}
});
});
};
Expand Down

0 comments on commit a8ad54d

Please sign in to comment.