]> source.dussan.org Git - jquery.git/commitdiff
Don't pass handler function as data for events + test (#1140)
authorBrandon Aaron <brandon.aaron@gmail.com>
Tue, 24 Apr 2007 21:48:52 +0000 (21:48 +0000)
committerBrandon Aaron <brandon.aaron@gmail.com>
Tue, 24 Apr 2007 21:48:52 +0000 (21:48 +0000)
src/event/event.js
src/event/eventTest.js

index 3834fd65f53e21c41971dff4a6621510c12f5cb7..2d9c53056e9765ae49fc4000a87535796f8419ee 100644 (file)
@@ -14,7 +14,7 @@ jQuery.event = {
                        element = window;
                
                // if data is passed, bind to handler 
-               if( data != undefined ) { 
+               if( data != handler ) { 
                // Create temporary function pointer to original handler 
                        var fn = handler; 
 
@@ -55,7 +55,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 +101,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 +274,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 +309,7 @@ jQuery.fn.extend({
                        jQuery.event.add( this, type, function(event) {
                                jQuery(this).unbind(event);
                                return (fn || data).apply( this, arguments);
-                       }, data);
+                       }, fn && data);
                });
        },
 
index d6d1160997902be931926e054168791eb6558398..8d83216181e3f9dd7fae047e88a7faf171ce9f78 100644 (file)
@@ -1,12 +1,12 @@
 module("event");
 
 test("bind()", function() {
-       expect(10);
+       expect(11);
 
        var handler = function(event) {
                ok( event.data, "bind() with data, check passed data exists" );
                ok( event.data.foo == "bar", "bind() with data, Check value of passed data" );
-       }
+       };
        $("#firstp").bind("click", {foo: "bar"}, handler).click();
        
        reset();
@@ -15,9 +15,14 @@ test("bind()", function() {
                ok( event.data.foo == "bar", "Check value of passed data" );
                ok( data, "Check trigger data" );
                ok( data.bar == "foo", "Check value of trigger data" );
-       }
+       };
        $("#firstp").bind("click", {foo: "bar"}, handler).trigger("click", [{bar: "foo"}]);
        
+       var handler = function(event) {
+               ok ( !event.data, "Check that no data is added to the event object" );
+       };
+       $("#firstp").unbind().bind("click", handler).trigger("click");
+       
        // events don't work with iframes, see #939
        var tmp = document.createElement('iframe');
        document.body.appendChild( tmp );
@@ -39,7 +44,7 @@ test("bind()", function() {
        var counter = 0;
        function selectOnChange(event) {
                equals( event.data, counter++, "Event.data is not a global event object" );
-       }
+       };
        $("select").each(function(i){
                $(this).bind('change', i, selectOnChange);
        }).trigger('change');
@@ -90,7 +95,7 @@ test("trigger(event, [data]", function() {
                ok( a == 1, "check passed data" );
                ok( b == "2", "check passed data" );
                ok( c == "abc", "check passed data" );
-       }
+       };
        $("#firstp").bind("click", handler).trigger("click", [1, "2", "abc"]);
 });