diff options
author | Brandon Aaron <brandon.aaron@gmail.com> | 2007-02-25 19:36:29 +0000 |
---|---|---|
committer | Brandon Aaron <brandon.aaron@gmail.com> | 2007-02-25 19:36:29 +0000 |
commit | 34cb5b5812db50d921f7c7a0c398eb68167b3da3 (patch) | |
tree | cafeb0a2f9e6dd212887f2ec2d05d10f31ce9a3e /src | |
parent | b15ae79a389299cac19f59ed14efafc3e9d8ef0d (diff) | |
download | jquery-34cb5b5812db50d921f7c7a0c398eb68167b3da3.tar.gz jquery-34cb5b5812db50d921f7c7a0c398eb68167b3da3.zip |
Fix for #964
Diffstat (limited to 'src')
-rw-r--r-- | src/event/event.js | 30 | ||||
-rw-r--r-- | src/event/eventTest.js | 6 |
2 files changed, 29 insertions, 7 deletions
diff --git a/src/event/event.js b/src/event/event.js index e7f920f9b..fb7f820ca 100644 --- a/src/event/event.js +++ b/src/event/event.js @@ -55,18 +55,36 @@ jQuery.event = { // Detach an event or set of events from an element remove: function(element, type, handler) { - if (element.$events) - if ( type && type.type ) - delete element.$events[ type.type ][ type.handler.guid ]; - else if (type && element.$events[type]) + if (element.$events) { + var i,j,k; + if ( type && type.type ) { // type is actually an event object here + handler = type.handler; + type = type.type; + } + + if (type && element.$events[type]) + // remove the given handler for the given type if ( handler ) delete element.$events[type][handler.guid]; + + // remove all handlers for the given type else - for ( var i in element.$events[type] ) + for ( i in element.$events[type] ) delete element.$events[type][i]; + + // remove all handlers else - for ( var j in element.$events ) + for ( j in element.$events ) this.remove( element, j ); + + // remove event handler if no more handlers exist + for ( k in element.$events[type] ) + if (k) { + k = true; + break; + } + if (!k) element["on" + type] = null; + } }, trigger: function(type, data, element) { diff --git a/src/event/eventTest.js b/src/event/eventTest.js index 9615e0b63..a71e01b77 100644 --- a/src/event/eventTest.js +++ b/src/event/eventTest.js @@ -15,7 +15,7 @@ test("toggle(Function, Function) - add toggle event and fake a few clicks", func }); test("unbind(event)", function() { - expect(3); + expect(4); var el = $("#firstp"); el.click(function() { ok( true, "Fake normal bind" ); @@ -25,6 +25,10 @@ test("unbind(event)", function() { ok( true, "Fake onebind" ); }); el.click().click(); + + el.click(function() { return; }); + el.unbind('click'); + ok( !el[0].onclick, "Handler is removed" ); // Bug #964 }); test("trigger(event, [data]", function() { |