Module: events

events.js. An Event System (John Resig - Secrets of a JS Ninja http://jsninja.com/) (Original book version wasn't completely usable, so fixed some things and made Closure Compiler compatible) This should work very similarly to jQuery's events, however it's based off the book version which isn't as robust as jquery's, so there's probably some differences.

Source:
utils/events.js

Methods


<static> fixEvent(event)

Fix a native event to have standard property values

Parameters:
Name Type Description
event Object

Event object to fix.

Source:
utils/events.js
Returns:

Fixed event object.

Type
Object

<static> off(elem [, type] [, fn])

Removes event listeners from an element

Parameters:
Name Type Argument Description
elem Element | Object

Object to remove listeners from.

type string | Array.<string> <optional>

Type of listener to remove. Don't include to remove all events from element.

fn EventTarget~EventListener <optional>

Specific listener to remove. Don't include to remove listeners for an event type.

Source:
utils/events.js

<static> on(elem, type, fn)

Add an event listener to element It stores the handler function in a separate cache object and adds a generic handler to the element's event, along with a unique id (guid) to the element.

Parameters:
Name Type Description
elem Element | Object

Element or object to bind listeners to

type string | Array.<string>

Type of event to bind to.

fn EventTarget~EventListener

Event listener.

Source:
utils/events.js

<static> one(elem, type, fn)

Trigger a listener only once for an event

Parameters:
Name Type Description
elem Element | Object

Element or object to bind to.

type string | Array.<string>

Name/type of event

fn Event~EventListener

Event Listener function

Source:
utils/events.js

<static> trigger(elem, event [, hash])

Trigger an event for an element

Parameters:
Name Type Argument Description
elem Element | Object

Element to trigger an event on

event EventTarget~Event | string

A string (the type) or an event object with a type attribute

hash Object <optional>

data hash to pass along with the event

Source:
utils/events.js
Returns:
  • Returns the opposite of defaultPrevented if default was prevented
      - Otherwise returns undefined
Type
boolean | undefined

<inner> _cleanUpEvents(elem, type)

Clean up the listener cache and dispatchers

Parameters:
Name Type Description
elem Element | Object

Element to clean up

type string

Type of event to clean up

Source:
utils/events.js

<inner> _handleMultipleEvents(fn, elem, type, callback)

Loops through an array of event types and calls the requested method for each type.

Parameters:
Name Type Description
fn function

The event method we want to use.

elem Element | Object

Element or object to bind listeners to

type string

Type of event to bind to.

callback EventTarget~EventListener

Event listener.

Source:
utils/events.js