On Mar 26, 4:56 am, Christophe Porteneuve <[EMAIL PROTECTED]> wrote:
> Hey,
>
> lsmith a écrit :
>
> > Yes, what I am asking for sounds pretty hacky, but I do not want to
> > rewrite tons of js I did not write myself to begin with, so I am
> > willing to cut a corner here.
>
> Simulating events is a very tricky thing.  There's no standard API for
> it yet.

There is, the W3C DOM 2 Events spec includes dispatchEvent for just
this purpose:

"dispatchEvent
"This method allows the dispatch of events into the implementations
event model. Events dispatched in this manner will have the same
capturing and bubbling behavior as events dispatched directly by the
implementation. The target of the event is the EventTarget on which
dispatchEvent is called."

<URL: 
http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-EventTarget-dispatchEvent
>

The spec is unchanged since 2000, it's a pity that the most common
browser hasn't implemented it.


> Thomas Fuchs simulates those for unit testing purposes, but
> that's still highly experimental, and FF only.  Look at his unittest.js
> file, the Event.simulateMouse stuff, and how he uses it in his
> unit/functional test pages.

There's an example of dispatchEvent on the Mozilla DOM pages:

<URL: http://developer.mozilla.org/en/docs/DOM:element.dispatchEvent >


>
> Still, probably not portable at all.  So YMMV, big time.

IE has fireEvent, the following link may help:

<URL:
http://groups.google.com.au/group/comp.lang.javascript/browse_frm/thread/27e7c70e51ff8a99/98cea9cdf065a524?lnk=gst&q=dispatchEvent&rnum=2#98cea9cdf065a524
>

The link to fireEvent at MSDN in that thread is broken, but you can
search for it.


--
Rob


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to