Cross-Platform API for DOM Events manipulation.
Index
Methods
Methods
-
<static> UWA.Event.onDomReady(callback, context, window)
-
Cross-Platform method to run a callback when DOM is ready.
Example
UWA.Event.onDomReady(function () { // Called when DOM is ready });
Parameters
Name Type Argument Description callback
Function Callback triggered when DOM is ready
context
Object <optional>
Callback context
window
Window <optional>
window object
-
<static> UWA.Event.dispatchEvent(element, eventType, options) → {Event}
-
Dispatch Event on an element.
Available options:
Mouse and touch events (e.g mouseup, mousedown, click, ...):
Options Description detail
The Event's mouse click count. screenX
The Event's screen x coordinate. screenY
The Event's screen y coordinate. clientX
The Event's client x coordinate. clientY
The Event's client y coordinate. relatedTarget
The Event's related EventTarget. Touch events (e.g touchstart, touchmove, touchend, touchcancel):
Options Description touches
A collection of Touch objects representing all touches associated with this event. targetTouches
A collection of Touch objects representing all touches associated with this target. changedTouches
A collection of Touch objects representing all touches that changed in this event. scale
See below rotation
The delta rotation since the start of an event, in degrees, here clockwise is positive and counter-clockwise is negative. The initial value is 0.0. Scale option:
The distance between two fingers since the start of an event as a multiplier of the initial distance. The initial value is 1.0. If less than 1.0, the gesture is pinch close (to zoom out). If greater than 1.0, the gesture is pinch open (to zoom in).
Keyboard events (e.g keydown, keyup, ...):
Options Description keyCode
unsigned long keyCode charCode
unsigned long charCode All events (e.g load, unload, ...):
Options Description ctrlKey
Whether or not control key was depressed during the Event. altKey
Whether or not alt key was depressed during the Event. shiftKey
Whether or not shift key was depressed during the Event. metaKey
Whether or not meta key was depressed during the Event. button
The Event's mouse event.button. Example
var element = new UWA.Element('div'); element.addEvent('click', function (event) { // Process your event behavior here }); // Trigger click event on element UWA.Event.dispatchEvent(element, 'click');
Parameters
Name Type Description element
Element A standart DOM node
eventType
String An event name (e.g mouseup)
options
Object Options hash or a option/value pair.
Returns
A standard DOM event.
- Type
- Event
- See:
-
- http://www.w3.org/TR/2007/WD-DOM-Level-3-Events-20071221/events.html#Events-MouseEvent
- http://www.w3.org/TR/2007/WD-DOM-Level-3-Events-20071221/events.html#Events-KeyboardEvent
- http://www.w3.org/TR/2007/WD-DOM-Level-3-Events-20071221/events.html#Events-eventgroupings-basicevents
- https://dvcs.w3.org/hg/webevents/raw-file/tip/touchevents.html
-
<static> UWA.Event.getElement(event)
-
Get element target to event parameter.
Parameters
Name Type Description event
Event A standard DOM event
Returns
Element attached to the event extended with <UWA.Element> methods.
-
<static> UWA.Event.findElement(event, tagName)
-
Find an parent element of event target using tagName.
Parameters
Name Type Description event
Event A standard DOM event
tagName
String Parent element target tagname
Returns
Element matched extended with <UWA.Element> methods.
-
<static> UWA.Event.stopPropagation(event)
-
Cross-Platform method to stop the propagation of an event.
This stops the event from bubbling up through the DOM. This method does not prevent the default action from being invoked, use UWA.Event.preventDefault for that effect.
Example
var element = new UWA.Element('span'); element.addEvent('click', function (event) { // Prevent default action UWA.Event.stopPropagation(event); // Process your event behavior here });
Parameters
Name Type Description event
Event A standard DOM event
-
<static> UWA.Event.preventDefault(event)
-
Cross-Platform method to prevent the default action of the event.
Example
var element = new UWA.Element('a', { href: "http://example.com" }); element.addEvent('click', function (event) { // Prevent propagation of the event UWA.Event.preventDefault(event); // Process your event behavior here });
Parameters
Name Type Description event
Event A standard DOM event
-
<static> UWA.Event.stop(event)
-
Stop an Event from propagating and also executes preventDefault.
Example
var element = new UWA.Element('div'); element.addEvent('click', function (event) { // Prevent default action and propagation of the event UWA.Event.stop(event); // Process your event behavior here });
Parameters
Name Type Description event
Event A standard DOM event
-
<static> UWA.Event.isDefaultPrevented(event) → {Boolean}
-
Return
true
if Event.preventDefault() has been called for this event.Parameters
Name Type Description event
Event A standard DOM event
Returns
true
if if Event.preventDefault() has been called for this event.- Type
- Boolean
-
<static> UWA.Event.whichButton(event) → {Integer}
-
Cross-Platform method to get the mouse event used button.
During mouse events caused by the depression or release of a mouse button, button is used to indicate which mouse button changed state.
-1 indicates no button is pressed.
0 indicates the normal button of the mouse (in general on the left or the one button on Macintosh mice, used to activate a button or select text).
2 indicates the contextual property (in general on the right, used to display a context menu) button of the mouse if present.
1 indicates the extra (in general in the middle and often combined with the mouse wheel) button. Some mice may provide or simulate more buttons, and values higher than 2 can be used to represent such buttons.
Example
var element = new UWA.Element('div'); element.addEvent('click', function (event) { var button = UWA.Event.whichButton(event); if (button === 0) { // Process normal button } else if (button === 2) { // Process contextual button } else if (button === 1) { // Process middle button } });
Parameters
Name Type Description event
Event A standard DOM event
Returns
The used mouse button event, or -1 if no button is pressed.
- Type
- Integer
-
<static> UWA.Event.whichKey(event) → {String}
-
Cross-Platform method to get the keyboard event pressed keys.
Notice:
Using other event type based on key (keydown, keypress, keyup) only meta keys (ctrl, alt, shift) can be expected.
Example
UWA.Element.addEvent.call(document, 'keydown', function (event) { var key = UWA.Event.whichKey(event); if (key === 'up') { // Process up action here } else if (key === 'down') { // Process down action here } else if (key === 'ctrl+down') { // Process ctrl+down action here } });
Parameters
Name Type Description event
Event a standart DOM event
Returns
An string pressed key value (e.g "ctrl+f", "f").
- Type
- String
-
<static> UWA.Event.wheelDelta(event) → {Integer}
-
Cross-Platform method to get how many pixels the mouse wheel scrolls the page.
Parameters
Name Type Description event
Event A standard DOM event
Returns
Number of pixels the mouse wheel scrolls the page.
- Type
- Integer