Re: Detecting and Creating Events

On 8/20/09 8:18 AM, Garrett Smith wrote:
> The inability to easily and accurately detect events is a problem.
> Programs want to know if an event is implemented at runtime. If it is,
> then the feature can be used. If not, it a fallback stratety is in
> order. Many new event types are being created and implemented. How can
> a program feature-test to see if they are implemented?
>
> Proposal: add a "hasEvent" method to EventTarget:
>
> EventTarget {
>    boolean hasEvent(in DOMString eventType)
> }
>
> This allows script to call the target's "hasEvent" method to see if
> the event is (claimed to be) supported.
>
> var hasFocusIn = false;
>
> if(typeof el.hasEvent != "undefined") {
>    hasFocusIn = el.hasEvent("domfocusin");
> }
>
This has the problem that browser may not know what additional events
extensions or plugins can fire.


> There should be a simple way to create and fire an event.
>
> interface DocumentEvent {
>    Event createInitedEvent(in domstring type, in Object options)
>    raises(dom::DOMException);
> }
>
> In createInitedEvent, the type of event created is determined by the
> string arg /type/, which is a prefixed with a DOM Interface (as a
> string) followed by ".", followed by the event type. The event is
> inited with the /options/. This is a "map" of options that the event
> has, such as - offsetX - , - pageY - , etc.
I agree a method like this would be very useful, but it could
be easily implemented in a script library.

It could be useful to have
dispatchInitedEvent(in domstring type, in Object options)
in EventTarget. (again something to implement easily in a script library)


-Olli

Received on Thursday, 20 August 2009 15:58:20 UTC