Caplin Trader 5.1.0

Class: module:ct-dom/event/Event

module:ct-dom/event/Event()

The Event class provides a uniform interface over the W3C event object, which is implemented differently in IE than it is in standards compliant browsers. Using this class for performing event access eliminates the need for much of the boiler plate code that would otherwise be required. Except where this was not possible, this interface has been modeled on the W3C event object specification.

The module:ct-dom/event/Event#getNormalizedEvent method is used to get a reference to a normalized event object. This requires the event object to be passed as a parameter since the global window.event object is not available in all browsers. If it is not possible to obtain the information that is necessary using the normalized event, the underlying event can be obtained via the module:ct-dom/event/Event#getRawEvent method.

Example usage:

window.onload = function() {
  document.body.onmousedown = function(rawEvent) {
    // rawEvent required in Firefox, in IE this will be undefined, and the
    // getNormalizedEvent() method will use the window.event global instead
    var normalisedEvent = Event.getNormalizedEvent(rawEvent);

    // check if the middle mouse button was pressed
    if (normalisedEvent.button == Event.MouseButtons.MIDDLE) {
      // handle the event
      console.log("Middle mouse button pressed on " + normalisedEvent.target.tagName);
    }
 };
};

Further reading:

Constructor

new module:ct-dom/event/Event()

This constructor is private and should not be used. To create a normalised event please use the module:ct-dom/event/Event#getNormalizedEvent method.

Members

(static) MouseButtons.LEFT :int

The event corresponds to the left mouse button (value 0).

Type:
  • int

(static) MouseButtons.MIDDLE :int

The event corresponds to the middle mouse button (value 1).

Type:
  • int

(static) MouseButtons.RIGHT :int

The event corresponds to the right mouse button (value 2).

Type:
  • int

altKey :boolean

Returns true if the "ALT" key was pressed when the event was triggered, otherwise false.

Type:
  • boolean

button :int

Returns which mouse button was clicked when the event was triggered. Please see module:ct-dom/event/Event/MouseButtons for the possible values.

WARNING - The normalisation of the button in Internet Explorer is not suitable if the user is expected to press more than one mouse button at any one time. If they do so, then the normalised value will only indicate that one of the buttons has been pressed. For example if the user presses the LEFT and RIGHT mouse buttons, this value will be Event.MouseButtons.LEFT.

Type:
  • int

charCode :int

Returns the ascii code of the character that will be inserted due to a keypress event.

Type:
  • int

clientX :int

Returns the horizontal coordinate of the mouse pointer when the event was triggered.

Type:
  • int

clientY :int

Returns the vertical coordinate of the mouse pointer when the event was triggered.

Type:
  • int

ctrlKey :boolean

Returns true if the "CTRL" key was pressed when the event was triggered, otherwise false.

Type:
  • boolean

keyCode :int

Returns the code of the key during a keyUp or keyDown event. You should use this on keyUp or keyDown events. It contains a code indicating the hardware key that was pressed. This is not necessarily the same as the ascii character that will be inserted.

Type:
  • int

relatedTarget :HtmlElement

Returns the element related to the actual target that triggered the event. For example when a mouseout event is fired, the module:ct-dom/event/Event#target will refer to element that the mouse pointer is moving out of, whilst the relatedTarget will refer to the element that is being moved into.

Type:
  • HtmlElement

screenX :int

Returns the horizontal coordinate of the mouse pointer when the event was triggered.

Type:
  • int

screenY :int

Returns the vertical coordinate of the mouse pointer when the event was triggered.

Type:
  • int

shiftKey :boolean

Returns true if the "SHIFT" key was pressed when the event was triggered, otherwise false.

Type:
  • boolean

target :HtmlElement

Returns the element that triggered the event. For example when a click event is fired, this is the element that was clicked.

Type:
  • HtmlElement

type :String

Returns the name of the event.

Type:
  • String

Methods

(static) cancelEventBubbling(eventObj)

Crossbrowser method for canceling event bubbling.

Parameters:
Name Type Description
eventObj Object

The event object.

(static) getEventSrc(eventObj:) → {Object}

Crossbrowser method for returning the DOM element that fired the event.

Parameters:
Name Type Description
eventObj: Object

The event object

Returns:

The DOM element where that fired the event

Type
Object

(static) getNormalizedEvent(rawEvent) → {module:ct-dom/event/Event}

Gets the normalised event that applies across all browsers representing the specified event.

Parameters:
Name Type Description
rawEvent HtmlEvent

The event to be normalised. If this value is undefined this method will use the window.event.

See:
Throws:

if the rawEvent is undefined and the window.event global does not exist.

Type
module:ct-core/Error
Returns:

A normalised event.

Type
module:ct-dom/event/Event

finalize()

Clean up any DOM references in the event.

getRawEvent() → {HtmlEvent}

Gets the underlying event that this normalised event was constructed from.

Returns:

The underlying event.

Type
HtmlEvent

preventDefault()

Cancels the event if it is cancelable, without stopping further propagation of the event. This means that any default action normally taken as a result of the event will not occur (e.g. the key that was pressed will be ignored). This method does not stop further propagation of the event through the DOM (please see module:ct-dom/event/Event#stopPropagation).

Invoking this method for a non-cancelable event has no effect.

stopPropagation()

Prevents further propagation of the current event.