Proposition for live with mouseenter and mouseleave
Hello everybody,
I hope you all had a safe trip home, mine was even longer than I
thought: 36 hours!
Anyway, back to work. I'm busy with a patch to add built-in support of
mouseenter and mouseleave to the live function, I hope somebody else
is not already doing the same thing.
First I wondered what part of I had to modify to add this feature. It
appears that this could be either done in "withinElement" (the special
handler of the mouseenter and mouseleave properties) or in
liveHandler.
So far, withinElement filters mouseover and mouseout elements using
the event.relatedTarget to emulate mouseenter and mouseleave. It would
be possible to make this function aware of the selector used by live
(), then to do something like:
var target = $(event.target).closest(event.data.selector)[0],
related;
if(target) {
related = $(event.relatedTarget).closest(event.data.selector)[0];
if(!related || target != related) jQuery.event.handle.apply( this,
arguments );
}
This would be a clean solution as it only requires to modify
withinElement.
However we end up using closest() three times: twice in this function,
and once again in liveHandler.
To avoid that, my choice is to bypass withinElement and to modify
liveHandler: if the event is mouseenter or mouseleave, the
event.relatedTaget is also tested.
The proposed patch is here: http://dev.jquery.com/attachment/ticket/5259/patchEvent.txt
Please let me know if there is a better way of doing it that I have
missed.
Regards,
lrbabe