Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "dom"

Index

Functions

Const $addChild

  • $addChild(parent: Element, child: Element, idx?: NumOrElement): void

Const $attribs

  • $attribs(el: Element, attribs: any): void
  • Takes an object of attributes and applies them to given DOM element.

    remarks

    The following rules & transformations are applied (in the stated order):

    • {@link @thi.ng/api#IDeref} values are derefd
    • attributes prefixed with on are considered event listeners and can either have a function value or tuple of [listener, opts], where opts are the standard .addEventListener() options
    • function values for any other attribs are first called with the entire attribs object and return value used
    • array values are converted into space-delimited string

    CSS classs are to given as class attribute, with its value either a string or an object of booleans. If the latter, the given class names are either added to or removed from the current list of classes.

    CSS style rules can be defined via the style attrib. Please $style for further details.

    Data attributes are to be given as object under the data attribute name, with its values being merged with the element's current dataset property.

    Depending on element type the value attribute will be updated keeping the current cursor position / selection intact.

    Parameters

    • el: Element
    • attribs: any

    Returns void

Const $clear

  • $clear(el: Element): Element

Const $el

  • $el(tag: string, attribs: any, body?: any, parent?: Element, idx?: NumOrElement): Element
  • Create a single DOM element and optionally attaches it to parent.

    remarks

    Supports Emmet-style tag names in this form: tag#id.class1.class2. attribs is a plain object of element attributes. See $attribs for further details.

    If parent is given, but no idx arg, the new element will be appended as child.

    Parameters

    • tag: string
    • attribs: any
    • Optional body: any
    • Optional parent: Element
    • Default value idx: NumOrElement = -1

    Returns Element

Const $html

  • $html(el: HTMLElement, body: MaybeDeref<string>): void
  • Same as el.innerHtml = body, use with caution! If body is an {@link @thi.ng/api#IDeref} it'll be automatically deref'd.

    Parameters

    • el: HTMLElement
    • body: MaybeDeref<string>

    Returns void

Const $moveTo

  • $moveTo(newParent: Element, el: Element, idx?: NumOrElement): void

Const $remove

  • $remove(el: Element): void

Const $style

  • $style(el: Element, rules: string | any): void
  • Takes an object (or string) of CSS properties, compiles them into a single CSS string and sets it as style attribute on the given element.

    remarks

    All property values can be {@link @thi.ng/api#IDeref} values, in which case they're are first derefd before use. If the value is a function, it will be called with the entire rules object as arg and the return value used.

    Parameters

    • el: Element
    • rules: string | any

    Returns void

Const $text

  • $text(el: HTMLElement, body: any): void
  • Same as el.innerText = body, however if body is an {@link @thi.ng/api#IDeref} it'll be automatically deref'd.

    Parameters

    • el: HTMLElement
    • body: any

    Returns void

Const $tree

  • $tree(tree: any, parent: Element, idx?: NumOrElement): Promise<any>
  • hdom-style DOM tree creation from hiccup format. Returns DOM element of tree root. See $el for further details.

    remarks

    Supports elements given in these forms:

    • IComponent instance
    • {@link IDeref} instance (must resolve to another supported type in this list)
    • ["div#id.class", {...attribs}, ...children]
    • [IComponent, ...mountargs]
    • [function, ...args]
    • ES6 iterable of the above (for child values only!)

    Any other values will be cast to strings and added as spans to current parent.

    Parameters

    • tree: any
    • parent: Element
    • Default value idx: NumOrElement = -1

    Returns Promise<any>

Const $treeElem

  • $treeElem(tree: any, parent: Element, idx: NumOrElement): Element | Promise<any>

Const $treeIter

  • $treeIter(tree: any, parent: Element): null

Const $treeTag

  • $treeTag(tree: any, parent: Element, idx: NumOrElement): Element

Const registerPrefix

  • registerPrefix(prefix: string, url: string): void
  • Registers an XML namespace prefix and its URL for later use, e.g. to define namespaced elements/attributes.

    Parameters

    • prefix: string
    • url: string

    Returns void

Const setAttrib

  • setAttrib(el: Element, id: string, val: any, attribs: any): void

Const updateDataAttribs

  • updateDataAttribs(el: HTMLElement, attribs: any): void

Const updateValueAttrib

  • updateValueAttrib(el: HTMLInputElement, value: any): void

Object literals

Const PREFIXES

PREFIXES: object
internal

svg

svg: string = XML_SVG

xlink

xlink: string = XML_XLINK

xmlns

xmlns: string = XML_XMLNS

Generated using TypeDoc