addEvent() recoding contest entryThis was largely based on Angus Turnbull's Event Manager (http://www.twinhelix.com), but a little simpler and without the closure (and a few ideas from Jeffery To's entry). I've verified that it works in IE 5, 5.5 and 6 and Firefox on Windows and IE 5 and Safari on Mac OS. Using IE 5 on a Mac it appears that removeEvent doesn't work - the borders still appear - but showBorder() definitely isn't called onmouseover.
If supported, addEventListener() is used; if not, the functions are added to the 'eventCache' of the object and the raiseEvents() function assigned to the event DOM1 (?) style. The object is also stored in an array so we know which objects contain events that need to be removed onunload.
I purposely avoided using attachEvent() to ensure handlers would be called in the order they were added.
Also, this will add a cleanup function (it's actually a function to add the event to make sure it is the last unload event) to the unload event the first time an event is added (if addEventListener() is not supported.)
If supported, removeEventListener() is used; if not, the function is simply removed from the 'eventCache' for that object.
Calls each of the cached functions for the event for the object against the object to make sure this works properly. This will only ever be called if addEventListener() is not supported.
This is the cleanup function for IE. This will be called as the last onunload method if any events have been added using addEvent() and addEventListener() is not supported.
I added these in because they're in my common .js file for backwards compatibility. Using them makes the other methods a bit tider.