| ||||||||||||
| ||||||||||||
| Description | ||||||||||||
| Events Handling in DOM Level 2 | ||||||||||||
| Synopsis | ||||||||||||
| ||||||||||||
| Documentation | ||||||||||||
This module provides support for handling events that a program executed in a Web browser may receive. The Javascript backend uses mixed model of event handling. Although methods like addEventListener are available via automated W3C IDL conversion, it is known that not all browsers consistently support this model of event handling. On the other hand, older model of setting event handlers as on- attributes of DOM HTML element objects has been widely supported by many generations of Web browsers. In the same time, attributes of Event object (see DOM.Level2.Events, DOM.Level2.Event, DOM.Level2.KeyEvent, DOM.Level2.MouseEvent, etc.) are available even with this model of setting event handlers. So, this is possible to write: get'keyCode e $ \kci ->
if kci == cDOM_VK_ENTER
then
...
else
...
Other methods of Event objects family are also available, but their support may vary across different web browsers. There are two paradigms of handling DOM events. One, similar to the "traditional" method of setting a permanent event handler on a DOM object is represented by the setEventHandler function. Another, oriented to using pseudo-threads (see the Control.Concurrent.JSThreads module description), is represented by the waitFor function. | ||||||||||||
| setEventHandler | ||||||||||||
| ||||||||||||
The waitFor function sets the event handler on a given DOM object so that it invokes the current continuation. Right after the event fires, the same event handler on the DOM object is removed (set to null). So, between calls to waitFor the DOM object remains irresponsive to users actions. Threads using waitFor usually pass events received to other threads via message boxes. Below is an example of such thread used in an activator for a Button element. actb v mb par = (waitFor par "click" :: CPS Bool TMouseEvent) $ \e -> sendMsg_ mb v |>>| actb v mb par The thread contains an infinite loop which waits for an event, sends a message using sendMsg_, then repeats again. Return valus of waitFor depends on whether any other thread has already been waiting for the same event from this DOM element. If not analyzed, this may alter the handler's default action. Use waitForB to explicitly set the handler return value. | ||||||||||||
| waitFor | ||||||||||||
| ||||||||||||
| Produced by Haddock version 0.8 | ||||||||||||