Defines static class UFNode, an utilities library with static methods to work with HTML Nodes.

Constructors

Methods

  • Adds css classes to a node, its siblings and the siblings of all parents but not the parents itself.

    Parameters

    • node: Node

      Node to add class to

    • cssClass: string

      Class to add

    • oneSelf: boolean

      True to add class to oneself also.

    • skipEmpty: boolean

      True to skip empty text nodes

    • OptionalbackupList: UFNodeBackup[]

      Optional backup list

    Returns void

  • Recursively adds css classes to a nodes children (and grandchildren). If the child node is a text node, it will get replaced by a wrapping span node with the specified class.

    If backupList is set, the method will store the original text node and newly created wrapper nodes in the list. Use restoreNodes to restore the original nodes.

    Parameters

    • parentNode: Node

      Node to process its children of

    • cssClasses: string

      Css classes to add

    • skipEmpty: boolean

      True to skip empty text nodes

    • OptionalbackupList: UFNodeBackup[]

      Optional backup list

    Returns void

  • Adds style rule to class attribute. If the node is a text node, it will be wrapped by a span using wrapTextNode.

    If backupList is set, the method will store the original text node and newly created wrapper node in the list. Use restoreNodes to restore the original nodes.

    Parameters

    • node: Node

      Node to add class to

    • cssClasses: string

      Css classes to add

    • skipEmpty: boolean

      True to skip empty text nodes

    • OptionalbackupList: UFNodeBackup[]

      Optional backup list

    Returns Node

    node or the new wrapping span node

  • Add css classes to a node and next siblings.

    Parameters

    • node: Node

      Node to start with

    • cssClasses: string

      Css classes to add

    • oneSelf: boolean

      When true add class to node, else skip oneself.

    • skipEmpty: boolean

      True to skip empty text nodes

    • OptionalbackupList: UFNodeBackup[]

      Optional backup list

    Returns void

  • Gets the index of a node inside the parent node.

    Parameters

    • parentNode: Node

      Parent node

    • childNode: Node

      Node to get index of

    Returns number

    index or -1 if not found

  • Gets the index of a node within its parent.

    Parameters

    • node: Node

      Node to check

    Returns number

    index

  • Gets the position inside an element for a specific location.

    Code based on: https://github.com/timdown/rangy/blob/master/src/modules/inactive/rangy-position.js

    The function returns an object with the following properties:

    • offset: position within the text of the found element
    • node: dom node the position is pointing to

    Parameters

    • document: Document

      Document of contents

    • x: number

      X position in screen

    • y: number

      Y position in screen

    • usePrecedingPosition: boolean

      When true select element before else select element after if position is in between two elements.

    Returns null | { node: Node; offset: number }

    An object with two properties or null if no element could be found at the location.

  • Removes a css class from a node, its siblings and the siblings of all parents but not the parents itself.

    Parameters

    • node: Node

      Node to remove class from

    • cssClass: string

      class to remove

    • oneSelf: boolean

      True to remove class from oneself also.

    Returns void

  • Removes a css class from a node, its siblings and the siblings of all parents but not the parents itself.

    Parameters

    • node: Node

      Node to remove class from

    • cssClass: string

      Css class to remove

    • oneSelf: boolean

      True to remove class from oneself also.

    Returns void

  • Recursively removes css class from a nodes children (and grandchildren).

    Parameters

    • parentNode: Node

      Node to start with

    • cssClass: string

      Class to remove

    Returns void

  • Remove a css class from a node and next siblings.

    Parameters

    • node: Node

      Node to start with

    • cssClass: string

      Css class to remove

    • oneSelf: boolean

      When true remove class from node, else skip oneself.

    Returns void

  • Removes a css class from a node. The css class is only removed if the node is an element.

    Parameters

    • node: Node

      Node to remove css class from

    • cssClass: string

      Css class to remove

    Returns void

  • Remove a css class from a node and previous siblings.

    Parameters

    • node: Node

      Node to start with

    • cssClass: string

      Css class to remove

    • oneSelf: boolean

      When true remove class from node, else skip oneself.

    • children: boolean

      When true remove class from the children as well

    Returns void

  • Replace all replacement nodes with their originals. Then it will set the length property to 0, clearing all stored values.

    Parameters

    • backupList: UFNodeBackup[]

      Array of backup entries as created by the addXXXX methods.

    Returns void

  • Wraps a text node with a span element.

    Parameters

    • node: Node

      Node to wrap into a span element.

    • OptionalcssClasses: string

      Optional css classes to use for span

    Returns HTMLSpanElement

    New span element