Re: Fwd: DOM event detection

On 12/28/10, Garrett Smith <> wrote:
> On 12/28/10, Jacob Rossi <> wrote:
>>> How does that work? Post up some examples. Thanks.
>> //Test for textinput
>> var evt = document.createEvent("TextEvent");
> That can throw. Needs to be in a try/catch.
>> evt.initTextEvent("textinput",true,true,window,"x",1,"en-US");
>> document.addEventListener("textinput",function(e){if(e.inputMode){SUPPORTS_TEXTEVENT
>> = true;}},false);
>> document.dispatchEvent(evt);
>> alert(SUPPORTS_TEXTEVENT?'pass':'fail');
> Use `typeof`. What happens when inputMode is 0? Well, that's converted
> to `false`..
If `inputMode == 0` there that would be a bug because you passed `1`.
Though now I am thinking that an explicit test for `e.inputMode === 1`
would be clearer, and better yet, use a variable for that, to make an
explicit GIGO check.

var inputMode = 1;
evt.initTextEvent("textinput",true,true,window,"x", inputMode,"en-US");


if(e.inputMode === inputMode) {


D3E draft defines hasFeature method and also specifies new events that
will be detected with that same functionality. Those events are
evolving. And a good example of that evolution is the different
numbers of parameters with the initTextEvent method.

Event synthesis is one way to make inferences about feature detection.
The DOM Events APIs for event synthesis are a bunch of one-off
methods. They're brittle and they're cumbersome to use.

Feature detection mechanism and event synthesis mechanisms are
applicable to all EventTargets; they could be called "core"

Core EventTarget functionality and specific event types should be
specified separately. Doing this ensures that the core design is
extensible and that it is not tied to specific events.

The existing event synthesis API is not extensible. The proposed
extensible solution to core EventTarget event synthesis was to define
a way to create any event using a "properties" object, such as:

  var ev = document.createEvent(iface);
  ev.initEventProperties( properties );

Thanks for the example, BTW.

Received on Wednesday, 29 December 2010 03:20:40 UTC