addEvent() recoding contest entry

Remove border effect.

[EDIT]
In my quest to get the currentTarget I overlooked the fact that the keyword this should be the same as the currentTarget. So this script doesn't count.
[/EDIT]

I have used #3 from John Resig as a base for this script (is that allowed??). At the moment it's the script that appeals to me the most. What I've done to it is add a currentTarget property to the event object for mouse events. That means you can get the currentTarget property in Internet Explorer. I've also changed the order of the object event add tests to match the original Scott Andrew script (it now works in Opera 8 on Mac).

To demonstrate the currentTarget property I've modified the <li> tags to have an id matching the text in the a tag. The id of the <li> is alerted on click.

The script gets the currentTarget property by making use of the Microsoft mouseenter and mouseleave events. The targets from those will always (I think) give the currentTarget of the following mouse events. This script, being a cross platform script, assumes you wouldn't use this script to add Microsoft's mouseenter and mouseleave events.

Here's the script:

function addEvent( obj, type, fn ) {
	if ( obj.addEventListener ) {
		obj.addEventListener( type, fn, false );
	} else {
		//
		if ( "clickmouseovermousedownmouseupmouseout".indexOf(type.toLowerCase()) > -1 ) {
			// add a mouseenter and mouseleave to record the currenttarget
			addEvent(obj,'mouseenter',function (e) {
				this.currTarg = e.srcElement;
			});
			addEvent(obj,'mouseleave',function (e) {
				this.currTarg = e.toElement;
			});
		}
		//
		obj['e'+type+fn] = fn;
		obj[type+fn] = function(){
			var e = window.event;
			if ( "clickmouseovermousedownmouseupmouseout".indexOf(e.type) > -1 ) {
				e.currentTarget =  (e.currentTarget) ? e.currentTarget : obj.currTarg;
			}
			obj['e'+type+fn](e);
		}
		obj.attachEvent( 'on'+type, obj[type+fn] );
	}
}
function removeEvent( obj, type, fn ) {
	if ( obj.removeEventListener ) {
		obj.removeEventListener( type, fn, false );
	} else {
		obj.detachEvent( 'on'+type, obj[type+fn] );
	}
}