Namespace: CB_Elements

CB_Elements

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

Source:
To Do:
  • Think about creating a function called "add" or "create" to create a new element (it could accept "tagName", "id" and "content" parameters).
  • Think about creating "setStyle" and "setStyleById" methods to add a given style attribute and also supporting a boolean parameter to also add the style attribute with vendor prefixes (webkit, moz, ms, o, khtml) if we want to.

Methods


<static> addClass(element, className [, checkValues] [, onAddClass]) → {Node}

Adds a desired class to a given element. The element can contain other classes and they will be kept.

Parameters:
Name Type Argument Default Description
element Node

The element that will get the new given class.

className string

The class that will be added.

checkValues boolean <optional>
false

If it is set to true, it will only try to add the given class if it is not being used already. It is recommended to use true to prevent some old clients from adding the same class multiple times.

onAddClass function <optional>

Callback function that will be called if the class of the element has been added, after doing it (this will happens always if "checkValues" is false). The first and unique parameter passed will be the affected element itself.

Source:
To Do:
  • Think about allowing to use more than once class (and think how many times the "onAddClass" function should be called).
Returns:

Returns the given element again.

Type
Node

<static> addClassById(elementId, className [, checkValues] [, onAddClass]) → {Node|null}

Adds a desired class to a given element (by its identifier). The element can contain other classes and they will be kept.

Parameters:
Name Type Argument Default Description
elementId string

The identifier of the element that will get the new given class.

className string

The class that will be added.

checkValues boolean <optional>
false

If it is set to true, it will only try to add the given class if it is not being used already. It is recommended to use true to prevent some old clients from adding the same class multiple times.

onAddClass function <optional>

Callback function that will be called if the class of the element has been added, after doing it (this will happens always if "checkValues" is false). The first and unique parameter passed will be the affected element itself.

Source:
To Do:
  • Think about allowing to use more than once class (and think how many times the "onAddClass" function should be called).
Returns:

Returns the affected element (if any) or null otherwise.

Type
Node | null

<static> appendContent(container, content [, displayValue] [, checkValues] [, computed] [, onContentWritten] [, onShow] [, appendAtBeginning]) → {Node}

Appends the desired content inside a given element, keeping the existing one (using innerHTML). Calls the CB_Elements.insertContent internally.

Parameters:
Name Type Argument Default Description
container Node

The element whose content we want to modify.

content string

The content that we want to add.

displayValue string <optional>

If provided, it will call CB_Elements.show internally after inserting the content to set the given display property to the element.

checkValues boolean <optional>
false

If it is set to true, it will only change the content if the current one is different from the given one and it will pass the same parameter to CB_Elements.show if it is called internally (when "displayValue" is given).

computed boolean <optional>
false

If "displayValue" is given, it will pass this parameter to CB_Elements.show if it is called internally (when "displayValue" is given).

onContentWritten function <optional>

Callback function that will be called if the content has been written, after doing it (this will happens always if "checkValues" is false). The unique parameter passed will be the container itself.

onShow function <optional>

If "displayValue" is given, it will pass this parameter to CB_Elements.show when it is called internally.

appendAtBeginning boolean <optional>
false

If set to true, it will append the given content to the existing one instead of overwritten it.

Source:
Returns:

Returns the given container again.

Type
Node

<static> appendContentBeginning(container, content [, displayValue] [, checkValues] [, computed] [, onContentWritten] [, onShow]) → {Node}

Appends the desired content inside a given element at the beginning, keeping the existing one (using innerHTML). Calls the CB_Elements.insertContent internally.

Parameters:
Name Type Argument Default Description
container Node

The element whose content we want to modify.

content string

The content that we want to add.

displayValue string <optional>

If provided, it will call CB_Elements.show internally after inserting the content to set the given display property to the element.

checkValues boolean <optional>
false

If it is set to true, it will only change the content if the current one is different from the given one and it will pass the same parameter to CB_Elements.show if it is called internally (when "displayValue" is given).

computed boolean <optional>
false

If "displayValue" is given, it will pass this parameter to CB_Elements.show if it is called internally (when "displayValue" is given).

onContentWritten function <optional>

Callback function that will be called if the content has been written, after doing it (this will happens always if "checkValues" is false). The unique parameter passed will be the container itself.

onShow function <optional>

If "displayValue" is given, it will pass this parameter to CB_Elements.show when it is called internally.

Source:
Returns:

Returns the given container again.

Type
Node

<static> appendContentById(containerId, content [, displayValue] [, checkValues] [, computed] [, onContentWritten] [, onShow] [, append] [, appendAtBeginning]) → {Node|null}

Appends the desired content inside a given element, keeping the existing one (using innerHTML), by its identifier. Calls the CB_Elements.insertContent internally.

Parameters:
Name Type Argument Default Description
containerId string

The identifier of the element whose content we want to modify.

content string

The content that we want to add.

displayValue string <optional>

If provided, it will call CB_Elements.show internally after inserting the content to set the given display property to the element.

checkValues boolean <optional>
false

If it is set to true, it will only change the content if the current one is different from the given one and it will pass the same parameter to CB_Elements.show if it is called internally (when "displayValue" is given).

computed boolean <optional>
false

If "displayValue" is given, it will pass this parameter to CB_Elements.show if it is called internally (when "displayValue" is given).

onContentWritten function <optional>

Callback function that will be called if the content has been written, after doing it (this will happens always if "checkValues" is false). The unique parameter passed will be the affected container itself.

onShow function <optional>

If "displayValue" is given, it will pass this parameter to CB_Elements.show when it is called internally.

append boolean <optional>
false

If set to true, it will append the given content to the existing one instead of overwritten it. By default, it appends it at the end unless that the "appendAtBeginning" is set to true.

appendAtBeginning boolean <optional>
false

If set to true, it will append the given content to the existing one instead of overwritten it.

Source:
Returns:

Returns the affected container (if any) or null otherwise.

Type
Node | null

<static> appendContentByIdBeginning(containerId, content [, displayValue] [, checkValues] [, computed] [, onContentWritten] [, onShow] [, append]) → {Node|null}

Appends the desired content inside a given element at the beginning, keeping the existing one (using innerHTML), by its identifier. Calls the CB_Elements.insertContent internally.

Parameters:
Name Type Argument Default Description
containerId string

The identifier of the element whose content we want to modify.

content string

The content that we want to add.

displayValue string <optional>

If provided, it will call CB_Elements.show internally after inserting the content to set the given display property to the element.

checkValues boolean <optional>
false

If it is set to true, it will only change the content if the current one is different from the given one and it will pass the same parameter to CB_Elements.show if it is called internally (when "displayValue" is given).

computed boolean <optional>
false

If "displayValue" is given, it will pass this parameter to CB_Elements.show if it is called internally (when "displayValue" is given).

onContentWritten function <optional>

Callback function that will be called if the content has been written, after doing it (this will happens always if "checkValues" is false). The unique parameter passed will be the affected container itself.

onShow function <optional>

If "displayValue" is given, it will pass this parameter to CB_Elements.show when it is called internally.

append boolean <optional>
false

If set to true, it will append the given content to the existing one instead of overwritten it. By default, it appends it at the end unless that the "appendAtBeginning" is set to true.

Source:
Returns:

Returns the affected container (if any) or null otherwise.

Type
Node | null

<static> byId()

Alias for CB_Elements.id.

Source:
See:

<static> classes(classNames [, baseElement] [, useCache]) → {NodeList|array}

Returns elements by their class or classes name.

Parameters:
Name Type Argument Default Description
classNames string

The name of the class or classes (separated by a blank space) whose elements we want to find. The order of the classes is just important for the internal cache.

baseElement Node <optional>
document

The node element parent where we want to focus our search.

useCache boolean <optional>
CB_Configuration.CrossBase.CB_Elements_classes_USE_CACHE

Defines whether to try to get the result from an internal cache (it will exist if we previously called the function with the same parameters) or not. The internal cache will be updated when this parameter is set to false or it will be created automatically when it did not exist before.

Source:
Returns:

Returns the elements (NodeList or array, depending on the web client).

Type
NodeList | array

<static> classesCacheClear( [classNames] [, baseElement]) → {Object}

Clears the internal cache used by CB_Elements.classes and others. If no parameter is given, whole internal cache will be cleared.

Parameters:
Name Type Argument Description
classNames string <optional>

The name of the class or classes (separated by a blank space) whose internal cache we want to clear. The order of the classes is important for the internal cache. If not provided, it will clear the whole internal cache or the internal cache that belongs to the "baseElement" given (if provided).

baseElement Node <optional>

The node element parent whose internal cache we want to clear. If not provided but "classNames" is provided, it will clear the internal cache which matches the given "classNames" for any nodes. If it is provided but "classNames" is not, it will clear all the internal cache that belongs to this node element.

Source:
Returns:

Returns the current internal cache after cleaning it (if it is has been possible), which is an associative array of two dimensions (JavaScript object) whose first index belongs to the nodes, the second and last index belongs to the class name or class names and the value belongs to the returning value of the CB_Elements.classes function when it was called for those parameters.

Type
Object

<static> classesCacheUpdate(classNames [, baseElement]) → {NodeList|array}

Returns elements by their class or classes name, updating (or creating) the internal cache. Calls the CB_Elements.classes function internally, with the "useCache" parameter set to false.

Parameters:
Name Type Argument Default Description
classNames string

The name of the class or classes (separated by a blank space) whose elements we want to find. The order of the classes is just important for the internal cache.

baseElement Node <optional>
document

The node element parent where we want to focus our search.

Source:
Returns:

Returns the elements (NodeList or array, depending on the web client).

Type
NodeList | array

<static> classesRemove(classNames [, baseElement] [, useCache])

Removes elements by their class or classes name.

Parameters:
Name Type Argument Default Description
classNames string

The name of the class or classes (separated by a blank space) whose elements we want to delete. The order of the classes is just important for the internal cache.

baseElement Node <optional>
document

The node element parent where we want to focus our search.

useCache boolean <optional>
CB_Configuration.CrossBase.CB_Elements_classes_USE_CACHE

Defines whether to try to get the result from an internal cache (it will exist if we previously called the function with the same parameters) or not. The internal cache will be updated when this parameter is set to false or it will be created automatically when it did not exist before.

Source:

<static> contextMenuDisable( [element] [, disableContextMenu]) → {Node}

Disables or enables the contextual menu for a given element or in the whole document.

Parameters:
Name Type Argument Default Description
element Node <optional>
document

The element whose contextual menu we want to disable or enable. If not given, it will affect the whole document.

disableContextMenu boolean <optional>
true

If set to false, it will allow showing the contextual menu. Otherwise, it will prevent it to show.

Source:
Returns:

Returns the affected element.

Type
Node

<static> contextMenuDisableById(elementId [, disableContextMenu]) → {Node|null}

Disables or enables the contextual menu for a given element (by its identifier).

Parameters:
Name Type Argument Default Description
elementId string

The identifier of the element whose contextual menu we want to disable or enable.

disableContextMenu boolean <optional>
true

If set to false, it will allow showing the contextual menu. Otherwise, it will prevent it to show.

Source:
Returns:

Returns the affected element (if any) or null otherwise.

Type
Node | null

<static> get()

Alias for CB_Elements.id.

Source:
See:

<static> getById()

Alias for CB_Elements.id.

Source:
See:

<static> getFrameBodyContent(frameElement) → {string|null}

Tries to get the body content of an iframe. Depending on the client and the safety measures, this might fail.

Parameters:
Name Type Description
frameElement HTMLIFrameElement

The iframe element whose body content we want to get.

Source:
Returns:

Returns null if something goes wrong.

Type
string | null

<static> getFrameBodyContentById(frameElementId) → {string|null}

Tries to get the body content of an iframe (by its identifier). Depending on the client and the safety measures, this might fail.

Parameters:
Name Type Description
frameElementId string

The identifier of the iframe element whose body content we want to get.

Source:
Returns:

Returns null if something goes wrong.

Type
string | null

<static> getHeight(element [, returnNullOnFail] [, computed]) → {*}

Returns the height of an element (having in mind its border).

Parameters:
Name Type Argument Default Description
element Node

The element whose data we are interested in.

returnNullOnFail function <optional>
false

If it is set to true, it will return null instead of zero (0) in the case that something goes wrong.

computed boolean <optional>
false

This parameter will be used when it calls CB_Elements.getStylePropertyInteger internally.

Source:
Returns:

It could return zero (0) or even a non-numeric value if something fails (use "returnNullOnFail" set to true to return null when it fails).

Type
*

<static> getHeightById(elementId [, returnNullOnFail] [, computed]) → {*}

Returns the height of an element (having in mind its border), by its identifier.

Parameters:
Name Type Argument Default Description
elementId string

The identifier of the element whose data we are interested in.

returnNullOnFail function <optional>
false

If it is set to true, it will return null instead of zero (0) in the case that something goes wrong.

computed boolean <optional>
false

This parameter will be used when it calls CB_Elements.getStylePropertyInteger internally.

Source:
Returns:

It could return zero (0) or even a non-numeric value if something fails (use "returnNullOnFail" set to true to return null when it fails).

Type
*

<static> getLeft(element [, ignoreScroll] [, returnNullOnFail] [, computed]) → {*}

Returns the left position of an element (having in mind getBoundingClientRect if available, its parents, etc.).

Parameters:
Name Type Argument Default Description
element Node

The element whose data we are interested in.

ignoreScroll boolean <optional>
true

If it is set to false, it will have in mind the current scroll position to calculate the result.

returnNullOnFail function <optional>
false

If it is set to true, it will return null instead of zero (0) in the case that something goes wrong.

computed boolean <optional>
false

This parameter will be used when it calls CB_Elements.getStyleProperty and CB_Elements.getStylePropertyInteger internally.

Source:
Returns:

It could return zero (0) or even a non-numeric value if something fails (use "returnNullOnFail" set to true to return null when it fails).

Type
*

<static> getLeftById(elementId [, ignoreScroll] [, returnNullOnFail] [, computed]) → {*}

Returns the left position of an element (having in mind getBoundingClientRect if available, its parents, etc.), by its identifier.

Parameters:
Name Type Argument Default Description
elementId string

The identifier of the element whose data we are interested in.

ignoreScroll boolean <optional>
true

If it is set to false, it will have in mind the current scroll position to calculate the result.

returnNullOnFail function <optional>
false

If it is set to true, it will return null instead of zero (0) in the case that something goes wrong.

computed boolean <optional>
false

This parameter will be used when it calls CB_Elements.getStyleProperty and CB_Elements.getStylePropertyInteger internally.

Source:
Returns:

It could return zero (0) or even a non-numeric value if something fails (use "returnNullOnFail" set to true to return null when it fails).

Type
*

<static> getParent(element) → {Node|null}

Returns the first parent of a given element:

Parameters:
Name Type Description
element Node

The element whose parent we want to get.

Source:
Returns:

Returns null if the parent cannot be found.

Type
Node | null

<static> getParentById(elementId) → {Node|null}

Returns the first parent of a given element (by its identifier):

Parameters:
Name Type Description
elementId string

The identifier of the element whose parent we want to get.

Source:
Returns:

Returns null if the parent cannot be found.

Type
Node | null

<static> getParents(element) → {array}

Returns an array with the parents of a given element, with the topmost parent in the highest index:

Parameters:
Name Type Description
element Node

The element whose parents we want to get.

Source:
Returns:
Type
array

<static> getParentsById(elementId) → {array}

Returns an array with the parents of a given element (by its identifier), with the topmost parent in the highest index:

Parameters:
Name Type Description
elementId string

The identifier of the element whose parents we want to get.

Source:
Returns:
Type
array

<static> getScrollLeftById( [elementId] [, onScrollLeftChanges] [, fireFirstTime] [, fireAlways] [, timeoutMs] [, returnNullOnFail]) → {number|null}

Returns the horizontal scroll of a given element (by its identifier) and allows running a callback function (becoming recursive if desired). Any previous interval started by a previous call to this function, for the same "elementId", will be stopped.

Parameters:
Name Type Argument Default Description
elementId string | window <optional>
window

The identifier of the element whose horizontal scroll position we want to get. If a string with the identifier is not given, the unique value allowed is the window object (which is the default value when a non-valid value or no value is given).

onScrollLeftChanges CB_Elements.getScrollLeftById_getScrollTopById_ON_SCROLL_CHANGES <optional>

The desired callback function. It will be called as an interval if "timeoutMs" is a valid integer value.

fireFirstTime boolean <optional>
false

If it is set to true, it will call the callback function (if any) as soon as this function is called.

fireAlways boolean <optional>
false

If it is set to true, it will call the callback function (if any) every interval even if the horizontal scroll value has not changed from the last call.

timeoutMs integer <optional>

The number of milliseconds between one call to the callback function (if any) and the next one. If not given, it will not perform any interval.

returnNullOnFail function <optional>
false

If it is set to true, it will return null instead of zero (0) in the case that something goes wrong.

Source:
Returns:

Returns the horizontal scroll of the given element (by its identifier). It could return zero (0) if something fails (use "returnNullOnFail" set to true to return null when it fails).

Type
number | null

<static> getScrollTopById( [elementId] [, onScrollTopChanges] [, fireFirstTime] [, fireAlways] [, timeoutMs] [, returnNullOnFail]) → {number|null}

Returns the vertical scroll of a given element (by its identifier) and allows running a callback function (becoming recursive if desired). Any previous interval started by a previous call to this function, for the same "elementId", will be stopped.

Parameters:
Name Type Argument Default Description
elementId string | window <optional>
window

The identifier of the element whose vertical scroll position we want to get. If a string with the identifier is not given, the unique value allowed is the window object (which is the default value when a non-valid value or no value is given).

onScrollTopChanges CB_Elements.getScrollLeftById_getScrollTopById_ON_SCROLL_CHANGES <optional>

The desired callback function. It will be called as an interval if "timeoutMs" is a valid integer value.

fireFirstTime boolean <optional>
false

If it is set to true, it will call the callback function (if any) as soon as this function is called.

fireAlways boolean <optional>
false

If it is set to true, it will call the callback function (if any) every interval even if the vertical scroll value has not changed from the last call.

timeoutMs integer <optional>

The number of milliseconds between one call to the callback function (if any) and the next one. If not given, it will not perform any interval.

returnNullOnFail function <optional>
false

If it is set to true, it will return null instead of zero (0) in the case that something goes wrong.

Source:
Returns:

Returns the vertical scroll of the given element (by its identifier). It could return zero (0) if something fails (use "returnNullOnFail" set to true to return null when it fails).

Type
number | null

<static> getStyle(element [, computed]) → {Object|null}

Returns the style of an element, computed or static:

Parameters:
Name Type Argument Default Description
element Node

The element whose style property we want to get.

computed boolean <optional>
false

If it is set to true, it will try to use the native function window.getComputedStyle (if available).

Source:
Returns:

Returns an associative array (JavaScript object) with all the styles retrieved or null if nothing can be retrieved.

Type
Object | null

<static> getStyleById(elementId [, computed]) → {Object|null}

Returns the style of an element, computed or static (by its identifier):

Parameters:
Name Type Argument Default Description
elementId string

The identifier of the element whose style property we want to get.

computed boolean <optional>
false

If it is set to true, it will try to use the native function window.getComputedStyle (if available).

Source:
Returns:

Returns an associative array (JavaScript object) with all the styles retrieved or null if nothing can be retrieved.

Type
Object | null

<static> getStyleProperty(element, attribute [, computed]) → {*}

Returns the desired attribute value from the style of an element, computed or static:

Parameters:
Name Type Argument Default Description
element Node

The element whose attribute value from its style we want to get.

attribute string

The name of the attribute whose value we want to get from the style.

computed boolean <optional>
false

If it is set to true, it will try to use the native function window.getComputedStyle (if available).

Source:
To Do:
  • Think about supporting a boolean parameter to try to find the attribute having into account vendor prefixes (webkit, moz, ms, o, khtml).
Returns:

Returns null if nothing can be retrieved.

Type
*

<static> getStylePropertyById(elementId, attribute [, computed]) → {*}

Returns the desired attribute value from the style of an element, computed or static (by its identifier):

Parameters:
Name Type Argument Default Description
elementId string

The identifier of the element whose attribute value from its style we want to get.

attribute string

The name of the attribute whose value we want to get from the style.

computed boolean <optional>
false

If it is set to true, it will try to use the native function window.getComputedStyle (if available).

Source:
To Do:
  • Think about supporting a boolean parameter to try to find the attribute having into account vendor prefixes (webkit, moz, ms, o, khtml).
Returns:

Returns null if nothing can be retrieved.

Type
*

<static> getStylePropertyInteger(element, attribute [, computed]) → {array}

Returns the integer value or values (base decimal) of a desired attribute from the style of an element, computed or static:

Parameters:
Name Type Argument Default Description
element Node

The element whose attribute value from its style we want to get.

attribute string

The name of the attribute whose value we want to get from the style.

computed boolean <optional>
false

If it is set to true, it will try to use the native function window.getComputedStyle (if available).

Source:
To Do:
  • Think about supporting a boolean parameter to try to find the attribute having into account vendor prefixes (webkit, moz, ms, o, khtml).
Returns:

Returns a numeric array with the values retrieved. If nothing could be retrieved, the first and unique index of the array will contain the value of zero (0).

Type
array

<static> getStylePropertyIntegerById(elementId, attribute [, computed]) → {array}

Returns the integer value or values (base decimal) of a desired attribute from the style of an element, computed or static (by its identifier):

Parameters:
Name Type Argument Default Description
elementId string

The identifier of the element whose attribute value from its style we want to get.

attribute string

The name of the attribute whose value we want to get from the style.

computed boolean <optional>
false

If it is set to true, it will try to use the native function window.getComputedStyle (if available).

Source:
To Do:
  • Think about supporting a boolean parameter to try to find the attribute having into account vendor prefixes (webkit, moz, ms, o, khtml).
Returns:

Returns a numeric array with the values retrieved. If nothing could be retrieved, the first and unique index of the array will contain the value of zero (0).

Type
array

<static> getStylePropertyNumeric(element, attribute [, computed] [, parseToInteger]) → {array}

Returns the numeric value or values (base decimal) of a desired attribute from the style of an element, computed or static:

Parameters:
Name Type Argument Default Description
element Node

The element whose attribute value from its style we want to get.

attribute string

The name of the attribute whose value we want to get from the style.

computed boolean <optional>
false

If it is set to true, it will try to use the native function window.getComputedStyle (if available).

parseToInteger boolean <optional>
false

If it is set to true, the value or values will be parsed to integer.

Source:
To Do:
  • Think about supporting a boolean parameter to try to find the attribute having into account vendor prefixes (webkit, moz, ms, o, khtml).
Returns:

Returns a numeric array with the values retrieved. If nothing could be retrieved, the first and unique index of the array will contain the value of zero (0).

Type
array

<static> getStylePropertyNumericById(elementId, attribute [, computed] [, parseToInteger]) → {array}

Returns the numeric value or values (base decimal) of a desired attribute from the style of an element, computed or static (by its identifier):

Parameters:
Name Type Argument Default Description
elementId string

The identifier of the element whose attribute value from its style we want to get.

attribute string

The name of the attribute whose value we want to get from the style.

computed boolean <optional>
false

If it is set to true, it will try to use the native function window.getComputedStyle (if available).

parseToInteger boolean <optional>
false

If it is set to true, the value or values will be parsed to integer.

Source:
To Do:
  • Think about supporting a boolean parameter to try to find the attribute having into account vendor prefixes (webkit, moz, ms, o, khtml).
Returns:

Returns a numeric array with the values retrieved. If nothing could be retrieved, the first and unique index of the array will contain the value of zero (0).

Type
array

<static> getTop(element [, ignoreScroll] [, returnNullOnFail] [, computed]) → {*}

Returns the top position of an element (having in mind getBoundingClientRect if available, its parents, etc.).

Parameters:
Name Type Argument Default Description
element Node

The element whose data we are interested in.

ignoreScroll boolean <optional>
true

If it is set to false, it will have in mind the current scroll position to calculate the result.

returnNullOnFail function <optional>
false

If it is set to true, it will return null instead of zero (0) in the case that something goes wrong.

computed boolean <optional>
false

This parameter will be used when it calls CB_Elements.getStyleProperty and CB_Elements.getStylePropertyInteger internally.

Source:
Returns:

It could return zero (0) or even a non-numeric value if something fails (use "returnNullOnFail" set to true to return null when it fails).

Type
*

<static> getTopById(elementId [, ignoreScroll] [, returnNullOnFail] [, computed]) → {*}

Returns the top position of an element (having in mind getBoundingClientRect if available, its parents, etc.), by its identifier.

Parameters:
Name Type Argument Default Description
elementId string

The identifier of the element whose data we are interested in.

ignoreScroll boolean <optional>
true

If it is set to false, it will have in mind the current scroll position to calculate the result.

returnNullOnFail function <optional>
false

If it is set to true, it will return null instead of zero (0) in the case that something goes wrong.

computed boolean <optional>
false

This parameter will be used when it calls CB_Elements.getStyleProperty and CB_Elements.getStylePropertyInteger internally.

Source:
Returns:

It could return zero (0) or even a non-numeric value if something fails (use "returnNullOnFail" set to true to return null when it fails).

Type
*

<static> getWidth(element [, returnNullOnFail] [, computed]) → {*}

Returns the width of an element (having in mind its border).

Parameters:
Name Type Argument Default Description
element Node

The element whose data we are interested in.

returnNullOnFail function <optional>
false

If it is set to true, it will return null instead of zero (0) in the case that something goes wrong.

computed boolean <optional>
false

This parameter will be used when it calls CB_Elements.getStylePropertyInteger internally.

Source:
Returns:

It could return zero (0) or even a non-numeric value if something fails (use "returnNullOnFail" set to true to return null when it fails).

Type
*

<static> getWidthById(elementId [, returnNullOnFail] [, computed]) → {*}

Returns the width of an element (having in mind its border), by its identifier.

Parameters:
Name Type Argument Default Description
elementId string

The identifier of the element whose data we are interested in.

returnNullOnFail function <optional>
false

If it is set to true, it will return null instead of zero (0) in the case that something goes wrong.

computed boolean <optional>
false

This parameter will be used when it calls CB_Elements.getStylePropertyInteger internally.

Source:
Returns:

It could return zero (0) or even a non-numeric value if something fails (use "returnNullOnFail" set to true to return null when it fails).

Type
*

<static> hide(element [, checkValues] [, computed] [, onHide]) → {Node}

Hides a given element by changing its display property to "none" and its visibility to "hidden".

Parameters:
Name Type Argument Default Description
element Node

The element that we want to hide.

checkValues boolean <optional>
false

If it is set to true, it will only perform the change if either the current visibility property is not "hidden" or the current display property is not "none".

computed boolean <optional>
false

This parameter will be used when it calls CB_Elements.getStyle internally.

onHide function <optional>

Callback function that will be called if the element has been hidden, after doing it (this will happens always if "checkValues" is false). The first parameter passed will be the affected element itself and the second and last parameter will be the new value of the display property (not computed) which should be "none".

Source:
Returns:

Returns the given element again.

Type
Node

<static> hideById(elementId [, checkValues] [, computed] [, onHide]) → {Node|null}

Hides a given element by changing its display property to "none" and its visibility to "hidden" (by its identifier).

Parameters:
Name Type Argument Default Description
elementId string

The identifier of the element that we want to hide.

checkValues boolean <optional>
false

If it is set to true, it will only perform the change if either the current visibility property is not "hidden" or the current display property is not "none".

computed boolean <optional>
false

This parameter will be used when it calls CB_Elements.getStyle internally.

onHide function <optional>

Callback function that will be called if the element has been hidden, after doing it (this will happens always if "checkValues" is false). The first parameter passed will be the affected element itself and the second and last parameter will be the new value of the display property (not computed) which should be "none".

Source:
Returns:

Returns the affected element (if any) or null otherwise.

Type
Node | null

<static> id(id [, useCache]) → {Node|Object|null}

Returns an element by its ID.

Parameters:
Name Type Argument Default Description
id string

The identifier of the element that we want to find.

useCache boolean <optional>
CB_Configuration.CrossBase.CB_Elements_id_USE_CACHE

Defines whether to try to get the result from an internal cache (it will exist if we previously called the function with the same parameters) or not. The internal cache will be updated when this parameter is set to false or it will be created automatically when it did not exist before.

Source:
Returns:

Returns the elements (Node or object, depending on the web client). It will return null when not found.

Type
Node | Object | null

<static> idCacheClear( [id]) → {Object}

Clears the internal cache used by CB_Elements.id and others. If no parameter is given, whole internal cache will be cleared.

Parameters:
Name Type Argument Description
id string <optional>

The identifier of the element whose internal cache we want to clear. If not provided, it will clear the whole internal cache.

Source:
Returns:

Returns the current internal cache after cleaning it (if it is has been possible), which is an associative array of one dimension (JavaScript object) whose first and unique index belongs to the identifier and the value belongs to each element.

Type
Object

<static> idCacheUpdate(id) → {node|Object|null}

Returns an element by its ID, updating (or creating) the internal cache. Calls the CB_Elements.id function internally, with the "useCache" parameter set to false.

Parameters:
Name Type Description
id string

The identifier of the element that we want to find.

Source:
Returns:

Returns the elements (Node or object, depending on the web client). It will return null when not found.

Type
node | Object | null

<static> idRemove(id [, useCache])

Removes an element by its ID.

Parameters:
Name Type Argument Default Description
id string

The identifier of the element that we want to delete.

useCache boolean <optional>
CB_Configuration.CrossBase.CB_Elements_id_USE_CACHE

Defines whether to try to get the result from an internal cache (it will exist if we previously called the function with the same parameters) or not. The internal cache will be updated when this parameter is set to false or it will be created automatically when it did not exist before.

Source:

<static> insertContent(container, content [, displayValue] [, checkValues] [, computed] [, onContentWritten] [, onShow] [, append] [, appendAtBeginning]) → {Node}

Inserts the desired content inside a given element (using innerHTML).

Parameters:
Name Type Argument Default Description
container Node

The element whose content we want to modify.

content string

The content that we want to add.

displayValue string <optional>

If provided, it will call CB_Elements.show internally after inserting the content to set the given display property to the element.

checkValues boolean <optional>
false

If it is set to true, it will only change the content if the current one is different from the given one and it will pass the same parameter to CB_Elements.show if it is called internally (when "displayValue" is given).

computed boolean <optional>
false

If "displayValue" is given, it will pass this parameter to CB_Elements.show if it is called internally (when "displayValue" is given).

onContentWritten function <optional>

Callback function that will be called if the content has been written, after doing it (this will happens always if "checkValues" is false). The unique parameter passed will be the container itself.

onShow function <optional>

If "displayValue" is given, it will pass this parameter to CB_Elements.show when it is called internally.

append boolean <optional>
false

If set to true, it will append the given content to the existing one instead of overwritten it. By default, it appends it at the end unless that the "appendAtBeginning" is set to true.

appendAtBeginning boolean <optional>
false

If set to true, it will append the given content to the existing one instead of overwritten it.

Source:
Returns:

Returns the given container again.

Type
Node

<static> insertContentById(containerId, content [, displayValue] [, checkValues] [, computed] [, onContentWritten] [, onShow] [, append] [, appendAtBeginning]) → {Node|null}

Inserts the desired content inside a given element (using innerHTML), by its identifier.

Parameters:
Name Type Argument Default Description
containerId string

The identifier of the element whose content we want to modify.

content string

The content that we want to add.

displayValue string <optional>

If provided, it will call CB_Elements.show internally after inserting the content to set the given display property to the element.

checkValues boolean <optional>
false

If it is set to true, it will only change the content if the current one is different from the given one and it will pass the same parameter to CB_Elements.show if it is called internally (when "displayValue" is given).

computed boolean <optional>
false

If "displayValue" is given, it will pass this parameter to CB_Elements.show if it is called internally (when "displayValue" is given).

onContentWritten function <optional>

Callback function that will be called if the content has been written, after doing it (this will happens always if "checkValues" is false). The unique parameter passed will be the affected container itself.

onShow function <optional>

If "displayValue" is given, it will pass this parameter to CB_Elements.show when it is called internally.

append boolean <optional>
false

If set to true, it will append the given content to the existing one instead of overwritten it. By default, it appends it at the end unless that the "appendAtBeginning" is set to true.

appendAtBeginning boolean <optional>
false

If set to true, it will append the given content to the existing one instead of overwritten it.

Source:
Returns:

Returns the affected container (if any) or null otherwise.

Type
Node | null

<static> preventSelection(element [, avoidSelection]) → {Node|null}

Prevents or allows the possibility of selecting the content of a given element (makes it unselectable).

Parameters:
Name Type Argument Default Description
element Node

The element which we want to affect.

avoidSelection boolean <optional>
true

If set to false, it will allow selecting the content. Otherwise, it will prevent it to be selected.

Source:
Returns:

Returns the given element again or null.

Type
Node | null

<static> preventSelectionById(elementId [, avoidSelection]) → {Node|null}

Prevents or allows the possibility of selecting the content of a given element (makes it unselectable), by its ID.

Parameters:
Name Type Argument Default Description
elementId string

The identifier of the element which we want to affect.

avoidSelection boolean <optional>
true

If set to false, it will allow selecting the content. Otherwise, it will prevent it to be selected.

Source:
Returns:

Returns the affected element (if any) or null otherwise.

Type
Node | null

<static> remove(element)

Removes an element given.

Parameters:
Name Type Description
element Node

The element that we want to delete.

Source:

<static> removeByClasses()

Source:
See:

<static> removeById()

Source:
See:

<static> removeByTagName()

Source:
See:

<static> removeClass(element, className [, checkValues] [, onRemoveClass]) → {Node}

Removes a desired class from a given element. The element can contain other classes and they will be kept.

Parameters:
Name Type Argument Default Description
element Node

The element whose class we want to remove.

className string

The class that will be removed if the element is using it.

checkValues boolean <optional>
false

If it is set to true, it will only try to perform the action if the given "className" is being used. The result will be the same with either true or false, but depending on the client used it could gain or lose performance.

onRemoveClass function <optional>

Callback function that will be called if the class of the element has been tried to be removed, after doing it (this will happens always if "checkValues" is false). The first and unique parameter passed will be the affected element itself.

Source:
To Do:
  • Think about allowing to remove more than once class at the same time, regardless of the order given and order set.
Returns:

Returns the given element again.

Type
Node

<static> removeClassById(elementId, className [, checkValues] [, onRemoveClass]) → {Node|null}

Removes a desired class from a given element (by its identifier). The element can contain other classes and they will be kept.

Parameters:
Name Type Argument Default Description
elementId string

The identifier of the element whose class we want to remove.

className string

The class that will be removed if the element is using it.

checkValues boolean <optional>
false

If it is set to true, it will only try to perform the action if the given "className" is being used. The result will be the same with either true or false, but depending on the client used it could gain or lose performance.

onRemoveClass function <optional>

Callback function that will be called if the class of the element has been tried to be removed, after doing it (this will happens always if "checkValues" is false). The first and unique parameter passed will be the affected element itself.

Source:
To Do:
  • Think about allowing to remove more than once class at the same time, regardless of the order given and order set.
Returns:

Returns the affected element (if any) or null otherwise.

Type
Node | null

<static> setClass(element, classNames [, checkValues] [, onSetClass]) → {Node}

Sets a desired class or classes to a given element. All previous classes (if any) will be replaced by the new one or new ones.

Parameters:
Name Type Argument Default Description
element Node

The element that will get the new given class or classes.

classNames string

The class or classes that will be set. More than one class can be given (separated by blank spaces).

checkValues boolean <optional>
false

If it is set to true, it will only try to set the given class or classes if they are not being used already.

onSetClass function <optional>

Callback function that will be called if the class or classes of the element have been set, after doing it (this will happens always if "checkValues" is false). The first and unique parameter passed will be the affected element itself.

Source:
Returns:

Returns the given element again.

Type
Node

<static> setClassById(elementId, classNames [, checkValues] [, onSetClass]) → {Node|null}

Sets a desired class or classes to a given element (by its identifier). All previous classes (if any) will be replaced by the new one or new ones.

Parameters:
Name Type Argument Default Description
elementId string

The identifier of the element that will get the new given class or classes.

classNames string

The class or classes that will be set. More than one class can be given (separated by blank spaces).

checkValues boolean <optional>
false

If it is set to true, it will only try to set the given class or classes if they are not being used already.

onSetClass function <optional>

Callback function that will be called if the class or classes of the element have been set, after doing it (this will happens always if "checkValues" is false). The first and unique parameter passed will be the affected element itself.

Source:
Returns:

Returns the affected element (if any) or null otherwise.

Type
Node | null

<static> setProperty(element, property, propertyValue [, checkValues] [, onSetProperty]) → {Node|null}

Changes a desired element property with the given value.

Parameters:
Name Type Argument Default Description
element Node

The element whose property we want to modify.

property string

The name of the property that we want to modify.

propertyValue *

The value desired for the property.

checkValues boolean <optional>
false

If set to true, it will only modify the property if the current value is different from the given one.

onSetProperty function <optional>

Callback function that will be called if the property of the element has been set, after doing it (this will happens always if "checkValues" is false). The first and unique parameter passed will be the affected element itself.

Source:
Returns:

Returns the given element again or null.

Type
Node | null

<static> setPropertyById(elementId, property, propertyValue [, checkValues] [, onSetProperty]) → {Node|null}

Changes a desired element property with the given value (by its identifier).

Parameters:
Name Type Argument Default Description
elementId string

The identifier of the element whose property we want to modify.

property string

The name of the property that we want to modify.

propertyValue *

The value desired for the property.

checkValues boolean <optional>
false

If set to true, it will only modify the property if the current value is different from the given one.

onSetProperty function <optional>

Callback function that will be called if the property of the element has been set, after doing it (this will happens always if "checkValues" is false). The first and unique parameter passed will be the affected element itself.

Source:
Returns:

Returns the affected element (if any) or null otherwise.

Type
Node | null

<static> show(element [, displayValue] [, checkValues] [, computed] [, onShow]) → {Node}

Changes the display property to the desired value of a given element, to show it. Its visibility property will be set to "visible".

Parameters:
Name Type Argument Default Description
element Node

The element whose display property we want to change.

displayValue string <optional>
'block'

The display value we want to set. If not provided or "none" is provided, it will use "block" instead.

checkValues boolean <optional>
false

If it is set to true, it will only perform the change if either the current visibility property is not "visible" or the current display property is different from the given one.

computed boolean <optional>
false

This parameter will be used when it calls CB_Elements.getStyle internally.

onShow function <optional>

Callback function that will be called if the change has been performed, after doing it (this will happens always if "checkValues" is false). The first parameter passed will be the affected element itself and the second and last parameter will be the new value of the display property (not computed).

Source:
Returns:

Returns the given element again.

Type
Node

<static> showById(elementId [, displayValue] [, checkValues] [, computed] [, onShow]) → {Node|null}

Changes the display property to the desired value of a given element, to show it (by its identifier). Its visibility property will be set to "visible".

Parameters:
Name Type Argument Default Description
elementId string

The identifier of the element whose display property we want to change.

displayValue string <optional>
'block'

The display value we want to set. If not provided or "none" is provided, it will use "block" instead.

checkValues boolean <optional>
false

If it is set to true, it will only perform the change if either the current visibility property is not "visible" or the current display property is different from the given one.

computed boolean <optional>
false

This parameter will be used when it calls CB_Elements.getStyle internally.

onShow function <optional>

Callback function that will be called if the change has been performed, after doing it (this will happens always if "checkValues" is false). The first parameter passed will be the affected element itself and the second and last parameter will be the new value of the display property (not computed).

Source:
Returns:

Returns the affected element (if any) or null otherwise.

Type
Node | null

<static> showHide(element [, displayValue] [, checkValues] [, computed] [, onToggleDisplay] [, onShow] [, onHide]) → {Node}

Toggles the display property (from "none" to the desired value or vice versa) of a given element, to show or hide it.
If the element is hidden (its display is "none"), it will call CB_Elements.show internally to show it. Otherwise, it will call CB_Elements.hide internally. Note that these two functions will also change the visibility property (setting it to either "visible" or "hidden", respectively) of the element.

Parameters:
Name Type Argument Default Description
element Node

The element whose display property we want to toggle.

displayValue string <optional>
'block'

The display value when we want to show the element (it will be used only if the element is currently hidden, when it calls CB_Elements.show internally). The display value to hide the element is always "none".

checkValues boolean <optional>
false

This parameter will be used when it calls either CB_Elements.show or CB_Elements.hide internally.

computed boolean <optional>
false

This parameter will be used to get the current style and also when it calls either CB_Elements.show or CB_Elements.hide internally.

onToggleDisplay function <optional>

This parameter will be used when it calls either CB_Elements.show if "onShow" is not provided or CB_Elements.hide if "onHide" is not provided, internally.

onShow function <optional>

This parameter will be used when it calls CB_Elements.show internally. If not provided but "onToggleDisplay" is provided, it will use the latter instead.

onHide function <optional>

This parameter will be used when it calls CB_Elements.hide internally. If not provided but "onToggleDisplay" is provided, it will use the latter instead.

Source:
Returns:

Returns the given element again.

Type
Node

<static> showHideById(elementId [, displayValue] [, checkValues] [, computed] [, onToggleDisplay] [, onShow] [, onHide]) → {Node|null}

Toggles the display property (from "none" to the desired value or vice versa) of a given element, to show or hide it (by its identifier).
If the element is hidden (its display is "none"), it will call CB_Elements.show internally to show it. Otherwise, it will call CB_Elements.hide internally. Note that these two functions will also change the visibility property (setting it to either "visible" or "hidden", respectively) of the element.

Parameters:
Name Type Argument Default Description
elementId string

The identifier of the element whose display property we want to toggle.

displayValue string <optional>
'block'

The display value when we want to show the element (it will be used only if the element is currently hidden, when it calls CB_Elements.show internally). The display value to hide the element is always "none".

checkValues boolean <optional>
false

This parameter will be used when it calls either CB_Elements.show or CB_Elements.hide internally.

computed boolean <optional>
false

This parameter will be used to get the current style and also when it calls either CB_Elements.show or CB_Elements.hide internally.

onToggleDisplay function <optional>

This parameter will be used when it calls either CB_Elements.show if "onShow" is not provided or CB_Elements.hide if "onHide" is not provided, internally.

onShow function <optional>

This parameter will be used when it calls CB_Elements.show internally. If not provided but "onToggleDisplay" is provided, it will use the latter instead.

onHide function <optional>

This parameter will be used when it calls CB_Elements.hide internally. If not provided but "onToggleDisplay" is provided, it will use the latter instead.

Source:
Returns:

Returns the affected element (if any) or null otherwise.

Type
Node | null

<static> tag( [tagName] [, baseElement] [, useCache]) → {NodeList|array}

Returns elements by their tag name.

Parameters:
Name Type Argument Default Description
tagName string <optional>
'*'

The name of the tag whose elements we want to find. Use asterisk ("*") in the case that we want all the elements.

baseElement Node <optional>
document

The node element parent where we want to focus our search.

useCache boolean <optional>
CB_Configuration.CrossBase.CB_Elements_tag_USE_CACHE

Defines whether to try to get the result from an internal cache (it will exist if we previously called the function with the same parameters) or not. The internal cache will be updated when this parameter is set to false or it will be created automatically when it did not exist before.

Source:
Returns:

Returns the elements (NodeList or array, depending on the web client).

Type
NodeList | array

<static> tagCacheClear( [tagName] [, baseElement]) → {Object}

Clears the internal cache user by CB_Elements.tag and others. If no parameter is given, whole internal cache will be cleared.

Parameters:
Name Type Argument Description
tagName string <optional>

The name of the tag whose internal cache we want to clear. Use asterisk ("*") in the case that we want to clear the internal cache for CB_Elements.tag which is used when it is called with this exact parameter. If not provided, it will clear the whole internal cache or the internal cache that belongs to the "baseElement" given (if provided).

baseElement Node <optional>

The node element parent whose internal cache we want to clear. If not provided but "tagName" is provided, it will clear the internal cache which matches the given "tagName" for any nodes. If it is provided but "tagName" is not, it will clear all the internal cache that belongs to this node element.

Source:
Returns:

Returns the current internal cache after clearing it (if it is has been possible), which is an associative array of two dimensions (JavaScript object) whose first index belongs to the nodes, the second and last index belongs to the tag name and the value belongs to the returning value of the CB_Elements.tag function when it was called for those parameters.

Type
Object

<static> tagCacheUpdate( [tagName] [, baseElement]) → {NodeList|array}

Returns elements by their tag name, updating (or creating) the internal cache. Calls the CB_Elements.tag function internally, with the "useCache" parameter set to false.

Parameters:
Name Type Argument Default Description
tagName string <optional>
'*'

The name of the tag whose elements we want to find. Use asterisk ("*") in the case that we want all the elements.

baseElement Node <optional>
document

The node element parent where we want to focus our search.

Source:
Returns:

Returns the elements (NodeList or array, depending on the web client).

Type
NodeList | array

<static> tagRemove( [tagName] [, baseElement] [, useCache])

Removes elements by their tag name.

Parameters:
Name Type Argument Default Description
tagName string <optional>
'*'

The name of the tag whose elements we want to delete. Use asterisk ("*") in the case that we want all the elements.

baseElement Node <optional>
document

The node element parent where we want to focus our search.

useCache boolean <optional>
CB_Configuration.CrossBase.CB_Elements_tag_USE_CACHE

Defines whether to try to get the result from an internal cache (it will exist if we previously called the function with the same parameters) or not. The internal cache will be updated when this parameter is set to false or it will be created automatically when it did not exist before.

Source:

<static> toggleClass(element, classA [, classB] [, onToggleClass]) → {Node}

Toggles the class of a given element between two given classes or adds/removes the given class. The element can contain other classes and they will be kept.

Parameters:
Name Type Argument Default Description
element Node

The element whose class we want to toggle.

classA string

The class that will be used in the case that the element is not using it already.

classB string <optional>
''

The class that will be used in the case that the given "classA" is being used by the element. If not given or an empty string is given, it will just remove the "classA" in the case it is being used by the element.

onToggleClass function <optional>

Callback function that will be called if the class of the element has been toggled or removed, after doing it. The first parameter passed will be the affected element itself and the second and last parameter will be the class used this time (or an empty string).

Source:
Returns:

Returns the given element again.

Type
Node

<static> toggleClassById(elementId, classA [, classB] [, onToggleClass]) → {Node|null}

Toggles the class of a given element between two given classes (by its identifier). The element can contain other classes and they will be kept.

Parameters:
Name Type Argument Default Description
elementId string

The identifier of the element whose class we want to toggle.

classA string

The class that will be used in the case that the element is not using it already.

classB string <optional>
''

The class that will be used in the case that the given "classA" is being used by the element. If not given or an empty string is given, it will just remove the "classA" in the case it is being used by the element.

onToggleClass function <optional>

Callback function that will be called if the class of the element has been toggled or removed, after doing it. The first parameter passed will be the affected element itself and the second and last parameter will be the class used this time (or an empty string).

Source:
Returns:

Returns the affected element (if any) or null otherwise.

Type
Node | null

Type Definitions


getScrollLeftById_getScrollTopById_ON_SCROLL_CHANGES(scrollLeftOrTop, scrollLeftOrTopPrevious, scrollWidthOrHeight, clientWidthOrHeight, scrollLeftOrTopRelative, scrollLeftOrTopRelativePrevious)

Callback that is used as the "onScrollLeftChanges" parameter for the CB_Elements.getScrollLeftById function or as the "onScrollTopChanges" parameter for the CB_Elements.getScrollTopById function. All values received should be checked since some could be not numbers.

Parameters:
Name Type Description
scrollLeftOrTop *

The scroll left or scroll top position.

scrollLeftOrTopPrevious *

The previous scroll left or scroll top position.

scrollWidthOrHeight *

The scroll width or scroll height.

clientWidthOrHeight *

The client width or client height (element.clientWidth/element.offsetWidth or element.clientHeight/element.offsetHeight, depending on the web client).

scrollLeftOrTopRelative *

The relative scroll left or scroll top position.

scrollLeftOrTopRelativePrevious *

The previous relative scroll left or scroll top position.

Source: