-
Notifications
You must be signed in to change notification settings - Fork 1
guide to events
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.- first param should be an element to attach the event
- second param should be a type in the form of ‘click’ for click events and ‘load’ for onload etc.
- third param should be a function to be exectued.
- lastly, optionally pass a boolean to turn on capturing in mozilla and the rest of the w3c fan browsers
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