Event class

From PhiWiki
Jump to: navigation, search

The Event class offers properties to query events. Since v1.3.0 Phi[sketeer] uses jQuery to normalize the event object over different browser implementations.

Basic event handler
Button Mouse Key Misc Custom
.click() .mouseover() .keydown() .focus() .on()
.dblclick() .mouseout() .keyup() .blur() .off()
.mousedown() .mousemove() .keypress() .drop() .one()
.mouseup() .trigger()

Usage

Use the provided event handler in Phi to get the normalized event object.

Properties

  • Boolean altKey [read]
  • Number button [read]
  • Number clientX [read]
  • Number clientY [read]
  • Boolean ctrlKey [read]
  • Boolean metaKey [read]
  • Number pageX [read]
  • Number pageY [read]
  • Number screenX [read]
  • Number screenY [read]
  • Boolean shiftKey [read]
  • Number timeStamp [read]
  • String type [read]
  • Number which [read]

Boolean altKey

Indicates if the ALT key was pressed.

Number button

Returns the number of mouse buttons which are pressed during a mouse event.

  • 0 left button
  • 1 mid button
  • 2 right buttom

Warning: Not all browsers support the button property correctly. Use e.which instead.

Number clientX

Returns the number of pixels relative to the left side of the browser window during a mouse event.

Number clientY

Returns the number of pixels relative to the top of the browser window during a mouse event.

Boolean ctrlKey

Indicates if the CTRL key was pressed.

Boolean metaKey

Indicates if the META key was pressed.

Number pageX

Returns the number of pixels relative to the left side of the document during a mouse event.

Number pageY

Returns the number of pixels relative to the top of the document during a mouse event.

Number screenX

Returns the number of pixels relative to the left border of the complete screen during a mouse event.

Number screenY

Returns the number of pixels relative to the top of the complete screen during a mouse event.

Boolean shiftKey

Indicates if the SHIFT key was pressed.

Number timeStamp

Returns the difference in milliseconds between the event occurred and 1. Jan. 1970 UTC.

Warning: Firefox has a long term bug regarding the timeStamp property.

String type

Returns the nature of the event like onclick, onmousemove, etc.

Number which

Contains the key code in a key event or the mouse button code which was pressed in a mouse event.

In a mouse event the following codes are returned:

  • 0 no button
  • 1 left button
  • 2 mid button
  • 3 right button

Functions

Boolean isDefaultPrevented()

v2.0.0 returns true if the default action has been prevented, otherwise false.

Boolean isPropagationStopped()

v2.0.0 returns true if the propagation has been stopped, otherwise false.

Void preventDefault()

v2.0.0 prevents the default action of this item.

Void stopPropagation()

v2.0.0 stops the propagation to other elements.

Additional notes

We highly recommend not to use the built-in browser handler like
item.onclick=function(){}
Use the shorthand handler to get a normalized event object.