addEvent()/removeEvent() correctly passes these test.

Get the latest source

If you find bugs or have suggestions please write to my GMail address.

Use the addListener/removeListener functions or make aliases of them.

Do not use the _addEvent/_removeEvent functions (note the underscores).

You can obviously use _addEvent/_removeEvent if you like and if you know what you are doing. These two function needs function references to be able to correctly detach events, you can attach anonymous functions but you will not be able to detach them later on if you need to. The addListener/removeListener wrappers does not suffer from this specific problem use them instead.

The addListener/removeListener wrappers will fix the "this" keyword, the window context, the order of execution of events in the order they where set (you can change it run-time at will), the correct removal of listeners (including anonymous functions), and the pairing of some W3C standard properties. They will also provide a static list of events for testing/debugging purpose on all browsers.

There are two defined constants that will allow changing the behavior of this event manager, they are:

- EVENTS_W3C true/false

Allow to change the default event registration model (true) in favor of the old inline event model, which was the only model available in version 4 and older browsers.

- EVENTS_FIFO true/false

Allow to change the default order of execution (true) which is to fire in the order the events where added to the chain. (In Mozilla/Firefox/Opera it is by default, not on IE though).

There are debug lines that you can remove when you are finished testing (hey !!! when you are finished testing I said...). They will just spit an alert message (very bad right?) well I have done it on purpose, so I now if I am setting the same event on the same object twice or if I try to remove a non existent event. OK, if you insist just remove them if you whish :-)

IMPORTANT

Do not use the DOMLoaded "thing" found in the IFRAMES example, it will mostly break in your environment. It works here as expected ONLY because there are no images at all, neither in the document nor in the iframes. This demo is dedicated to the addEvent/removeEvent solution thread not to the DOMContentLoaded solution for IE.

NOTES:

- Some event manager will still fail this simple test case, (one window one document).
- This is not experimental any more, it is stable enough for production use.
- Please bear with me while I test it and try to make it still better.
- Your comments are strongly appreciated.