Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.

guide to events

oatkiller edited this page Sep 13, 2010 · 1 revision

add_listener

use this to add an event listener.

add_listener registers the event to be removed on window unload in order to protect ie users from reported issues. add_listener also passes a second object in addition to the event. the second object has several methods that get properties and perform actions on the event.

var remove_the_event = o.dom.event.add_listener(document.body,'click',function (e,oe) {

// oe has .get_target which returns the target of the event
o.dom.remove_node(oe.get_target());

// add_listener returns an function that removes the listener
remove_the_event();

});// remove the first element the users clicks from the dom.
  1. first param should be an element to attach the event
  2. second param should be a type in the form of ‘click’ for click events and ‘load’ for onload etc.
  3. third param should be a function to be exectued.
  4. lastly, optionally pass a boolean to turn on capturing in mozilla and the rest of the w3c fan browsers

oe (get_abstraction)

the second param passed to an event handler that is registered with add_listener is an object with several methods that act on the event.

get_event: returns a reference to the event (some browsers dont pass it to the handler)
get_button: returns the mouse button used on mousedown and mouseup events
get_key: returns the key used in a kewdown and keyup or the character in a keypress event
get_mouse_coordinates: returns an obj with x and y integers that are the mouse coordinates
get_related_target: returns the element being moused to and from in mouseout and mouseover events
get_target: returns the element the event occured on
prevent_default: attempts to stop the browsers built in behavior, such as navigation in the case of a click to a link or submittion in the case of submit in a form
cancel: stops the propogation of an event to other elements

sometimes this also has a delegate_target property which is a reference to the target the delegate function picked

Clone this wiki locally