]> source.dussan.org Git - jquery.git/commitdiff
unbind handlers with data + test (#935)
authorBrandon Aaron <brandon.aaron@gmail.com>
Tue, 24 Apr 2007 22:35:04 +0000 (22:35 +0000)
committerBrandon Aaron <brandon.aaron@gmail.com>
Tue, 24 Apr 2007 22:35:04 +0000 (22:35 +0000)
src/event/event.js
src/event/eventTest.js

index 9b5feb1526c1bbf23306c0eb39de041fb152c17b..a3db2f3ab0bcb501fe85903d0175c4e253913390 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)
index 8d83216181e3f9dd7fae047e88a7faf171ce9f78..15e66313e8c56a3906c29db6950d7c378d9a1637 100644 (file)
@@ -1,13 +1,15 @@
 module("event");
 
 test("bind()", function() {
-       expect(11);
+       expect(12);
 
        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();
+       $("#firstp").bind("click", {foo: "bar"}, handler).click().unbind("click", handler);
+       
+       ok( !$("#firstp").get(0).$events, "Event handler unbound when using data." );
        
        reset();
        var handler = function(event, data) {
@@ -16,12 +18,14 @@ test("bind()", function() {
                ok( data, "Check trigger data" );
                ok( data.bar == "foo", "Check value of trigger data" );
        };
-       $("#firstp").bind("click", {foo: "bar"}, handler).trigger("click", [{bar: "foo"}]);
+       $("#firstp").bind("click", {foo: "bar"}, handler).trigger("click", [{bar: "foo"}]).unbind(handler);
        
+       reset();
        var handler = function(event) {
                ok ( !event.data, "Check that no data is added to the event object" );
        };
-       $("#firstp").unbind().bind("click", handler).trigger("click");
+       $("#firstp").bind("click", handler).trigger("click");
+       
        
        // events don't work with iframes, see #939
        var tmp = document.createElement('iframe');