X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fevent.js;h=3e0a885d86125cdf905e2ce50295aba2a295a2c7;hb=709df933049ccce53d0b6bb510ad9c39fd6304fe;hp=cb68c38bbf76cbfb33cf89a1091b1323e023292e;hpb=bdd6aca209fe79bc6a085693008436cce37d5b31;p=jquery.git diff --git a/src/event.js b/src/event.js index cb68c38..3e0a885 100644 --- a/src/event.js +++ b/src/event.js @@ -49,10 +49,14 @@ jQuery.event = { if ( typeof jQuery == "undefined" || jQuery.event.triggered ) return val; - val = jQuery.event.handle.apply(elem, arguments); + val = jQuery.event.handle.apply(arguments.callee.elem, arguments); return val; }); + // Add elem as a property of the handle function + // This is to prevent a memory leak with non-native + // event in IE. + handle.elem = elem; // Handle multiple events seperated by a space // jQuery(...).bind("mouseover mouseout", fn); @@ -87,6 +91,9 @@ jQuery.event = { // Keep track of which events have been used, for global triggering jQuery.event.global[type] = true; }); + + // Nullify elem to prevent memory leaks in IE + elem = null; }, guid: 1, @@ -150,6 +157,8 @@ jQuery.event = { // Remove the expando if it's no longer used for ( ret in events ) break; if ( !ret ) { + var handle = jQuery.data( elem, "handle" ); + if ( handle ) handle.elem = null; jQuery.removeData( elem, "events" ); jQuery.removeData( elem, "handle" ); } @@ -198,7 +207,7 @@ jQuery.event = { // Handle triggering of extra function if ( extra && jQuery.isFunction( extra ) ) { // call the extra function and tack the current return value on the end for possible inspection - var ret = extra.apply( elem, data.concat( val ) ); + ret = extra.apply( elem, val == null ? data : data.concat( val ) ); // if anything is returned, give it precedence and have it overwrite the previous value if (ret !== undefined) val = ret; @@ -263,18 +272,11 @@ jQuery.event = { }, fix: function(event) { - // Short-circuit if the event has already been fixed by jQuery.event.fix - if ( event[ expando ] ) - return event; - // store a copy of the original event object // and clone to set read-only properties var originalEvent = event; event = jQuery.extend({}, originalEvent); - // Mark the event as fixed by jQuery.event.fix - event[ expando ] = true; - // add preventDefault and stopPropagation since // they will not work on the clone event.preventDefault = function() { @@ -312,7 +314,7 @@ jQuery.event = { } // Add which for key events - if ( !event.which && (event.charCode || event.keyCode) ) + if ( !event.which && ((event.charCode || event.charCode === 0) ? event.charCode : event.keyCode) ) event.which = event.charCode || event.keyCode; // Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for Macs) @@ -561,7 +563,7 @@ var withinElement = function(event, elem) { // Check if mouse(over|out) are still within the same parent element var parent = event.relatedTarget; // Traverse up the tree - while ( parent && parent != elem ) try { parent = parent.parentNode } catch(error) { parent = elem; }; + while ( parent && parent != elem ) try { parent = parent.parentNode; } catch(error) { parent = elem; } // Return true if we actually just moused on to a sub-element return parent == elem; };