Reference Source
public class | source

Commons

You can directly use an instance of this class. commons

Utility belt.

Member Summary

Public Members
public

Caution: the selector doesn't verify if elements are visible.

  • read-only

public

Caution: the selector doesn't verify if elements are visible.

  • read-only

public

Returns Coral global options retrieved on the <script> data attributes including:

  • [data-coral-icons]: source folder of the SVG icons.

Method Summary

Public Methods
public

addResizeListener(element: HTMLElement, onResize: Function)

Adds a resize listener to the given element.

public

augment(dest: Object, source: ...Object, handleCollision: CommonsHandleCollision): Object

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.

public

callAll(func: ...Function, nth: Number): Function

Call all of the provided functions, in order, returning the return value of the specified function.

public

extend(dest: Object, source: ...Object): Object

Copy the properties from all provided objects into the first object.

public

getSubProperty(root: Object, path: String): *

Get the value of the property at the given nested path.

public

Get a unique ID.

public

nextFrame(onNextFrame: Function): *

Execute the provided callback on the next animation frame.

public

ready(element: HTMLElement, onDefined: CommonsReadyCallback)

Checks if Coral components and all nested Coral components are defined as Custom Elements.

public

Removes a resize listener from the given element.

public

setSubProperty(root: Object, path: String, obj: String)

Assign an object given a nested path

public

Return a new object with the swapped keys and values of the provided object.

public

transitionEnd(element: HTMLElement, onTransitionEndCallback: CommonsTransitionEndCallback)

Execute the provided callback once a CSS transition has ended.

Public Members

public FOCUSABLE_ELEMENT_SELECTOR: String source

Caution: the selector doesn't verify if elements are visible.

  • read-only

See:

public TABBABLE_ELEMENT_SELECTOR: String source

Caution: the selector doesn't verify if elements are visible.

  • read-only

See:

public options: Object: * source

Returns Coral global options retrieved on the <script> data attributes including:

  • [data-coral-icons]: source folder of the SVG icons. If the icon collections have a custom name, they have to be loaded manually using Icon.load.
  • [data-coral-icons-external]: Whether SVG icons are always referenced as external resource. Possible values are "on" (default), "off" or "js" to load icons from a script.
  • [data-coral-typekit]: custom typekit id used to load the fonts.
  • [data-coral-logging]: defines logging level. Possible values are "on" (default) or "off".

Return:

Object

The global options object.

Public Methods

public addResizeListener(element: HTMLElement, onResize: Function) source

Adds a resize listener to the given element.

Params:

NameTypeAttributeDescription
element HTMLElement

The element to add the resize event to.

onResize Function

The resize callback.

public augment(dest: Object, source: ...Object, handleCollision: CommonsHandleCollision): Object source

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.

Params:

NameTypeAttributeDescription
dest Object

The object to copy properties to

source ...Object

An object to copy properties from. Additional objects can be passed as subsequent arguments.

handleCollision CommonsHandleCollision
  • optional

Called if the property being copied is already present on the destination. The return value will be used as the property value.

Return:

Object

The destination object, dest

public callAll(func: ...Function, nth: Number): Function source

Call all of the provided functions, in order, returning the return value of the specified function.

Params:

NameTypeAttributeDescription
func ...Function

A function to call

nth Number
  • optional
  • default: 0

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.

Return:

Function

The aggregate function.

public extend(dest: Object, source: ...Object): Object source

Copy the properties from all provided objects into the first object.

Params:

NameTypeAttributeDescription
dest Object

The object to copy properties to

source ...Object

An object to copy properties from. Additional objects can be passed as subsequent arguments.

Return:

Object

The destination object, dest

public getSubProperty(root: Object, path: String): * source

Get the value of the property at the given nested path.

Params:

NameTypeAttributeDescription
root Object

The root object on which the path should be traversed.

path String

The path of the sub-property to return.

Return:

*

The value of the provided property.

Throw:

*

Will throw an error if the path is not present on the object.

public getUID(): String source

Get a unique ID.

Return:

String

unique identifier.

public nextFrame(onNextFrame: Function): * source

Execute the provided callback on the next animation frame.

Params:

NameTypeAttributeDescription
onNextFrame Function

The callback to execute.

Return:

*

public ready(element: HTMLElement, onDefined: CommonsReadyCallback) source

Checks if Coral components and all nested Coral components are defined as Custom Elements.

Params:

NameTypeAttributeDescription
element HTMLElement

The element that should be watched.

onDefined CommonsReadyCallback

The callback to call when all components are ready.

See:

public removeResizeListener(element: HTMLElement, onResize: Function) source

Removes a resize listener from the given element.

Params:

NameTypeAttributeDescription
element HTMLElement

The element to remove the resize event from.

onResize Function

The resize callback.

public setSubProperty(root: Object, path: String, obj: String) source

Assign an object given a nested path

Params:

NameTypeAttributeDescription
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.

Throw:

*

Will throw an error if the path is not present on the object.

public swapKeysAndValues(obj: Object): Object source

Return a new object with the swapped keys and values of the provided object.

Params:

NameTypeAttributeDescription
obj Object

The object to copy.

Return:

Object

An object with its keys as the values and values as the keys of the source object.

public transitionEnd(element: HTMLElement, onTransitionEndCallback: CommonsTransitionEndCallback) source

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.

Params:

NameTypeAttributeDescription
element HTMLElement

The DOM element that is affected by the CSS transition.

onTransitionEndCallback CommonsTransitionEndCallback

The callback to execute.