Fix for #1061
[jquery.git] / src / event / event.js
index 61bd4e8..0acdf6b 100644 (file)
@@ -32,35 +32,38 @@ 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)
                        element.$events = {};
-
-               // Get the current list of functions bound to this event
-               var handlers = element.$events[type];
-
-               // Init the event handler queue
-               if (!handlers)
-                       handlers = element.$events[type] = {};
-
-               // Add the function to the element's handler list
-               handlers[handler.guid] = handler;
                
-               if (!element.$handle) {
+               if (!element.$handle)
                        element.$handle = function() {
                                jQuery.event.handle.apply(element, arguments);
                        };
 
+               // Get the current list of functions bound to this event
+               var handlers = element.$events[type];
+
+               // Init the event handler queue
+               if (!handlers) {
+                       handlers = element.$events[type] = {};  
+                       
                        // And bind the global event handler to the element
                        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
+               handlers[handler.guid] = handler;
+
                // Remember the function in a global list (for triggering)
                if (!this.global[type])
                        this.global[type] = [];
@@ -101,8 +104,8 @@ jQuery.event = {
                                        if (element.removeEventListener)
                                                element.removeEventListener(type, element.$handle, false);
                                        else if (element.detachEvent)
-                                               element.detachEvent("on" + type, element.$handle, false);
-                                       ret = element.$handle = null;
+                                               element.detachEvent("on" + type, element.$handle);
+                                       ret = null;
                                        delete events[type];
                                }
                        }
@@ -110,7 +113,7 @@ jQuery.event = {
                        // Remove the expando if it's no longer used
                        for ( ret in events ) break;
                        if ( !ret )
-                               element.$events = null;
+                               element.$handle = element.$events = null;
                }
        },
 
@@ -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);
                });
        },
 
@@ -548,6 +551,9 @@ jQuery.extend({
                        // Remove event lisenter to avoid memory leak
                        if ( jQuery.browser.mozilla || jQuery.browser.opera )
                                document.removeEventListener( "DOMContentLoaded", jQuery.ready, false );
+                       
+                       // Remove script element used by IE hack
+                       jQuery(window).load(function(){ jQuery("#__ie_init").remove(); });
                }
        }
 });
@@ -925,7 +931,6 @@ new function(){
                if ( script ) 
                        script.onreadystatechange = function() {
                                if ( this.readyState != "complete" ) return;
-                               this.parentNode.removeChild( this );
                                jQuery.ready();
                        };