strowger.event

Functions for managing DOM events.

add-listeners

(add-listeners element key listeners)

Add a map of event keywords to listener functions to a DOM element. The key argument is a unique value used to identify the listeners so that they can be removed using remove-listeners.

button->keyword

A map of mouse button codes to their corresponding button names.

client-xy

(client-xy event)

Return the client X and Y coordinates of an event as an [x y] vector.

event-button

(event-button event)

Return the name of the button clicked on a :click or :dblclick event.

event-key

(event-key event)

Return the name of the key pressed on a :keyup, :keydown or :keypress event.

keycode->keyword

A map of key codes to their corresponding keyboard key names.

keyword->button

A map of the names of mouse buttons to their corresponding codes.

keyword->keycode

A map of the names of keyboard keys to their corresponding codes.

offset-xy

(offset-xy event)

Return the offset X and Y coordinate of an event as an [x y] vector. This function forces adherance to the W3C standard, avoiding cross-browser issues with .-offsetX and .-offsetY.

remove-listeners

(remove-listeners element key)

Remove all the listeners on a DOM element associated with the supplied key. See add-listeners.