Hemi JavaScript Framework

Hemi.event

Description

The Event class provides utilities for working with the browser event object, listening to and capturing events, and decorating Framework Objects with an API for scoping handlers back to the object.

static Hemi.event

version 3.1.0

Utilities for DOM Events.

See Using event utilities for an example of implementating the script on a page.

Index

Example Index

Method Index

Examples

Using event utilities

This example shows how to use the event buffer and scopeHandler mechanisms to preserve the event handler context to a specific object instance.

Example Code

<p id = "oPara">Test paragraph</p>
<script type = "text/javascript">
var oObject = Hemi.newObject("DemoType","1.0",true);
// Add the scopeHandler method for this object with addScopeBuffer
Hemi.event.addScopeBuffer(oObject);
// Create an event handler wrapper with scopeHandler for an onclick event.
// Specify the event name and the bit to use the ObjectRegistry.
// This creates oObject._prehandle_click which will invoke oObject._handle_click.
oObject.scopeHandler("click",0,0,1);
oObject._handle_click = function(e){
   var oEvent = Hemi.event.getEvent(e);
   var oSource = Hemi.event.getEventSource(e);
   // The 'this' object refers to the instance of oObject
};
 // Add the onclick event to the paragraph element, oPara
var oPara = document.getElementById("oPara");
// Use the _prehandle_click created by the scopeHandler method.
Hemi.event.addEventListener(oPara, "click", oObject._prehandle_click);
</script>

Methods

_handle_event

A developer specified event handler that is invoked after binding an event to the _prehandle_event handler, and which has the context specified by the scopeHandler method. Method is virtual and can be overridden.

Syntax

v = _handle_event( )

Returns

v as variant: Returns developer specified value.

_prehandle_event

Internal event handler used to establish context and to invoke the custom handler.

Syntax

v = _prehandle_event( )

Returns

v as variant: Returns value from

addScopeBuffer

Creates the scopeHandler method on the specified object.

Syntax

void addScopeBuffer( e )

Parameters

cancelEvent

Cancels the event.

Syntax

void cancelEvent( o )

Parameters

getEvent

Returns the event object, where the specified parameter may or may not be the event object depending on the browser.

Syntax

e = getEvent( o )

Parameters

Returns

e as object: The event object.

getEventDestination

Returns the event destination or target object.

Syntax

e = getEventDestination( o )

Parameters

Returns

e as object: The event destination object.

getEventOrigination

Returns the event origination object.

Syntax

e = getEventOrigination( o )

Parameters

Returns

e as object: The event origination or source object.

getEventSource

Returns the event source object.

Syntax

e = getEventSource( o )

Parameters

Returns

e as object: The event source object.

scopeHandler

Creates a custom event handler, _prehandle_event, which invokes _handle_event for the specified object, using the specified context. This method is created by addScopeBuffer. Method is virtual and can be overridden.

Syntax

f = scopeHandler( s, r, x, l )

Parameters

Returns

f as function: Custom event handler function.