Monday, 24. September 2007, 10:14:21
event capture, compatibility, addEventListener, addEvent
Google Indic Transliteration does quite precisely nothing in Opera. The reason is that they try adding a capturing key event listener to a TEXTAREA:
a.addEventListener(b,c,true)
from function _TR_addHandler in
labs001.js.
If you've followed the past twists of the event capture drama, you might recall that since Mozilla decided to
play chicken and re-write the spec according to their buggy implementation, we decided to
be bug compatible. So why is the transliteration still broken? Seems like we aren't quite compatible after all?
Yup. Test case here.Capturing
key event listeners still don't fire on target. That's a bug in our bug compatibility, leaving us
more standards compliant than intended.
So our bugs are buggy

. How do you spell "irony" in Hindi again?
Wednesday, 28. March 2007, 18:23:46
decompile, coding, addEvent, standards
...
A while ago, Peter-Paul Koch and some other JavaScript-interested bloggers held a competition for improving the "addEvent" function. The
winner was John Resig's
flexible JavaScript events function.
It creates a new property of the object you add an event listener to as follows:
obj['e'+type+fn] = fn;
The main purpose of that is to make the "this" keyword work inside event listeners. It is a clever hack, though looks a bit ugly - to ensure that the object property has a unique name, it concatenates "type" and "fn", meaning the browser
has to decompile the function and use its entire source as part of the property name. Decompiling a function object is slow, the property name becomes nothing short of ugly. Perhaps a few lines of code to make a prettier unique property name would be worth it?
Besides the ugliness, here comes the real problem:
the code assumes that all implementations can decompile functions. Opera can on desktop, but to save footprint this feature is disabled on mobile phones. Function.prototype.toString simply returns "[ECMAScript code]". Hence, each call to Resig's addEvent will overwrite the previous function object for that type, and the last function added will be called as many times as addEvent itself has been called. I'm afraid the clever hack has turned rather destructive - bad enough to break cross-platform compatibility for any app.
As written, the function makes the assumption that all browsers which have attachEvent support has IE's bugs. The simple fix would be to follow this rule: use object detection and
try the standards-compliant path first. First looking for the standards-compliant (thus probably the best defined) function might be a good general rule of thumb for compatibility. Cross-browser support for a method that is implemented by trying to figure out what another browser is doing is likely worse than support for a method specified in detail by the W3C, so by choosing the W3C stuff if it exists should get you better compatibility.