Print Friendly

# Class YAHOO.ext.EventObject

Package: | YAHOO.ext
Class: | EventObject
Extends: | Object
Defined In: | EventManager.js

EventObject exposes the Yahoo! UI Event functionality directly on the object passed to your event handler. It exists mostly for convenience. It also fixes the annoying null checks automatically to cleanup your code (All the YAHOO.util.Event methods throw javascript errors if the passed event is null). To get an EventObject instead of the standard browser event, your must register your listener thru the YAHOO.ext.EventManager or directly on an Element with YAHOO.ext.Element.addManagedListener or the shorthanded equivalent YAHOO.ext.Element.mon.
Example:

    fu<>nction handleClick(e){ // e is not a standard event object, it is a YAHOO.ext.EventObject
        e.preventDefault();
        var target = e.getTarget();
        ...
     }
     var myDiv = getEl('myDiv');
     myDiv.mon('click', handleClick);
     //or
     YAHOO.ext.EventManager.on('myDiv', 'click', handleClick);
     YAHOO.ext.EventManager.addListener('myDiv', 'click', handleClick);

This class is a singleton and cannot be created directly.

## Public Properties

Property | Defined By
--- | ---
| BACKSPACE : Number | EventObject
Key constant
| DELETE : Number | EventObject
Key constant
| DOWN : Number | EventObject
Key constant
| END : Number | EventObject
Key constant
| ESC : Number | EventObject
Key constant
| F5 : Number | EventObject
Key constant
| HOME : Number | EventObject
Key constant
| LEFT : Number | EventObject
Key constant
| PAGEDOWN : Number | EventObject
Key constant
| PAGEUP : Number | EventObject
Key constant
| RETURN : Number | EventObject
Key constant
| RIGHT : Number | EventObject
Key constant
| SPACE : Number | EventObject
Key constant
| TAB : Number | EventObject
Key constant
| UP : Number | EventObject
Key constant
| altKey : Object | EventObject
True if the alt key was down during the event
| browserEvent : Object | EventObject
The normal browser event
| button : Object | EventObject
The button pressed in a mouse event
| ctrlKey : Object | EventObject
True if the control key was down during the event
| shiftKey : Object | EventObject
True if the shift key was down during the event

## Public Methods

Method | Defined By
--- | ---
| findTarget(`String className`, [`String tagName`]) : HTMLelement | EventObject
Walk up the DOM looking for a particular target - if the default target matches, it is returned.
| getCharCode() : Number | EventObject
Gets the key code for the event. Returns value from YAHOO.util.Event.getCharCode() if the event is not null.
| getKey() : Number | EventObject
Returns a browsers key for a keydown event
| getPageX() : Number | EventObject
Gets the x coordinate of the event. Returns value from YAHOO.util.Event.getPageX() if the event is not null.
| getPageY() : Number | EventObject
Gets the y coordinate of the event. Returns value from YAHOO.util.Event.getPageY() if the event is not null.
| getRelatedTarget() : HTMLElement | EventObject
Gets the related target. Returns value from YAHOO.util.Event.getRelatedTarget() if the event is not null.
| getTarget() : HTMLelement | EventObject
Gets the target for the event. Returns value from YAHOO.util.Event.getTarget() if the event is not null.
| getTime() : Number | EventObject
Gets the time of the event. Returns value from YAHOO.util.Event.getTime() if the event is not null.
| getWheelDelta() : Number | EventObject
Normalizes mouse wheel delta across browsers
| getXY() : Array | EventObject
Gets the page coordinates of the event. Returns value from YAHOO.util.Event.getXY() if the event is not null.
| hasModifier() : Boolean | EventObject
Returns true if the control, shift or alt key was pressed during this event.
| preventDefault() : void | EventObject
Prevents the browsers default handling of the event. Calls YAHOO.util.Event.preventDefault() if the event is not null.
| stopEvent() : void | EventObject
Stop the event. Calls YAHOO.util.Event.stopEvent() if the event is not null.
| stopPropagation() : void | EventObject
Cancels bubbling of the event. Calls YAHOO.util.Event.stopPropagation() if the event is not null.

## Public Events

This class has no public events.

## Property Details

### BACKSPACE

`public Number BACKSPACE`
Key constant
This property is defined by EventObject.

### DELETE

`public Number DELETE`
Key constant
This property is defined by EventObject.

### DOWN

`public Number DOWN`
Key constant
This property is defined by EventObject.

### END

`public Number END`
Key constant
This property is defined by EventObject.

### ESC

`public Number ESC`
Key constant
This property is defined by EventObject.

### F5

`public Number F5`
Key constant
This property is defined by EventObject.

### HOME

`public Number HOME`
Key constant
This property is defined by EventObject.

### LEFT

`public Number LEFT`
Key constant
This property is defined by EventObject.

### PAGEDOWN

`public Number PAGEDOWN`
Key constant
This property is defined by EventObject.

### PAGEUP

`public Number PAGEUP`
Key constant
This property is defined by EventObject.

### RETURN

`public Number RETURN`
Key constant
This property is defined by EventObject.

### RIGHT

`public Number RIGHT`
Key constant
This property is defined by EventObject.

### SPACE

`public Number SPACE`
Key constant
This property is defined by EventObject.

### TAB

`public Number TAB`
Key constant
This property is defined by EventObject.

### UP

`public Number UP`
Key constant
This property is defined by EventObject.

### altKey

`public Object altKey`
True if the alt key was down during the event
This property is defined by EventObject.

### browserEvent

`public Object browserEvent`
The normal browser event
This property is defined by EventObject.

### button

`public Object button`
The button pressed in a mouse event
This property is defined by EventObject.

### ctrlKey

`public Object ctrlKey`
True if the control key was down during the event
This property is defined by EventObject.

### shiftKey

`public Object shiftKey`
True if the shift key was down during the event
This property is defined by EventObject.

## Method Details

### findTarget

`public function findTarget(`String className`, [`String tagName`])`
Walk up the DOM looking for a particular target - if the default target matches, it is returned.
Parameters:

- `className` : String
  The class name to look for or null
- `tagName` : String
  (optional) The tag name to look for

Returns:

- `HTMLelement`

This method is defined by EventObject.

### getCharCode

`public function getCharCode()`
Gets the key code for the event. Returns value from YAHOO.util.Event.getCharCode() if the event is not null.
Parameters:

- None.

Returns:

- `Number`

This method is defined by EventObject.

### getKey

`public function getKey()`
Returns a browsers key for a keydown event
Parameters:

- None.

Returns:

- `Number`
  The key code

This method is defined by EventObject.

### getPageX

`public function getPageX()`
Gets the x coordinate of the event. Returns value from YAHOO.util.Event.getPageX() if the event is not null.
Parameters:

- None.

Returns:

- `Number`

This method is defined by EventObject.

### getPageY

`public function getPageY()`
Gets the y coordinate of the event. Returns value from YAHOO.util.Event.getPageY() if the event is not null.
Parameters:

- None.

Returns:

- `Number`

This method is defined by EventObject.

### getRelatedTarget

`public function getRelatedTarget()`
Gets the related target. Returns value from YAHOO.util.Event.getRelatedTarget() if the event is not null.
Parameters:

- None.

Returns:

- `HTMLElement`

This method is defined by EventObject.

### getTarget

`public function getTarget()`
Gets the target for the event. Returns value from YAHOO.util.Event.getTarget() if the event is not null.
Parameters:

- None.

Returns:

- `HTMLelement`

This method is defined by EventObject.

### getTime

`public function getTime()`
Gets the time of the event. Returns value from YAHOO.util.Event.getTime() if the event is not null.
Parameters:

- None.

Returns:

- `Number`

This method is defined by EventObject.

### getWheelDelta

`public function getWheelDelta()`
Normalizes mouse wheel delta across browsers
Parameters:

- None.

Returns:

- `Number`
  The delta

This method is defined by EventObject.

### getXY

`public function getXY()`
Gets the page coordinates of the event. Returns value from YAHOO.util.Event.getXY() if the event is not null.
Parameters:

- None.

Returns:

- `Array`
  The xy values like [x, y]

This method is defined by EventObject.

### hasModifier

`public function hasModifier()`
Returns true if the control, shift or alt key was pressed during this event.
Parameters:

- None.

Returns:

- `Boolean`

This method is defined by EventObject.

### preventDefault

`public function preventDefault()`
Prevents the browsers default handling of the event. Calls YAHOO.util.Event.preventDefault() if the event is not null.
Parameters:

- None.

Returns:

- `void`

This method is defined by EventObject.

### stopEvent

`public function stopEvent()`
Stop the event. Calls YAHOO.util.Event.stopEvent() if the event is not null.
Parameters:

- None.

Returns:

- `void`

This method is defined by EventObject.

### stopPropagation

`public function stopPropagation()`
Cancels bubbling of the event. Calls YAHOO.util.Event.stopPropagation() if the event is not null.
Parameters:

- None.

Returns:

- `void`

This method is defined by EventObject.

yui-ext - Copyright © 2006 Jack Slocum. | Yahoo! UI - Copyright © 2006 Yahoo! Inc.
All rights reserved.