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

NameTypegetsetDescripton
eventsObjectcheckedObject holding all the available event types for this instance by name. Register event types by calling addEvent.

Methods

NameDescription
addEventListenerThis method adds a EventListener to the instance.
dispatchEventThis 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.
hasEventTypeCheck if event type exists on instance.
hasListenersReturns 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.
removeEventListenerThis 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.
setAttributeThis 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 EventListener to the instance.

Syntax

object.addEventListener ( oListener )

Parameters

NameTypeOptionalDefaultDescripton
oListenerBiEventListenerThe event listener to add

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

NameTypeOptionalDefaultDescripton
eBiEvent/StringThe 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

hasEventType

Check if event type exists on instance.

Syntax

object.hasEventType ( sType )

Parameters

NameTypeOptionalDefaultDescripton
sTypeStringthe event 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

NameTypeOptionalDefaultDescripton
sTypeStringcheckedThe 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

NameTypeOptionalDefaultDescripton
sTypeStringThe event type (name)
fHandlerFunctionThe function/handler to remove
oObjectObjectOptional 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

NameTypeOptionalDefaultDescripton
sNameStringThe attribute name
sValueStringThe attribute value
oParserBiXmlResourceParserOptional parser that was used to read an XML file

Return Type

void