handle = jQuery.data(elem, "handle") || jQuery.data(elem, "handle", function(){
// Handle the second event of a trigger and when
// an event is called after a page has unloaded
- if ( typeof jQuery !== "undefined" && !jQuery.event.triggered )
- return jQuery.event.handle.apply(arguments.callee.elem, arguments);
+ return typeof jQuery !== "undefined" && !jQuery.event.triggered ?
+ jQuery.event.handle.apply(arguments.callee.elem, arguments) :
+ undefined;
});
// Add elem as a property of the handle function
// This is to prevent a memory leak with non-native
jQuery.each(types.split(/\s+/), function(index, type) {
// Namespaced event handlers
var parts = type.split(".");
- type = parts[0];
- handler.type = parts[1];
+ type = parts.shift();
+ handler.type = parts.sort().join(".");
// Get the current list of functions bound to this event
var handlers = events[type];
// jQuery(...).unbind("mouseover mouseout", fn);
jQuery.each(types.split(/\s+/), function(index, type){
// Namespaced event handlers
- var parts = type.split(".");
- type = parts[0];
+ var namespace = type.split(".");
+ type = namespace.shift();
+ namespace = RegExp("(^|\\.)" + namespace.sort().join(".*\\.") + "(\\.|$)");
if ( events[type] ) {
// remove the given handler for the given type
else
for ( handler in events[type] )
// Handle the removal of namespaced events
- if ( !parts[1] || events[type][handler].type == parts[1] )
+ if ( namespace.test(events[type][handler].type) )
delete events[type][handler];
// remove generic event handler if no more handlers exist
// Namespaced event handlers
namespace = event.type.split(".");
- event.type = namespace[0];
- namespace = namespace[1];
+ event.type = namespace.shift();
+
// Cache this now, all = true means, any handler
- all = !namespace && !event.exclusive;
+ all = !namespace.length && !event.exclusive;
+
+ namespace = RegExp("(^|\\.)" + namespace.sort().join(".*\\.") + "(\\.|$)");
handlers = ( jQuery.data(this, "events") || {} )[event.type];
var handler = handlers[j];
// Filter the functions by class
- if ( all || handler.type == namespace ) {
+ if ( all || namespace.test(handler.type) ) {
// Pass in a reference to the handler function itself
// So that we can later remove it
event.handler = handler;