Thanks Mislav,

In prep for my reply I was looking through the 1.6_rc0 release and I
have to give you guys a HUGE hand on the event firing using a real
event object.
Very very cool stuff...

I am trying to think of the easiest way to explain the problem and the
Take for example my old implementation of a cross browser
DOMContentLoaded event.

Snippet: (I use the word "notify" instead of "fire")

Before the window onload event is fired I check to see if the
DOMContentLoaded has been notified or if they equal each other (if the
browser dosent support any form of  DOMContentLoaded emulation I have
it fallback on the window onload event)

If the DOMContentLoaded event has been notified then I allow the
trigger to fire,
else I have it repeat in 10 milliseconds and check again.

I am able to so this because I, not the browser, control the execution
of the event observers. I accomplish this by only having the browser
handle one main observer that in turn calls all of its subsequent

For example:
Event.intercept(window, 'load', options);

Event.intercept() creates the "main observer", basically passing the
event name prefixed with an  undercore, '_load', to Event.observe()
which then allows it to pass to the normal  Event._observeAndCache();

Event.observe(window, 'load', function(){ alert('one');});
Event.observe(window, 'load', function(){ alert('two');});
Event.observe(window, 'load', function(){ alert('three');});

Event.observe() checks to see if I have set up a "main observer" for
this element+eventName. It does have a "main observer" so it passes it
interceptor.observe(), instead of Event._observeAndCache();

Event.observe() Snippet:

Now the window load event fires, which calls the main observer's
"notify" method.
The notify method checks the status (either pass, fail, or repeat) set
my an optional onPreNotify() callback.

If the status is "pass" then it iterates over its own observers and
sets the "notified" flag to true.

Notify Snippet:

I am able to fail, repeat, or pass a notification attempt and
accurately track the completed execution of observers. Using an array
to iterate observers also allows for proper "first-in first-out"
observer execution that IE lacks...

$('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'

Does this make since???

You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at

Reply via email to