Coral.commons is Coral's utility belt. It contains shared functions that are used throughout Coral.

Coral.commons API

The Coral utility belt.

Static Properties

Coral.commons.FOCUSABLE_ELEMENT_SELECTOR {String}

Focusable elements are defined by https://www.w3.org/TR/html5/editing.html#focus-management. Caution: the selector doesn't verify if elements are visible.

Coral.commons.TABBABLE_ELEMENT_SELECTOR {String}

Tabbable elements are defined by https://www.w3.org/TR/html5/editing.html#sequential-focus-navigation-and-the-tabindex-attribute. Caution: the selector doesn't verify if elements are visible.

Methods

Coral.commons.augment

Copy the properties from the source object to the destination object, but calls the callback if the property is already present on the destination object.
Parameters:
Name Type Optional Description
dest Object No
The object to copy properties to
source Object No
An object to copy properties from. Additional objects can be passed as subsequent arguments.
handleCollision Coral.commons~handleCollision Yes
Called if the property being copied is already present on the destination. The return value will be used as the property value.
Returns:
The destination object, dest {Object}

Coral.commons.callAll

Call all of the provided functions, in order, returning the return value of the specified function.
Parameters:
Name Type Optional Default Description
func function No
A function to call
nth Number Yes
A zero-based index indicating the noth argument to return the value of. If the nth argument is not a function, null will be returned.
Returns:
The aggregate function. {function}

Coral.commons.extend

Copy the properties from all provided objects into the first object.
Parameters:
Name Type Description
dest Object The object to copy properties to
source Object An object to copy properties from. Additional objects can be passed as subsequent arguments.
Returns:
The destination object, dest {Object}

Coral.commons.getSubProperty

Get the value of the property at the given nested path.
Parameters:
Name Type Description
root Object The root object on which the path should be traversed.
path String The path of the sub-property to return.
Throws:
Will throw an error if the path is not present on the object.
Returns:
The value of the provided property. {*}

Coral.commons.getUID

Get a unique ID.
Returns:
unique identifier. {String}

Coral.commons.mixin

Mix a set of mixins to a target object.
Parameters:
Name Type Description
target Object The target prototype or instance on which to apply mixins.
mixins Object|Coral~mixin|Array.<(Object|Coral~mixin)> A mixin or set of mixins to apply.
options Object An object that will be passed to functional mixins as the second argument (options).

Coral.commons.nextFrame

Execute the provided callback on the next animation frame.
Parameters:
Name Type Description
callback function The callback to execute.

Coral.commons.ready

Checks, if a Coral components and all nested components are ready, which means their _initialize and _render methods have been called. If so, the provided callback function is executed
Parameters:
Name Type Description
element HTMLElement The element that should be watched for ready events.
callback Coral.commons~readyCallback The callback to call when all components are ready.

Coral.commons.setSubProperty

Assign an object given a nested path
Parameters:
Name Type Description
root Object The root object on which the path should be traversed.
path String The path at which the object should be assignment.
obj String The object to assign at path.
Throws:
Will throw an error if the path is not present on the object.

Coral.commons.swapKeysAndValues

Return a new object with the swapped keys and values of the provided object.
Parameters:
Name Type Description
obj Object The object to copy.
Returns:
An object with its keys as the values and values as the keys of the source object. {Object}

Coral.commons.transitionEnd

Execute the provided callback once a CSS transition has ended. This method listens for the next transitionEnd event on the given DOM element. In case the provided element does not have a transition defined, the callback will be called in the next macrotask to allow a normal application execution flow. It cannot be used to listen continuously on transitionEnd events.
Parameters:
Name Type Description
element HTMLElement The DOM element that is affected by the CSS transition.
callback Coral.commons~transitionEndCallback The callback to execute.

Type Definitions

instance.handleCollision

Called when a property already exists on the destination object.
Parameters:
Name Type Description
oldValue * The value currently present on the destination object.
newValue * The value on the destination object.
prop * The property that collided.
dest * The destination object.
source * The source object.
Returns:
The value to use. If undefined, the old value will be used. {*}

instance.readyCallback

Execute the callback once a component and sub-components are ready.
Parameters:
Name Type Description
element HTMLElement The element that is ready.

instance.transitionEndCallback

Execute the callback once a CSS transition has ended.
Parameters:
Name Type Description
event

The event passed to the callback.

Name Type Description
event.target HTMLElement The DOM element that was affected by the CSS transition.
event.cssTransitionSupported Boolean Whether CSS transitions are supported by the browser.
event.transitionStoppedByTimeout Boolean Whether the CSS transition has been ended by a timeout (should only happen as a fallback).