CBI (Configuration Bindings Interface) helper utilities and DOM helpers.

Provides initialization for CBI UI elements, dependency handling, validation wiring and miscellaneous helpers used by LuCI forms. Functions defined here are registered as global window.* symbols.

Methods

(inner) E() → {HTMLElement}

Create DOM elements using L.dom.create helper (convenience wrapper).

Returns:
Type: 
HTMLElement

(inner) N_(n, s, p, copt) → {string}

Plural-aware translation lookup.

Parameters:
NameTypeAttributesDescription
nnumber

Quantity to evaluate plural form.

sstring

Singular string.

pstring

Plural string.

cstring<optional>

Optional context.

Returns:

Translated plural form or source string.

Type: 
string

(inner) _(s, copt) → {string}

Lookup a translated string for the given message and optional context. Falls back to the source string when no translation found.

Parameters:
NameTypeAttributesDescription
sstring

Source string.

cstring<optional>

Optional translation context.

Returns:

Translated string or original.

Type: 
string

(inner) cbi_d_add(field, dep, index)

Register a dependency entry for a field.

Parameters:
NameTypeDescription
fieldHTMLElement | string

Field element or its id.

depObject

Dependency specification object.

indexnumber

Order index of the dependent node.

(inner) cbi_d_check(deps) → {boolean}

Evaluate a list of dependency descriptors and return whether any match.

Parameters:
NameTypeDescription
depsArray.<Object>

Array of dependency objects to evaluate.

Returns:

True when dependencies indicate the element should be shown.

Type: 
boolean

(inner) cbi_d_checkvalue(target, ref) → {boolean}

Check whether an input/select identified by target matches the given reference value.

Parameters:
NameTypeDescription
targetstring

Element id or name to query.

refstring

Reference value to compare with.

Returns:

True if the current value matches ref.

Type: 
boolean

(inner) cbi_d_update()

Update DOM nodes based on registered dependencies, showing or hiding nodes and restoring their order when dependency state changes.

(inner) cbi_dropdown_init(sb) → {L.ui.Dropdown|undefined}

Initialize a dropdown element into an L.ui.Dropdown instance and bind it. If already bound, this is a no-op.

Parameters:
NameTypeDescription
sbHTMLElement

The select element to convert.

Returns:

Dropdown instance or undefined when already bound.

Type: 
L.ui.Dropdown | undefined

(inner) cbi_init()

Initialize CBI widgets and wire up dependency and validation handlers. Walks the DOM looking for CBI-specific data attributes and replaces placeholders with interactive widgets.

(inner) cbi_row_swap(elem, up, store) → {boolean}

Move a table row up or down within a section and update the storage field.

Parameters:
NameTypeDescription
elemHTMLElement

Element inside the row that triggers the swap.

upboolean

If true, move the row up; otherwise move down.

storestring

ID of the hidden input used to store the order.

Returns:

Always returns false to cancel default action.

Type: 
boolean

(inner) cbi_submit(elem, nameopt, valueopt, actionopt) → {boolean}

Submit a form, optionally adding a hidden input to pass a name/value pair.

Parameters:
NameTypeAttributesDescription
elemHTMLElement

Element inside the form or an element with a form.

namestring<optional>

Name of hidden input to include, if any.

valuestring<optional>

Value for the hidden input (defaults to '1').

actionstring<optional>

Optional form action URL override.

Returns:

True on successful submit, false when no form found.

Type: 
boolean

(inner) cbi_tag_last(container)

Mark the last visible value container child with class cbi-value-last.

Parameters:
NameTypeDescription
containerHTMLElement

Parent container element.

(inner) cbi_update_table(table, …data, placeholderopt)

Update or initialize a table UI widget with new data.

Parameters:
NameTypeAttributesDescription
tableHTMLElement | string

Table element or selector.

dataArray.<Node><repeatable>

Data to update the table with.

placeholderstring<optional>

Placeholder text when empty.

(inner) cbi_validate_field(cbid, optional, type)

Attach a validator to a field and wire validation events.

Parameters:
NameTypeDescription
cbidHTMLElement | string

Element or element id to validate.

optionalboolean

Whether an empty value is allowed.

typestring

Validator type expression (passed to L.validation).

(inner) cbi_validate_form(form, errmsgopt) → {boolean}

Run all validators associated with a form and optionally show an error.

Parameters:
NameTypeAttributesDescription
formHTMLFormElement

Form element containing validators.

errmsgstring<optional>

Message to show when validation fails.

Returns:

True when form is valid.

Type: 
boolean

(inner) cbi_validate_named_section_add(input)

Enable/disable a named-section add button depending on input value.

Parameters:
NameTypeDescription
inputHTMLInputElement

Input that contains the new section name.

(inner) cbi_validate_reset(form) → {boolean}

Trigger a delayed form validation (used to allow UI state to settle).

Parameters:
NameTypeDescription
formHTMLFormElement

Form to validate after a short delay.

Returns:

Always returns true.

Type: 
boolean

(inner) findParent(node, selector) → {HTMLElement|null}

Find the parent matching selector from node upwards.

Parameters:
NameTypeDescription
nodeNode

Starting node.

selectorstring

CSS selector to match ancestor.

Returns:
Type: 
HTMLElement | null

(inner) isElem(e) → {HTMLElement|null}

Return the element for input which may be an element or an id.

Parameters:
NameTypeDescription
eElement | string

Element or id.

Returns:
Type: 
HTMLElement | null

(inner) matchesElem(node, selector) → {boolean}

Test whether node matches a CSS selector.

Parameters:
NameTypeDescription
nodeNode

Node to test.

selectorstring

CSS selector.

Returns:
Type: 
boolean

(inner) s8(bytes, off) → {number}

Read signed 8-bit integer from a byte array at the given offset.

Parameters:
NameTypeDescription
bytesArray.<number>

Byte array.

offnumber

Offset into the array.

Returns:

Signed 8-bit value (returned as unsigned number).

Type: 
number

(inner) sfh(s) → {string|null}

Compute a stable 32-bit-ish string hash used for translation keys. Encodes UTF-8 surrogate pairs and mixes bytes into a hex hash string.

Parameters:
NameTypeDescription
sstring | null

Input string.

Returns:

Hex hash string or null for empty input.

Type: 
string | null

(inner) trimws(s) → {string}

Trim whitespace and normalise internal whitespace sequences to single spaces.

Parameters:
NameTypeDescription
s*

Value to convert to string and trim.

Returns:

Trimmed and normalised string.

Type: 
string

(inner) u16(bytes, off) → {number}

Read unsigned 16-bit little-endian integer from a byte array at offset.

Parameters:
NameTypeDescription
bytesArray.<number>

Byte array.

offnumber

Offset into the array.

Returns:

Unsigned 16-bit integer.

Type: 
number