Fix for #181
[jquery.git] / src / event / event.js
index 55e205a..19bb4f6 100644 (file)
@@ -1583,8 +1583,8 @@ new function(){
                var o = e[i];
                
                // Handle event binding
-               jQuery.fn[o] = function(f, amount){
-                       return f ? this.bind(o, f, amount) : this.trigger(o);
+               jQuery.fn[o] = function(f){
+                       return f ? this.bind(o, f) : this.trigger(o);
                };
                
                // Handle event unbinding
@@ -1592,8 +1592,16 @@ new function(){
                
                // Finally, handle events that only fire once
                jQuery.fn["one"+o] = function(f){
-                       // use bind with amount param to bind only once
-                       return this.bind(o, f, 1);
+                       // save cloned reference to this
+                       var element = jQuery(this);
+                       var handler = function() {
+                               // unbind itself when executed
+                               element.unbind(o, handler);
+                               element = null;
+                               // apply original handler with the same arguments
+                               f.apply(this, arguments);
+                       };
+                       return this.bind(o, handler);
                };
                        
        };
@@ -1613,11 +1621,12 @@ new function(){
        
                // Use the defer script hack
                var script = document.getElementById("__ie_init");
-               script.onreadystatechange = function() {
-                       if ( this.readyState != "complete" ) return;
-                       this.parentNode.removeChild( this );
-                       jQuery.ready();
-               };
+               if (script) // script does not exist if jQuery is loaded dynamically
+                       script.onreadystatechange = function() {
+                               if ( this.readyState != "complete" ) return;
+                               this.parentNode.removeChild( this );
+                               jQuery.ready();
+                       };
        
                // Clear from memory
                script = null;