Tuesday, July 24th, 2007

Uniform Event Model: Making IE think W3C

Category: JavaScript, Library

Tavs Dokkedahl has written a small script that makes IE conform to the W3C DOM3 Event recommendation (at least the part that FF supports).

The Uniform Event Model adds support for the capture, atTarget and bubbling phases and provide most of the EventListener interface including among others the addEventListener, removeEventListener, createEvent, initEvent and dispactEvent methods. All handlers are passed an event object with almost complete information according to standards. See the list of features for detailed information on event flow, methods and properties.

Tavs has documentation that covers:

  1. An introduction to the framework
  2. The available W3C features
  3. The perfomance implications.

Posted by Dion Almaer at 5:43 am

3.7 rating from 33 votes


Comments feed TrackBack URI

Interesting. What happens if you alter the DOM using innerHTML? Will the resulting nodes by “UEMed”?

Comment by Steve Brewer — July 24, 2007

Sometimes it seems that the time is right for some ideas. We are currently working on moving qooxdoo’s DOM event handling code to it’s own layer, independent of the widget stuff. This event layer will have some of the same features, e.g. support for the capturing phase in IE and unified event objects modeled after the W3C DOM standard. Special mouse and key event handlers are responsible for normalizing event sequences and in the case of the key handler computing the key identifier. Another interesting feature, which we have brought from the IE to the other browsers is mouse event capturing.

Early documentation can ba found here: http://qooxdoo.org/documentation/general/dom_event_layer

Comment by Fabian Jakobs — July 24, 2007

Maybe I’m rusty on my algorithm time complexity theory, but on the perf page in the creator’s documentation he lists two algorithms that include nested loops as O(n). That sounds more like O(n^2) or at best maybe O(n log n) to me. Feel free to correct me if I’m wrong, computational theorists.

Comment by Jason — July 24, 2007

The outer loop runs a constant number (100) of times: 100*n = O(n) !

Comment by Stephan Baumeister — July 24, 2007

Yes 100 * n != O(n) but, 100 * O(n) :P.

Comment by ibolmo — July 24, 2007

I haven’t looked at the code, but I suspect it has the same problems with this mentioned in PPK’s addEvent() considered harmful.

Comment by Braden Anderson — July 24, 2007

Thanks for the comments.

@ Steve Brewer. I am working on replacing the existing innerHTML method. Note however that this method is not in the W3C recommendations. But since it is wildly supported and used (and misused) it would be a good idea to support it.

@ Jason. The perfomance tests are not scientifically correct. They are my best shoot at an upper bound on the worst case scenario. You’re right that 2 for loops would produce O(n^2) but the inner loop is executed only twise at a maximum. Therefore I feel it is closer to the real world to regard the inner loop as a constant – hence the O(n) result.

@ Braden Anderson. If you look at the code you will see that there is no resemblence with UEM and the original code of Scott Andrew. UEM does not use the native addEvent nor removeEvent() methods. It currently uses the fireEvent method to enulate dispatchEvent although it is not strictly nessesary. The addEvent() method you are refering to is a nice solution but falls short in many places.

Comment by Tavs Dokkedahl — July 24, 2007

Tavs, I don’t understand why you said the inner loop executes only twice at a maximum (in your response to Jason). But IF that’s the case, then since the outer loop is 100 times always, the growth rate would then be independent of the size of the inputs. The the big-oh should be O(1). (Constant factor is dropped in big-oh notation).

Comment by Kevin Hoang Le — July 24, 2007

“100 * O(n)” is not a correct statement, as you can’t multiply a number with a collection of functions (thats what the big O notation represents).
In computer sience “100*n = O(n)” is quite right. It has the same meaning as f(n)=100*n is element of O(n).
See: http://en.wikipedia.org/wiki/Big_O_notation

Comment by Stephan Baumeister — July 25, 2007

@ Steve Brewer. I found a way to support innerHTML – it might contain beta errors but the approach seems good. Try it out if you like.

@ Kevin Hoang Le. You can only have two event handlers of the same type with the same function registered for any one element – hence it can execute twice at maximum. The loopNum variable is only in the code for testing purposes. It tells how many times to test the loop. It is not an integral part of UEM and thus does not count in the result for the code perfomance.

Comment by Tavs Dokkedahl — July 26, 2007

Leave a comment

You must be logged in to post a comment.