Version 1.2 glow.events.Event
API Quick Reference
JavaScript is required to use the quick reference
Prototype for event objects passed to listeners.
When firing a custom event, create a glow.events.Event object and add properties and methods specific to your event. If you do not create an event, a standard glow.events.Event object will be created for you.
For built in events ('click', 'keypress', etc), a normalised event object based on glow.events.Event is passed to the event listener. To access the native event object, use the 'nativeEvent' property on the event object.
Some of the properties described below are only available for certain event types. These are listed in the property descriptions where applicable.
Notes for Opera
The information returned from Opera about key events does not allow certain keys to be differentiated. This mainly applies to special keys, such as the arrow keys, function keys, etc. which conflict with some printable characters.
For keypress events, the event object will always contain the printable where there is a conflict. For keyup and keydown events, the keyCode property will contain the keyCode and the key property will contain the key identifier for the special key.
Constructor
new glow.events.Event(properties)-
Parameters
- properties
-
- Type
- Optional
- Yes
Properties to add to the Event instance. Each key-value pair in the object will be added to the Event as properties
Properties
- altKey
-
Whether the alt key was pressed during the key event.
- Type
Description
Only available for keyboard events.
- attachedTo
-
The object/element that the listener is attached to.
- Type
- |
Description
See the description for 'source' for more details.
- button
-
A number representing which button was pressed.
- Type
Description
Only available for mouse events.
0 for the left button, 1 for the middle button or 2 for the right button.
- capsLock
-
Whether caps-lock was on during the key event
- Type
- | Undefined
Description
Only available for keyboard events.
If the key is not alphabetic, this property will be undefined as it is not possible to tell if caps-lock is on in this scenario.
- charCode
-
The unicode character code for a printable character.
- Type
- | Undefined
Description
Only available for keyboard events.
This will be undefined if the key was not a printable character.
- chr
-
A printable character string.
- Type
Description
Only available for keyboard events.
The string of the key that was pressed, for example 'j' or 's'.
This will be undefined if the key was not a printable character.
- ctrlKey
-
Whether the ctrl key was pressed during the key event.
- Type
Description
Only available for keyboard events.
- key
-
A short identifier for the key for special keys.
- Type
- | Undefined
Description
Only available for keyboard events.
If the key was not a special key this property will be undefined.
See the list of key identifiers in glow.events.addKeyListener
- keyCode
-
An integer number represention of the keyboard key that was pressed.
- Type
Description
Only available for keyboard events.
- pageX
-
The horizontal position of the mouse pointer in the page in pixels.
- Type
Description
Only available for mouse events.
- pageY
-
The vertical position of the mouse pointer in the page in pixels.
- Type
Description
Only available for mouse events.
-
The element that the mouse has come from or is going to.
- Type
Description
Only available for mouse over/out events.
- shiftKey
-
Whether the shift key was pressed during the key event.
- Type
Description
Only available for keyboard events.
- source
-
The actual object/element that the event originated from.
- Type
Description
For example, you could attach a listener to an 'ol' element to listen for clicks. If the user clicked on an 'li' the source property would be the 'li' element, and 'attachedTo' would be the 'ol'.
- wheelDelta
-
The number of clicks up (positive) or down (negative) that the user moved the wheel.
- Type
Description
Only available for mouse wheel events.
Methods
- defaultPrevented
-
Test if the default action has been prevented.
Synopsis
myEvent.defaultPrevented();Returns
True if the default action has been prevented.
- preventDefault
-
Prevent the default action for events.
Synopsis
myEvent.preventDefault();Description
This can also be achieved by returning false from an event callback
- propagationStopped
-
Tests if propagation has been stopped for this event.
Synopsis
myEvent.propagationStopped();Returns
True if event propagation has been prevented.
Example
// see if anything handles the event on this, and if not fire it on this.overlay var e = glow.events.fire(this, "open"); if (! e.propagationStopped()) { glow.events.fire(this.overlay, "open", e); } - stopPropagation
-
Stops the event propagating.
Synopsis
myEvent.stopPropagation();Description
For DOM events, this stops the event bubbling up through event listeners added to parent elements. The event object is marked as having had propagation stopped (see propagationStopped).
Example
// catch all click events that are not links glow.events.addListener( document, 'click', function () { alert('document clicked'); } ); glow.events.addListener( 'a', 'click', function (e) { e.stopPropagation(); } );