jquery event: Now using an internal argument to detect if bubbling on $.event.trigger. The other would fail when it receives an event object with target. Also, the target isn't nulled anymore.
In addition, there was a lot of code running O(n) during bubbling while not needed.
This commit is contained in:
parent
989e3f61f7
commit
b2552e6ea3
31
src/event.js
31
src/event.js
|
@ -163,10 +163,11 @@ jQuery.event = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
trigger: function( event, data, elem) {
|
trigger: function( event, data, elem, bubbling /* internal */ ) {
|
||||||
// Event object or event type
|
// Event object or event type
|
||||||
var type = event.type || event;
|
var type = event.type || event;
|
||||||
|
|
||||||
|
if( !bubbling ){
|
||||||
event = typeof event === "object" ?
|
event = typeof event === "object" ?
|
||||||
// jQuery.Event object
|
// jQuery.Event object
|
||||||
event[expando] ? event :
|
event[expando] ? event :
|
||||||
|
@ -190,29 +191,28 @@ jQuery.event = {
|
||||||
if ( this.events && this.events[type] )
|
if ( this.events && this.events[type] )
|
||||||
jQuery.event.trigger( event, data, this.handle.elem );
|
jQuery.event.trigger( event, data, this.handle.elem );
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Handle triggering a single element
|
// Handle triggering a single element
|
||||||
} else {
|
|
||||||
|
|
||||||
// don't do events on text and comment nodes
|
// don't do events on text and comment nodes
|
||||||
if ( elem.nodeType == 3 || elem.nodeType == 8 )
|
if ( !elem || elem.nodeType == 3 || elem.nodeType == 8 )
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|
||||||
// Clone the incoming data, if any
|
|
||||||
data = jQuery.makeArray(data);
|
|
||||||
|
|
||||||
// AT_TARGET phase (not bubbling)
|
// AT_TARGET phase (not bubbling)
|
||||||
if( !event.target ){
|
if( !bubbling ){
|
||||||
// Clean up in case it is reused
|
// Clean up in case it is reused
|
||||||
event.result = undefined;
|
event.result = undefined;
|
||||||
event.target = elem;
|
event.target = elem;
|
||||||
|
|
||||||
|
// Clone the incoming data, if any
|
||||||
|
data = jQuery.makeArray(data);
|
||||||
|
data.unshift( event );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fix for custom events
|
|
||||||
event.currentTarget = elem;
|
event.currentTarget = elem;
|
||||||
|
|
||||||
data.unshift( event );
|
|
||||||
|
|
||||||
var fn = jQuery.isFunction( elem[ type ] );
|
var fn = jQuery.isFunction( elem[ type ] );
|
||||||
|
|
||||||
// Trigger the event, it is assumed that "handle" is a function
|
// Trigger the event, it is assumed that "handle" is a function
|
||||||
|
@ -224,11 +224,10 @@ jQuery.event = {
|
||||||
if ( (!fn || (jQuery.nodeName(elem, 'a') && type == "click")) && elem["on"+type] && elem["on"+type].apply( elem, data ) === false )
|
if ( (!fn || (jQuery.nodeName(elem, 'a') && type == "click")) && elem["on"+type] && elem["on"+type].apply( elem, data ) === false )
|
||||||
event.result = false;
|
event.result = false;
|
||||||
|
|
||||||
// Extra functions don't get the custom event object
|
// data.shift();
|
||||||
data.shift();
|
|
||||||
|
|
||||||
// Trigger the native events (except for clicks on links)
|
// Trigger the native events (except for clicks on links)
|
||||||
if ( event.target === elem && fn && !event.isDefaultPrevented() && !(jQuery.nodeName(elem, 'a') && type == "click") ) {
|
if ( !bubbling && fn && !event.isDefaultPrevented() && !(jQuery.nodeName(elem, 'a') && type == "click") ) {
|
||||||
this.triggered = true;
|
this.triggered = true;
|
||||||
try {
|
try {
|
||||||
elem[ type ]();
|
elem[ type ]();
|
||||||
|
@ -239,14 +238,10 @@ jQuery.event = {
|
||||||
if ( !event.isPropagationStopped() ) {
|
if ( !event.isPropagationStopped() ) {
|
||||||
var parent = elem.parentNode || elem.ownerDocument;
|
var parent = elem.parentNode || elem.ownerDocument;
|
||||||
if ( parent )
|
if ( parent )
|
||||||
jQuery.event.trigger(event, data, parent);
|
jQuery.event.trigger(event, data, parent, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean up, in case the event object is reused
|
|
||||||
event.target = null;
|
|
||||||
|
|
||||||
this.triggered = false;
|
this.triggered = false;
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
handle: function(event) {
|
handle: function(event) {
|
||||||
|
|
Loading…
Reference in a new issue