unbind handlers with data + test (#935)
[jquery.git] / src / event / event.js
index 3834fd6..a3db2f3 100644 (file)
@@ -32,8 +32,11 @@ jQuery.event = {
                }
 
                // Make sure that the function being executed has a unique ID
-               if ( !handler.guid )
+               if ( !handler.guid ) {
                        handler.guid = this.guid++;
+                       // Don't forget to set guid for the original handler function
+                       if (fn) fn.guid = handler.guid;
+               }
 
                // Init the element's event structure
                if (!element.$events)
@@ -55,7 +58,7 @@ jQuery.event = {
                        if (element.addEventListener)
                                element.addEventListener(type, element.$handle, false);
                        else if (element.attachEvent)
-                               element.attachEvent("on" + type, element.$handle, false);
+                               element.attachEvent("on" + type, element.$handle);
                }
 
                // Add the function to the element's handler list
@@ -101,7 +104,7 @@ jQuery.event = {
                                        if (element.removeEventListener)
                                                element.removeEventListener(type, element.$handle, false);
                                        else if (element.detachEvent)
-                                               element.detachEvent("on" + type, element.$handle, false);
+                                               element.detachEvent("on" + type, element.$handle);
                                        ret = null;
                                        delete events[type];
                                }
@@ -274,7 +277,7 @@ jQuery.fn.extend({
         */
        bind: function( type, data, fn ) {
                return this.each(function(){
-                       jQuery.event.add( this, type, fn || data, data );
+                       jQuery.event.add( this, type, fn || data, fn && data );
                });
        },
        
@@ -309,7 +312,7 @@ jQuery.fn.extend({
                        jQuery.event.add( this, type, function(event) {
                                jQuery(this).unbind(event);
                                return (fn || data).apply( this, arguments);
-                       }, data);
+                       }, fn && data);
                });
        },