Class o2.Event
static
class
o2.Event
Adds a new event listener to the DOM Node.
Usage example:
o2.Event.addEventListener('container', 'click', function(evt) { doClickHandling(); });
Adds a set of event handlers the the eventName of the given collection.
Usage example:
o2.Event.addEventListeners(['elm1', 'elm2'], 'click', function(evt) { handleClickEvent(); });
Gets the actual event object.
Usage example:
o2.Event.addEventListener('container', 'click', function(evt) { var e = o2.Event.getEventObject(evt); });
Gets the key code of the key-related event (keydown, keyup, keypress etc.).
Usage example:
o2.Event.addEventListener('container', 'keydown', function(evt) { var code = o2.Event.getKeyCode(evt); });
Gets the current mouse coordinates.
Usage example:
o2.Event.addEventListener('container', 'mousemove', function(evt) { var dimensions = o2.Event.getMouseCoordinates(evt); });
Gets the originating source of the event.
Usage example:
o2.Event.addEventListener('container', 'click', function(evt) { var src = o2.Event.getTarget(evt); });
Checks whether the pressed key is an arrow key.
Usage example:
o2.Event.addEventListener('container', 'keydown', function(evt) { var isArrowKey = o2.Event.isArrowKey(evt); });
Checks whether the pressed key is the backspace (DEL) key.
Usage example:
o2.Event.addEventListener('container', 'keydown', function(evt) { var isBackspaceKey = o2.Event.isBackspaceKey(evt); });
Checks whether the character in a onkeypress
event
actually produces a printable char.
The thing you have to remember is that you can't reliably tell
anything at all about any character that may be
typed in a onkeydown
or onkeyup
event:
The printable key is determined only in the onkeypress
handler.
Usage example:
o2.Event.addEventListener('container', 'keypress', function(evt) { var isCharKeypress = o2.Event.isCharacterKeypressEvent(evt); });
Checks whether the pressed key is the enter (return) key.
Usage example:
o2.Event.addEventListener('container', 'keypress', function(evt) { var isEnterKey = o2.Event.isEnterKey(evt); });
Checks whether the pressed key is the escape (ESC) key.
Usage example:
o2.Event.addEventListener('container', 'keypress', function(evt) { var isEscapeKey = o2.Event.isEscapeKey(evt); });
Checks whether or not the curent action is a right click action.
Usage example:
o2.Event.addEventListener('container', 'click', function(evt) { var isRightClick = o2.Event.isRightClick(evt); });
Checks whether the pressed key is the tab key.
Usage example:
o2.Event.addEventListener('container', 'keypress', function(evt) { var isTabKey = o2.Event.isTabKey(evt); });
Prevents the default action. When this method is called inside an
even handling callback, the default action associated with that
event is not triggered. Like, if it is an onclick
event on a link, then the browser does not go to the
href
of that link.
Usage example:
o2.Event.addEventListener('container', 'click', function(evt) { o2.Event.preventDefault(evt); });
Removes an already-added new event listener from the DOM Node.
Usage example:
o2.Event.removeEventListener('container', 'click', container_click);
Stops the propagation of the event upwards in the DOM hierarchy.
Note that "change" event does not bubble.
Also, events: change, submit, reset, focus, blur do not bubble in Internet Explorer.
According to specification, "focus" and "blur" should not bubble, while "change", "submit", "reset" should.
This behavior implemented properly in all web browsers but IE.
See http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-flow for details.
Usage example:
o2.Event.addEventListener('container', 'click', function(evt) { o2.Event.stopPropagation(evt); });
Function Details
function addEventListener
static
addEventListener(DomNode
node, String
evt, Function
fn)
Adds a new event listener to the DOM Node.
Usage example:
o2.Event.addEventListener('container', 'click', function(evt) { doClickHandling(); });
node
- the DOM object (or its
String
id) the evet shall be attached.
evt
- the name of the event (like "click",
"mousemove"...)
fn
- a reference to the on[event] callback action. function addEventListeners
Adds a set of event handlers the the eventName of the given collection.
Usage example:
o2.Event.addEventListeners(['elm1', 'elm2'], 'click', function(evt) { handleClickEvent(); });
collection
- an Object
or an
Array
of DOM nodes, or their
ids.
eventName
- the name of the event to
attach to.
handler
- the common event handling
callback. function getEventObject
static
getEventObject(Event
evt)
Gets the actual event object.
Usage example:
o2.Event.addEventListener('container', 'click', function(evt) { var e = o2.Event.getEventObject(evt); });
evt
- the actual DOM Event
object used
internally in Event.addEventListener DOM Event
object.
function getKeyCode
static
getKeyCode(Event
evt)
Gets the key code of the key-related event (keydown, keyup, keypress etc.).
Usage example:
o2.Event.addEventListener('container', 'keydown', function(evt) { var code = o2.Event.getKeyCode(evt); });
Integer
, if found; 0
otherwise.
function getMouseCoordinates
static
getMouseCoordinates(Event
evt)
Gets the current mouse coordinates.
Usage example:
o2.Event.addEventListener('container', 'mousemove', function(evt) { var dimensions = o2.Event.getMouseCoordinates(evt); });
{x: mouseX, y: mouseY}
where x
is the distance from the top of the screen, and
y
is the distance from the left of the screen.
function getTarget
static
getTarget(Event
evt)
Gets the originating source of the event.
Usage example:
o2.Event.addEventListener('container', 'click', function(evt) { var src = o2.Event.getTarget(evt); });
function isArrowKey
static
isArrowKey(Event
evt)
Checks whether the pressed key is an arrow key.
Usage example:
o2.Event.addEventListener('container', 'keydown', function(evt) { var isArrowKey = o2.Event.isArrowKey(evt); });
true
if the pressed key is an arrow key,
false
otherwise.
function isBackspaceKey
static
isBackspaceKey(Event
evt)
Checks whether the pressed key is the backspace (DEL) key.
Usage example:
o2.Event.addEventListener('container', 'keydown', function(evt) { var isBackspaceKey = o2.Event.isBackspaceKey(evt); });
true
if the pressed key is the backspace key,
false
otherwise.
function isCharacterKeypressEvent
static
isCharacterKeypressEvent()
Checks whether the character in a onkeypress
event
actually produces a printable char.
The thing you have to remember is that you can't reliably tell
anything at all about any character that may be
typed in a onkeydown
or onkeyup
event:
The printable key is determined only in the onkeypress
handler.
Usage example:
o2.Event.addEventListener('container', 'keypress', function(evt) { var isCharKeypress = o2.Event.isCharacterKeypressEvent(evt); });
true
if the pressed key is a printable
character; false
otherwise.
function isEnterKey
static
isEnterKey(Event
evt)
Checks whether the pressed key is the enter (return) key.
Usage example:
o2.Event.addEventListener('container', 'keypress', function(evt) { var isEnterKey = o2.Event.isEnterKey(evt); });
true
if the pressed key is the enter key,
false
otherwise.
function isEscapeKey
static
isEscapeKey(Event
evt)
Checks whether the pressed key is the escape (ESC) key.
Usage example:
o2.Event.addEventListener('container', 'keypress', function(evt) { var isEscapeKey = o2.Event.isEscapeKey(evt); });
true
if the pressed key is the escape key,
false
otherwise.
function isRightClick
static
isRightClick(Event
evt)
Checks whether or not the curent action is a right click action.
Usage example:
o2.Event.addEventListener('container', 'click', function(evt) { var isRightClick = o2.Event.isRightClick(evt); });
true
if the event is a right click event,
false
otherwise.
function isTabKey
static
isTabKey(Event
evt)
Checks whether the pressed key is the tab key.
Usage example:
o2.Event.addEventListener('container', 'keypress', function(evt) { var isTabKey = o2.Event.isTabKey(evt); });
true
if the pressed key is the tab key,
false
otherwise.
function preventDefault
static
preventDefault(Event
evt)
Prevents the default action. When this method is called inside an
even handling callback, the default action associated with that
event is not triggered. Like, if it is an onclick
event on a link, then the browser does not go to the
href
of that link.
Usage example:
o2.Event.addEventListener('container', 'click', function(evt) { o2.Event.preventDefault(evt); });
evt
- the actual DOM Event
object used
internally in Event.addEventListener function removeEventListener
static
removeEventListener(DomNode
node, String
evt, Function
fn)
Removes an already-added new event listener from the DOM Node.
Usage example:
o2.Event.removeEventListener('container', 'click', container_click);
node
- the DOM object (or its String
reference) the evet shall be removed.
evt
- the name of the event (like "click",
"mousemove"...)
fn
- a reference to the on[event] callback action. function stopPropagation
static
stopPropagation(Event
evt)
Stops the propagation of the event upwards in the DOM hierarchy.
Note that "change" event does not bubble.
Also, events: change, submit, reset, focus, blur do not bubble in Internet Explorer.
According to specification, "focus" and "blur" should not bubble, while "change", "submit", "reset" should.
This behavior implemented properly in all web browsers but IE.
See http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-flow for details.
Usage example:
o2.Event.addEventListener('container', 'click', function(evt) { o2.Event.stopPropagation(evt); });
evt
- the actual DOM Event
object used
internally in Event.addEventListener
A cross-browser event handling and event utilities class.