Class clove::utils

class clove::utils

Namespace for some utilities.

Public Functions

main_parts_resized(reason)

Call this method if resizing is required due to external situations.

It is not required to call this method in typical situations. A situation which requires this method is changing the stylesheets from outside.

Parameters
  • reason: Optional arbitrary object which describes the reason for resizing. Can be evaluated by handlers in a custom way.

applyDefaultsToConfig(config, defaults)

Returns a copy of config with the additional members from defaults, whereever there was no value in config.

Parameters
  • config: The source object.

  • defaults: Default values for members to apply to the result whereever they are missing.

addOnDestroyHandler(domnode, handler)

Listen for the removal of a node in the dom tree and eventually execute a handler function.

Parameters
  • domnode: The node in the dom tree to observe.

  • handler: The function to execute on removal of domnode.

addOnDragHandler(domnode, dragbeginhandler, draghandler, dragendhandler)

Listen for a drag event of a node and eventually execute handler functions.

A drag consists of mouse/finger down, moving and releasing.

Parameters
  • domnode: The node in the dom tree to observe.

  • dragbeginhandler: The function to execute when a drag operation begins.

  • draghandler: The function to execute while moving (with relative coordinates as parameters).

  • dragendhandler: The function to execute when a drag operation ends.

addOnDoubleClickTapHandler(domnode, handler)

Listen for double click/tap event of a node and eventually execute a handler function.

This is like a pure double click event, but also supports touch.

See also clove::utils::removeOnDoubleClickTapHandler().

Parameters
  • domnode: The node in the dom tree to observe.

  • handler: The function to execute on double click/tap.

removeOnDoubleClickTapHandler(domnode, handler)

Remove a double click/tap event handler.

Parameters
  • domnode: The node in the dom tree to remove a handler from.

  • handler: The function to remove.

arraysum(x)

Computes the sum of all elements in an Array.

Parameters
  • x: The Array to sum up.

findWidgetForDomNode(node)

Finds the (most inner) clove::Widget a given dom node contains to.

Parameters
  • node: The dom node.

getExtraSize(node, withMargin)

Computes the extra size of a dom node.

This is the difference between inner size and the outer size (i.e. borders, padding, …).

Parameters
  • node: The dom node to measure.

  • withMargin: If to include margins.

getInnerSize(node)

Computes the inner size of a dom node.

This is the size without borders, padding, …

Parameters
  • node: The dom node to measure.

getOuterSize(node, withMargin)

Computes the outer size of a dom node.

This is the size including borders, padding, …

Parameters
  • node: The dom node to measure.

  • withMargin: If to include margins.

suspendResizing()

Temporarily suspends all user interface resizing.

This is useful for performance reasons during intensive changes to the user interface.

Use this with caution and always call clove::utils::resumeResizing afterwards.

Return

A token object used for resuming later on.

resumeResizing(token)

Resumes the user interface resizing after it was suspended with clove::utils::suspendResizing.

It automatically takes care of resizing everything which diverged meanwhile.

Parameters
  • token: The token object.

cssLengthToPixels(v, axis)

Translates a css length specification string to a numeric pixel value.

Note: This does not make sense for all kinds of lengths, e.g. percentages will not work.

Parameters
  • v: The css length.

  • axis: The axis (‘x’ or ‘y’).

insertToArray(array, i, v)

Inserts a value into an array.

Parameters
  • array: The array.

  • i: The position.

  • v: The new value to insert.

popup(config, showconfig)

Shows a popup.

This can show an arbitrary widget decoupled from the main user interface (swimming above it).

This call retuns a dialog result structure, containing the following:

  • widget: The popup widget as clove::Widget.

  • namescope: The root namescope for the popup as clove::NameScope.

    Parameters
    • config: The widget configuration, as for clove::build(), which specifies the popup.

    • showconfig: A configuration object which specifies some presentation aspects.

isDescendantOf(d, p)

Checks if d is a descendant of p in the html dom node.

Parameters
  • d: An html dom node.

  • p: An html dom node.

arrayToDatasource(array)

Builds a clove::Datasource containing the same content as the input array.

Parameters
  • array: The input array.

connectDatasourceToWidget(widget, datasource, dspropname, rootptrpropname, inserthandlername, removehandlername, updatehandlername, afterdisconnectedfct, beforeconnectedfct, afterconnectedfct)

Connects a clove::Datasource to an internal widget interface (also removes the old connection).

Connects a datasource to a widget.

This method is solely used by the inner implementation of a widget for using a datasource. It is not useful to call it in any other situation!

Used internally in widget implementations.

Parameters
  • widget: A clove::Widget.

  • datasource: A clove::Datasource.

  • dspropname: The property name for storing the current datasource in the widget.

  • rootptrpropname: The property name to get the root clove::DatasourceValuePointer from the widget.

  • inserthandlername: The name of the widget’s insert handler method.

  • removehandlername: The name of the widget’s remove handler method.

  • updatehandlername: The name of the widget’s update handler method.

  • afterdisconnectedfct: Optional function called just after disconnection of the old datasource.

  • beforeconnectedfct: Optional function called just before connecting the new datasource.

  • afterconnectedfct: Optional function called just after connecting the new datasource.

Parameters
  • widget: The clove::Widget.

  • datasource: The clove::Datasource to connect.

  • dspropname: The name of the datasource property.

  • rootptrpropname: The name of the root value pointer property.

  • inserthandlername: The name of the insert handler.

  • removehandlername: The name of the remove handler.

  • updatehandlername: The name of the update handler.

  • afterdisconnectedfct: This function is called after the last datasource is disconnected.

  • beforeconnectedfct: This function is called just before the datasource is connected.

  • afterconnectedfct: This function is called right after the datasource is connected.

animateNode(node, animationname, animationduration, animationendedfct)

Plays a css animation on a html dom node for one iteration and fires a callback afterwards.

Parameters
  • node: The html dom node to animate.

  • animationname: The css animation name.

  • animationduration: The animation duration in milliseconds.

  • animationendedfct: a callback function() called when the animation ends.

setStyleClassAssigned(node, clss, assigned)

Sets or unsets a css class to an html dom node.

Parameters
  • node: The html dom node to modify.

  • clss: The css class name.

  • assigned: If to assign or unassign it.

deferLoading(eload)

Defers loading of Clove by an event.

Used only internally and in exotic situations.

Call this before loading is finished (i.e. typically while the document itself loads) and before the eload event triggers (i.e. not when it already might have triggered).

See also runOnLoaded().

Parameters
  • eload: The clove::Event object which is triggered when it’s ready for continue loading.

runOnLoaded(fct)

Runs a function as soon as possible, but not before Clove has finished loading.

Used only internally and in exotic situations. One would typically use clove::populateUI() instead.

Parameters
  • fct: The function() to execute when Clove is loaded.

getFullPathForLoadedResource(tgtname, elementtype, elementsrcattrname)

Returns the full path for an already loaded script or stylesheet with known file name.

Used only internally and in exotic situations.

Parameters
  • tgtname: The complete file name (bare; without slashes) of the file to search for.

  • elementtype: Optional element type (default: "script").

  • elementsrcattrname: Optional element type’s attribute name for the source url (if type is not "script" or "style").

tryLoadScript(scriptpath, config)

Tries to load another javascript.

If it succeeds, it returns the url of it.

config may contain:

  • rootrefscript: For relative script paths, this reference script is used in order to determine the base directory.

  • onload: A function() to execute when the script is loaded.

    Parameters
    • scriptpath: The path to the javascript file.

    • config: A (optional) configuration object.

tryLoadStyle(stylepath, config)

Tries to load a css stylesheet.

If it succeeds, it returns the url of it.

config may contain:

  • rootrefscript: For relative style paths, this reference script is used in order to determine the base directory.

  • onload: A function() to execute when the stylesheet is loaded.

    Parameters
    • stylepath: The path to the css stylesheet file.

    • config: A (optional) configuration object.

OnMainResized

Triggered when the main view resized.

This is a clove.Event instance. See Manual for details.