Part 1:
In some instances where you have a lot of observers attached to the "contentloaded" event, the window.onload event will fire before all of the "contentloaded" observers are executed.
Part 2:
All browsers, except IE, follow the "first in, first out" rule.
This means that:
$('foo').observe('click', function(){ alert('one');});
$('foo').observe('click', function(){ alert('two');});
$('foo').observe('click', function(){ alert('thee');});
//EOMB - when foo is clicked alerts: 'one', 'two', and 'three'
//IE - when foo is clicked alerts: 'three', 'two', and 'one'
My proposed fix will address both issues (I will create a patch when I have some time).
Basically you mod the Event class to manage the observer list (instead of letting the browser).
Back to the previous example:
$('foo').observe('click', function(){ alert('one');});
/*
1) Event.observe checks the element for an “__eventInterceptHandle”
2) If no handle exists it creates the handle and all the peaces necessary
to track the observers of that Element+EventName.
3) When foo is clicked it triggers the one “real” handler to call the
subsequent observers (first in first out).
When the window onload event fires it checks the status of the
“contentloaded” observers. If they are not done executing it loops
checking its status every 10 ms or so.
*/
Loose Examples
Here is an example of similar functionality I used in Prototype 1.5.1.
The method names are not important, the key is in the functionality.
Event Intercept code:
http://pastie.caboo.se/private/rzzrkiaa3zvhclj1uh
Cross-browser onDOMContentLoaded using Event.intercept():
http://pastie.caboo.se/private/euowdrekwczeednbzr
IE window.onResize() fix
(problem discussed here http://www.snook.ca/archives/javascript/ie6_fires_onresize/ )
, this code requires a class called "Window" but you get the point:
http://pastie.caboo.se/private/scxhidmjmwstj35slg