mirror of
https://github.com/jquery/jquery.git
synced 2025-01-10 18:24:24 +00:00
Allow specific custom events to exit trigger early if there are no handlers bound for that type.
This commit is contained in:
parent
bbd9c776ea
commit
2f11ba7c98
13
src/event.js
13
src/event.js
@ -277,6 +277,14 @@ jQuery.event = {
|
||||
}
|
||||
},
|
||||
|
||||
// Events that are safe to short-circuit if no handlers are attached.
|
||||
// Native DOM events should not be added, they may have inline handlers.
|
||||
customEvent: {
|
||||
"getData": true,
|
||||
"setData": true,
|
||||
"changeData": true
|
||||
},
|
||||
|
||||
trigger: function( event, data, elem ) {
|
||||
// Event object or event type
|
||||
var type = event.type || event,
|
||||
@ -306,6 +314,11 @@ jQuery.event = {
|
||||
event.namespace = namespaces.join(".");
|
||||
event.namespace_re = new RegExp("(^|\\.)" + namespaces.join("\\.(?:.*\\.)?") + "(\\.|$)");
|
||||
|
||||
if ( jQuery.event.customEvent[ type ] && !jQuery.event.global[ type ] ) {
|
||||
// No jQuery handlers for this event type, and it can't have inline handlers
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle a global trigger
|
||||
if ( !elem ) {
|
||||
// Don't bubble custom events when global (to avoid too much overhead)
|
||||
|
Loading…
Reference in New Issue
Block a user