This commit is contained in:
Brandon Aaron 2007-02-25 19:36:29 +00:00
parent b15ae79a38
commit 34cb5b5812
3 changed files with 30 additions and 7 deletions

View file

@ -4,6 +4,7 @@
=== 1.1.2 === === 1.1.2 ===
* Event handlers (like element.onclick) are now removed when no more functions are bound to the event.
* Fixed DOM Manipulations for form elements. * Fixed DOM Manipulations for form elements.
* Fixed jQuery.isFunction to return false on nodes. * Fixed jQuery.isFunction to return false on nodes.
* Fixed jQuery.className.has, escaping regex characters in className (for metadata) * Fixed jQuery.className.has, escaping regex characters in className (for metadata)

View file

@ -55,18 +55,36 @@ jQuery.event = {
// Detach an event or set of events from an element // Detach an event or set of events from an element
remove: function(element, type, handler) { remove: function(element, type, handler) {
if (element.$events) if (element.$events) {
if ( type && type.type ) var i,j,k;
delete element.$events[ type.type ][ type.handler.guid ]; if ( type && type.type ) { // type is actually an event object here
else if (type && element.$events[type]) handler = type.handler;
type = type.type;
}
if (type && element.$events[type])
// remove the given handler for the given type
if ( handler ) if ( handler )
delete element.$events[type][handler.guid]; delete element.$events[type][handler.guid];
// remove all handlers for the given type
else else
for ( var i in element.$events[type] ) for ( i in element.$events[type] )
delete element.$events[type][i]; delete element.$events[type][i];
// remove all handlers
else else
for ( var j in element.$events ) for ( j in element.$events )
this.remove( element, j ); 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) { trigger: function(type, data, element) {

View file

@ -15,7 +15,7 @@ test("toggle(Function, Function) - add toggle event and fake a few clicks", func
}); });
test("unbind(event)", function() { test("unbind(event)", function() {
expect(3); expect(4);
var el = $("#firstp"); var el = $("#firstp");
el.click(function() { el.click(function() {
ok( true, "Fake normal bind" ); ok( true, "Fake normal bind" );
@ -25,6 +25,10 @@ test("unbind(event)", function() {
ok( true, "Fake onebind" ); ok( true, "Fake onebind" );
}); });
el.click().click(); el.click().click();
el.click(function() { return; });
el.unbind('click');
ok( !el[0].onclick, "Handler is removed" ); // Bug #964
}); });
test("trigger(event, [data]", function() { test("trigger(event, [data]", function() {