BiEventTarget
This class provides the functionality to add and remove event listeners as well as dispatch events. When an event is dispatched the listeners are notified.
This class extends
BiObject
and therefore all methods and fields available for
BiObject
are also available for
BiEventTarget
.
Constructor
new
BiEventTarget
(
)
Parameters
No parameters.
Properties
None.
Methods
| Name | Description |
addEventListener |
This method adds a function object to call when the event with
the given name is dispatched. In case an object is passed as the
third argument then that will be used as this and
the function will be treated as a method of that object. |
dispatchEvent |
This method dispatches an event and all the listeners
will get notified in the same order that they were added.
This returns false if any of the listeners called
preventDefault()
on the event object. |
hasListeners |
Returns whether the event target has any listeners of the given type. The argument is optional and if left out returns whether the event target has any listeners of any type. |
removeEventListener |
This method removes a previously added event handler function. Note that the same function and object that was used when adding the listener must be passed as the second and third argument. |
setAttribute |
This overrides the method to map attributes that starts with 'on' to event
listeners. For example calling setAttribute("onclick", "alert(event)")
will add a click listener with function (event) { alert(event) }
as the handler function. |
Events
None.
Static Methods
None.
Static Fields
None.
Remarks
function eventHandler(oEvent) { ... }; eventTarget.addEventListener("eventtype", eventHandler); function SomeClass() { ... someObject.addEventListener("eventtype", this.handleEvent, this); } The argument oEvent to the event handler is the same event object that was created in the dispatchEvent above. Inside the event handler function this will point to the object that dispatched the event (unless a third argument was provided).
Method Details
addEventListener
This method adds a function object to call when the event with
the given name is dispatched. In case an object is passed as the
third argument then that will be used as this and
the function will be treated as a method of that object.
Syntax
object.addEventListener ( sType,fHandler [ ,oObject ] )
Parameters
| Name | Type | Optional | Default | Descripton |
sType |
String |
The event type (name) | ||
fHandler |
Function |
The function to call | ||
oObject |
Object |
![]() |
Optional object that the function is a method of.
This is used to map this in the
function handling the event |
Return Type
void
dispatchEvent
This method dispatches an event and all the listeners
will get notified in the same order that they were added.
This returns false if any of the listeners called
preventDefault()
on the event object.
Syntax
object.dispatchEvent
(
e
)
Parameters
| Name | Type | Optional | Default | Descripton |
e |
|
The event object to use in the event. If a string is
used then a new BiEvent is created using the string
as the type. |
Return Type
Boolean
hasListeners
Returns whether the event target has any listeners of the given type. The argument is optional and if left out returns whether the event target has any listeners of any type.
Syntax
object.hasListeners
(
[
sType
]
)
Parameters
| Name | Type | Optional | Default | Descripton |
sType |
String |
![]() |
The type of listeners to check for |
Return Type
Boolean
removeEventListener
This method removes a previously added event handler function. Note that the same function and object that was used when adding the listener must be passed as the second and third argument.
Syntax
object.removeEventListener ( sType,fHandler [ ,oObject ] )
Parameters
| Name | Type | Optional | Default | Descripton |
sType |
String |
The event type (name) | ||
fHandler |
Function |
The function/handler to remove | ||
oObject |
Object |
![]() |
Optional object that the function is a method of. |
Return Type
void
setAttribute
This overrides the method to map attributes that starts with 'on' to event
listeners. For example calling setAttribute("onclick", "alert(event)")
will add a click listener with function (event) { alert(event) }
as the handler function.
Syntax
object.setAttribute ( sName,sValue [ ,oParser ] )
Parameters
| Name | Type | Optional | Default | Descripton |
sName |
String |
The attribute name | ||
sValue |
String |
The attribute value | ||
oParser |
|
![]() |
Optional parser that was used to read an XML file |
Return Type
void
