Added in support for global event triggering.
This commit is contained in:
parent
b2d15586bd
commit
64179692a0
26
jquery/jquery.js
vendored
26
jquery/jquery.js
vendored
|
@ -812,9 +812,14 @@ jQuery.event = {
|
||||||
}
|
}
|
||||||
handlers[handler.guid] = handler;
|
handlers[handler.guid] = handler;
|
||||||
element["on" + type] = jQuery.event.handle;
|
element["on" + type] = jQuery.event.handle;
|
||||||
|
|
||||||
|
var g = jQuery.event.global;
|
||||||
|
if (!g[type]) g[type] = [];
|
||||||
|
g[type].push( element );
|
||||||
},
|
},
|
||||||
|
|
||||||
guid: 1,
|
guid: 1,
|
||||||
|
global: {},
|
||||||
|
|
||||||
// Detach an event or set of events from an element
|
// Detach an event or set of events from an element
|
||||||
remove: function(element, type, handler) {
|
remove: function(element, type, handler) {
|
||||||
|
@ -830,10 +835,25 @@ jQuery.event = {
|
||||||
jQuery.event.remove( element, j );
|
jQuery.event.remove( element, j );
|
||||||
},
|
},
|
||||||
|
|
||||||
trigger: function(element,type,data) {
|
trigger: function(type,data,element) {
|
||||||
data = data || [ jQuery.event.fix({ type: type }) ];
|
// Touch up the incoming data
|
||||||
if ( element && element["on" + type] )
|
data = data || [];
|
||||||
|
|
||||||
|
// Handle triggering a single element
|
||||||
|
if ( element && element["on" + type] ) {
|
||||||
|
// Pass along a fake event
|
||||||
|
data.shift( jQuery.event.fix({ type: type, target: element }) );
|
||||||
|
|
||||||
|
// Trigger the event
|
||||||
element["on" + type].apply( element, data );
|
element["on" + type].apply( element, data );
|
||||||
|
|
||||||
|
// Handle a global trigger
|
||||||
|
} else if ( !element ) {
|
||||||
|
var g = jQuery.event.global[type];
|
||||||
|
if ( g )
|
||||||
|
for ( var i = 0; i < g.length; i++ )
|
||||||
|
jQuery.event.trigger( type, data, g[i] );
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
handle: function(event) {
|
handle: function(event) {
|
||||||
|
|
Loading…
Reference in a new issue