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).
- Type:
- HTMLElement
(inner) N_(n, s, p, copt) → {string}
Plural-aware translation lookup.
| Name | Type | Attributes | Description |
|---|---|---|---|
n | number | Quantity to evaluate plural form. | |
s | string | Singular string. | |
p | string | Plural string. | |
c | string | <optional> | Optional context. |
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.
| Name | Type | Attributes | Description |
|---|---|---|---|
s | string | Source string. | |
c | string | <optional> | Optional translation context. |
Translated string or original.
- Type:
- string
(inner) cbi_d_add(field, dep, index)
Register a dependency entry for a field.
| Name | Type | Description |
|---|---|---|
field | HTMLElement | | Field element or its id. |
dep | Object | Dependency specification object. |
index | number | Order index of the dependent node. |
(inner) cbi_d_check(deps) → {boolean}
Evaluate a list of dependency descriptors and return whether any match.
| Name | Type | Description |
|---|---|---|
deps | Array.<Object> | Array of dependency objects to evaluate. |
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.
| Name | Type | Description |
|---|---|---|
target | string | Element id or name to query. |
ref | string | Reference value to compare with. |
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.
| Name | Type | Description |
|---|---|---|
sb | HTMLElement | The select element to convert. |
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.
| Name | Type | Description |
|---|---|---|
elem | HTMLElement | Element inside the row that triggers the swap. |
up | boolean | If true, move the row up; otherwise move down. |
store | string | ID of the hidden input used to store the order. |
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.
| Name | Type | Attributes | Description |
|---|---|---|---|
elem | HTMLElement | Element inside the form or an element with a form. | |
name | string | <optional> | Name of hidden input to include, if any. |
value | string | <optional> | Value for the hidden input (defaults to '1'). |
action | string | <optional> | Optional form action URL override. |
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.
| Name | Type | Description |
|---|---|---|
container | HTMLElement | Parent container element. |
(inner) cbi_update_table(table, …data, placeholderopt)
Update or initialize a table UI widget with new data.
| Name | Type | Attributes | Description |
|---|---|---|---|
table | HTMLElement | | Table element or selector. | |
data | Array.<Node> | <repeatable> | Data to update the table with. |
placeholder | string | <optional> | Placeholder text when empty. |
(inner) cbi_validate_field(cbid, optional, type)
Attach a validator to a field and wire validation events.
| Name | Type | Description |
|---|---|---|
cbid | HTMLElement | | Element or element id to validate. |
optional | boolean | Whether an empty value is allowed. |
type | string | 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.
| Name | Type | Attributes | Description |
|---|---|---|---|
form | HTMLFormElement | Form element containing validators. | |
errmsg | string | <optional> | Message to show when validation fails. |
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.
| Name | Type | Description |
|---|---|---|
input | HTMLInputElement | 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).
| Name | Type | Description |
|---|---|---|
form | HTMLFormElement | Form to validate after a short delay. |
Always returns true.
- Type:
- boolean
(inner) findParent(node, selector) → {HTMLElement|null}
Find the parent matching selector from node upwards.
| Name | Type | Description |
|---|---|---|
node | Node | Starting node. |
selector | string | CSS selector to match ancestor. |
- Type:
- HTMLElement |
null
(inner) isElem(e) → {HTMLElement|null}
Return the element for input which may be an element or an id.
| Name | Type | Description |
|---|---|---|
e | Element | | Element or id. |
- Type:
- HTMLElement |
null
(inner) matchesElem(node, selector) → {boolean}
Test whether node matches a CSS selector.
| Name | Type | Description |
|---|---|---|
node | Node | Node to test. |
selector | string | CSS selector. |
- Type:
- boolean
(inner) s8(bytes, off) → {number}
Read signed 8-bit integer from a byte array at the given offset.
| Name | Type | Description |
|---|---|---|
bytes | Array.<number> | Byte array. |
off | number | Offset into the array. |
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.
| Name | Type | Description |
|---|---|---|
s | string | | Input string. |
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.
| Name | Type | Description |
|---|---|---|
s | * | Value to convert to string and trim. |
Trimmed and normalised string.
- Type:
- string
(inner) u16(bytes, off) → {number}
Read unsigned 16-bit little-endian integer from a byte array at offset.
| Name | Type | Description |
|---|---|---|
bytes | Array.<number> | Byte array. |
off | number | Offset into the array. |
Unsigned 16-bit integer.
- Type:
- number