W3C home > Mailing lists > Public > www-dom@w3.org > October to December 2010

Re: Fwd: DOM event detection

From: Garrett Smith <dhtmlkitchen@gmail.com>
Date: Tue, 28 Dec 2010 19:20:07 -0800
Message-ID: <AANLkTimdaXpDop+LTz=X-RhUmP6hgv8Q1SzsG1_sX=5d@mail.gmail.com>
To: Jacob Rossi <jrossi@microsoft.com>
Cc: "www-dom@w3.org" <www-dom@w3.org>, "schepers@w3.org" <schepers@w3.org>
On 12/28/10, Garrett Smith <dhtmlkitchen@gmail.com> wrote:
> On 12/28/10, Jacob Rossi <jrossi@microsoft.com> 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");
>> var SUPPORTS_TEXTEVENT = false
>> 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"
functionality

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.
-- 
Garrett
Received on Wednesday, 29 December 2010 03:20:40 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:14:07 GMT