Short-circuit jQuery.event.fix if it has already fixed the current event object.
[jquery.git] / src / event.js
index b27b418..fa8be8d 100644 (file)
@@ -102,7 +102,7 @@ jQuery.event = {
 
                if ( events ) {
                        // Unbind all events for the element
-                       if ( !types )
+                       if ( types == undefined )
                                for ( var type in events )
                                        this.remove( elem, type );
                        else {
@@ -196,7 +196,7 @@ jQuery.event = {
                                data.shift();
 
                        // Handle triggering of extra function
-                       if ( extra ) {
+                       if ( extra && jQuery.isFunction( extra ) ) {
                                // call the extra function and tack the current return value on the end for possible inspection
                                var ret = extra.apply( elem, data.concat( val ) );
                                // if anything is returned, give it precedence and have it overwrite the previous value
@@ -263,11 +263,18 @@ jQuery.event = {
        },
 
        fix: function(event) {
+               // Short-circuit if the event has already been fixed by jQuery.event.fix
+               if ( event[ expando ] )
+                       return event;
+                       
                // store a copy of the original event object 
                // and clone to set read-only properties
                var originalEvent = event;
                event = jQuery.extend({}, originalEvent);
                
+               // Mark the event as fixed by jQuery.event.fix
+               event[ expando ] = true;
+               
                // add preventDefault and stopPropagation since 
                // they will not work on the clone
                event.preventDefault = function() {