From 84d2307e0e20e9245523731a4450314cc0de6a95 Mon Sep 17 00:00:00 2001 From: Dave Methvin Date: Mon, 24 Oct 2011 11:17:24 -0400 Subject: Fix #10563. Ensure event.currentTarget==this if delegated. Now, event.delegateTarget is always the element where the event was handled, regardless of whether delegated handlers are attached. --- src/event.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/event.js b/src/event.js index 488d3bae9..a6cd82379 100644 --- a/src/event.js +++ b/src/event.js @@ -412,7 +412,7 @@ jQuery.event = { // Use the fix-ed jQuery.Event rather than the (read-only) native event args[0] = event; - event.currentTarget = this; + event.delegateTarget = this; // Determine handlers that should run if there are delegated events // Avoid disabled elements in IE (#6911) and non-left-click bubbling in Firefox (#3861) @@ -447,8 +447,11 @@ jQuery.event = { handlerQueue.push({ elem: this, matches: handlers.slice( delegateCount ) }); } + // Run delegates first; they may want to stop propagation beneath us for ( i = 0; i < handlerQueue.length && !event.isPropagationStopped(); i++ ) { matched = handlerQueue[ i ]; + event.currentTarget = matched.elem; + for ( j = 0; j < matched.matches.length && !event.isImmediatePropagationStopped(); j++ ) { handleObj = matched.matches[ j ]; @@ -456,9 +459,6 @@ jQuery.event = { // 2) have namespace(s) a subset or equal to those in the bound event (both can have no namespace). if ( run_all || (!event.namespace && !handleObj.namespace) || event.namespace_re && event.namespace_re.test( handleObj.namespace ) ) { - // Pass in a reference to the handler function itself - // So that we can later remove it - event.handler = handleObj.handler; event.data = handleObj.data; event.handleObj = handleObj; @@ -929,7 +929,7 @@ jQuery.fn.extend({ if ( types && types.preventDefault && types.handleObj ) { // ( event ) dispatched jQuery.Event var handleObj = types.handleObj; - jQuery( types.currentTarget ).off( + jQuery( types.delegateTarget ).off( handleObj.namespace? handleObj.type + "." + handleObj.namespace : handleObj.type, handleObj.selector, handleObj.handler -- cgit v1.2.3