Namespace: CB_Events

CB_Events

Static class to manage events. It will return itself if it is tried to be instantiated.

Source:

Methods


<static> add()

Alias for CB_Events.on.

Source:
See:

<static> executeByName(eventTarget, eventName [, e] [, returnOnNothingExecuted]) → {boolean}

Executes all event listeners for an specific event from a node (target).

Parameters:
Name Type Argument Description
eventTarget Object

The target whose event listeners we want to execute. It will be the value of "this" for every call to each listener.

eventName string

The name of the event whose event listeners we want to execute.

e Event <optional>

Event object that will be passed as the first and unique parameter for every call to each listener.

returnOnNothingExecuted * <optional>

The value that will be returned by the function if nothing is executed.

Source:
Returns:

Returns the result of doing the AND operator of all return values of each listener executed. If only one listener is executed, it will return the result of doing the AND operator with its returning value and "true". Returns the value of the "returnOnNothingExecuted" parameter if nothing is executed.

Type
boolean

<static> getAll() → {array}

Returns all stored event handlers (if any).

Source:
Returns:

Returns an array of CB_Events.EVENT_HANDLER objects.

Type
array

<static> getByName(eventTarget, eventName [, onlyWithFunction]) → {array}

Returns all handlers for an specific event from a node (target), if any.

Parameters:
Name Type Argument Default Description
eventTarget Object

The target whose event listeners we want to get.

eventName string

The name of the event whose event listeners we want to get.

onlyWithFunction boolean <optional>
false

Defines whether to return only the handlers which have a function as the listener.

Source:
Returns:

Returns an array of CB_Events.EVENT_HANDLER objects.

Type
array

<static> getType(e) → {string}

Returns the type of an event, if any (otherwise, returns an empty string).

Parameters:
Name Type Description
e Event

Event object.

Source:
Returns:
Type
string

<static> normalize(e) → {Event}

Gets the right event object for the current web client and normalizes it attaching to it some methods and properties if they were not present (as preventDefault, stopPropagation, target, etc.). The new attached methods and properties may include polyfills, etc.

Parameters:
Name Type Description
e Event

Event object. If not provided, it will use the value of "event", "window.event", "Event" or an empty object ("{}").

Source:
Returns:

Returns the event object normalized.

Type
Event

<static> on(eventTarget, eventName, eventFunction [, useCapture] [, keepOldEventFunction] [, erasable])

Adds an event listener.

Parameters:
Name Type Argument Default Description
eventTarget Object

The target where we want to attach the event listener.

eventName string

The name of the event that we want to add.

eventFunction function

The function (event listener) of the event that we want to add.

useCapture boolean <optional>
false

Defines whether the event we want to add will use capture or not. This parameter will be effective only if the current client supports the addEventListener method and will be used as its third parameter.

keepOldEventFunction boolean <optional>
true

Defines whether we want to keep any possible previous event listener for the same target and event name or not.

erasable boolean <optional>
true

Defines whether the event listener will be erasable by CB_Events.removeAll or CB_Events.removeByName functions later or not (it will always be erasable if we force delete).

Source:
To Do:
  • Try to simulate "useCapture" when the "addEventListener" method is not available.

<static> remove(eventTarget, eventName, eventFunction [, useCapture])

Removes an event listener (even if it is not erasable).

Parameters:
Name Type Argument Default Description
eventTarget Object

The target whose event listener we want to remove.

eventName string

The name of the event that we want to remove.

eventFunction function

The function (event listener) of the event that we want to remove.

useCapture boolean <optional>
false

Defines whether the event we want to remove was defined to use capture or not.

Source:

<static> removeAll( [forceDelete])

Removes all event listeners.

Parameters:
Name Type Argument Default Description
forceDelete boolean <optional>
false

If it is set to true, it will remove all event listeners (even the ones which were added as not erasable).

Source:

<static> removeByName(eventTarget, eventName [, forceDelete])

Deletes all handlers for an specific event from a node (target).

Parameters:
Name Type Argument Default Description
eventTarget Object

The target whose event listeners we want to remove.

eventName string

The name of the event whose event listeners we want to remove.

forceDelete boolean <optional>
false

If it is set to true, it will remove any listener (even the ones which were added as not erasable).

Source:

Type Definitions


EVENT_HANDLER

Object that contains an event handler.

Type:
  • Object
Properties:
Name Type Description
eventTarget Object

The target of the event.

eventName string

The name of the event.

eventFunction function

The event listener.

useCapture boolean

Defines whether the event listener was defined to use capture or not.

erasable boolean

Defines whether the event handler is erasable (without forcing delete) or not.

Source: