Diviner

Class JX.Event

Definedsrc/core/Event.js:26
GroupEvent Model
ExtendsJX.Base

A generic event, routed by JX.Stratcom. All events within Javelin are represented by a {@class:JX.Event}, regardless of whether they originate from a native DOM event (like a mouse click) or are custom application events.

See Concepts: Event Delegation for an introduction to Javelin's event delegation model.

Events have a propagation model similar to native Javascript events, in that they can be stopped with stop() (which stops them from continuing to propagate to other handlers) or prevented with prevent() (which prevents them from taking their default action, like following a link). You can do both at once with kill().

Tasks

Stopping Event Behaviors

Getting Event Information

Unspecified

Methods

node|null getNode(key)

parametersstringkeysigil or stratcom node key
returnnode|nullNode mapped to the specified key, or null if it the key does not exist. The available keys include: - 'tag:'+tag - first node of each type - 'id:'+id - all nodes with an id - sigil - first node of each sigil

Get the node corresponding to the specified key in this event's node map. This is a simple helper method that makes the API for accessing nodes less ugly.

JX.Stratcom.listen('click', 'tag:a', function(e) { var a = e.getNode('tag:a'); // do something with the link that was clicked });

dict getNodeData(key)

parametersstringkeysigil or stratcom node key
returndictdictionary of the node's metadata

Get the metadata associated with the node that corresponds to the key in this event's node map. This is a simple helper method that makes the API for accessing metadata associated with specific nodes less ugly.

JX.Stratcom.listen('click', 'tag:a', function(event) { var anchorData = event.getNodeData('tag:a'); // do something with the metadata of the link that was clicked });

string|null getSpecialKey()

returnstring|nullnull if there is no associated special key, or one of the strings 'delete', 'tab', 'return', 'esc', 'left', 'up', 'right', or 'down'.

Get the special key (like tab or return), if any, associated with this event. Browsers report special keys differently; this method allows you to identify a keypress in a browser-agnostic way. Note that this detects only some special keys: delete, tab, return escape, left, up, right, down.

For example, if you want to react to the escape key being pressed, you could install a listener like this:

JX.Stratcom.listen('keydown', 'example', function(e) { if (e.getSpecialKey() == 'esc') { JX.log("You pressed 'Escape'! Well done! Bravo!"); } });

static initialize()

returnwild

JX.Event installs a toString() method in __DEV__ which allows you to log or print events and get a reasonable representation of them:

Event<'click', ['path', 'stuff'], [object HTMLDivElement]>

bool isNormalClick()

returnbool

Determine if a click event is a normal click (left mouse button, no modifier keys).

bool isRightButton()

returnbool

Get whether the mouse button associated with the mouse event is the right-side button in a browser-agnostic way.

this kill()

returnthis

Stop and prevent an event, which stops it from propagating and prevents its defualt behavior. This is a convenience function, see stop() and prevent() for information on what it means to stop or prevent an event.

this prevent()

returnthis

Prevent an event's default action. This depends on the event type, but the common default actions are following links, submitting forms, and typing text. Event prevention is generally used when you have a link or form which work properly without Javascript but have a specialized Javascript behavior. When you intercept the event and make the behavior occur, you prevent it to keep the browser from following the link.

Preventing an event does not stop it from propagating, so other handlers will still receive it. See ""Using Events"" for more information on the distinction between 'stopping' and 'preventing' an event. See also stop() (which stops an event but does not prevent it) and kill() (which stops and prevents an event).

this stop()

returnthis

Stop an event from continuing to propagate. No other handler will receive this event, but its default behavior will still occur. See ""Using Events"" for more information on the distinction between 'stopping' and 'preventing' an event. See also prevent() (which prevents an event but does not stop it) and kill() (which stops and prevents an event).