From: jeresig Date: Mon, 21 Dec 2009 23:06:23 +0000 (-0500) Subject: Tweaked the syntax of withinElement a bit. X-Git-Tag: 1.4rc1~52 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=36c99dc0c7a745a88488f519b38de811d6d4c8d9;p=jquery.git Tweaked the syntax of withinElement a bit. --- diff --git a/src/event.js b/src/event.js index 72ebcf7e6..892525aea 100644 --- a/src/event.js +++ b/src/event.js @@ -532,23 +532,30 @@ jQuery.Event.prototype = { isPropagationStopped: returnFalse, isImmediatePropagationStopped: returnFalse }; + // Checks if an event happened on an element within another element // Used in jQuery.event.special.mouseenter and mouseleave handlers var withinElement = function( event ) { // Check if mouse(over|out) are still within the same parent element var parent = event.relatedTarget; + // Traverse up the tree - while ( parent && parent != this ) { + while ( parent && parent !== this ) { // Firefox sometimes assigns relatedTarget a XUL element // which we cannot access the parentNode property of - try { parent = parent.parentNode; } + try { + parent = parent.parentNode; + // assuming we've left the element since we most likely mousedover a xul element - catch(e) { break; } + } catch(e) { + break; + } } - if ( parent != this ) { + if ( parent !== this ) { // set the correct event type event.type = event.data; + // handle event if we actually just moused on to a non sub-element jQuery.event.handle.apply( this, arguments ); }