diff --git a/jsapi/LuCI.module_cbi.html b/jsapi/LuCI.module_cbi.html index 86c08da5ad..1f870e4e52 100644 --- a/jsapi/LuCI.module_cbi.html +++ b/jsapi/LuCI.module_cbi.html @@ -1,3 +1,3 @@ Module: cbi
On this page

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
LuCI Documentation
\ No newline at end of file +
On this page

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
LuCI Documentation
\ No newline at end of file diff --git a/jsapi/cbi.js.html b/jsapi/cbi.js.html index 944c703f2f..393128089a 100644 --- a/jsapi/cbi.js.html +++ b/jsapi/cbi.js.html @@ -677,133 +677,165 @@ String.prototype.format = function() return s; } + const dicts = []; + for (let i = 0; i < arguments.length; i++) + if (arguments[i] !== null && typeof(arguments[i]) === 'object' && !Array.isArray(arguments[i])) + dicts.push(arguments[i]); + let str = this; let subst, n, pad; let out = ''; const re = /^(([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X|q|h|j|t|m))/; + const re_named = /^(([^%]*)%\{([^}:]+)(?::('.|0|\x20)?(-)?(\d+)?(\.\d+)?(b|c|d|u|f|o|s|x|X|q|h|j|t|m))?\})/; let a = [], numSubstitutions = 0; - while ((a = re.exec(str)) !== null) { - const m = a[1]; - let leftpart = a[2], pPad = a[3], pJustify = a[4], pMinLength = a[5]; - let pPrecision = a[6], pType = a[7]; - let precision; + while (true) { + const an = re_named.exec(str); + a = an || re.exec(str); - if (pType == '%') { - subst = '%'; + if (!a) + break; + + const m = a[1]; + let leftpart = a[2], pPad, pJustify, pMinLength, pPrecision, pType; + let precision; + let param; + + if (an) { + pPad = a[4]; pJustify = a[5]; pMinLength = a[6]; + pPrecision = a[7]; pType = a[8] || 's'; + + param = ''; + for (let i = 0; i < dicts.length; i++) { + if (Object.prototype.hasOwnProperty.call(dicts[i], a[3])) { + param = dicts[i][a[3]]; + break; + } + } } else { - if (numSubstitutions < arguments.length) { - let param = arguments[numSubstitutions++]; + pPad = a[3]; pJustify = a[4]; pMinLength = a[5]; + pPrecision = a[6]; pType = a[7]; - pad = ''; - if (pPad && pPad.substr(0,1) == "'") - pad = pPad.substr(1,1); - else if (pPad) - pad = pPad; - else - pad = ' '; + if (pType == '%') { + subst = '%'; + out += leftpart + subst; + str = str.substr(m.length); + continue; + } - precision = -1; - if (pPrecision && pType == 'f') - precision = +pPrecision.substring(1); + if (numSubstitutions < arguments.length) + param = arguments[numSubstitutions++]; + } - subst = param; + if (param !== undefined) { + pad = ''; + if (pPad && pPad.substr(0,1) == "'") + pad = pPad.substr(1,1); + else if (pPad) + pad = pPad; + else + pad = ' '; - switch(pType) { - case 'b': - subst = Math.floor(+param || 0).toString(2); - break; + precision = -1; + if (pPrecision && pType == 'f') + precision = +pPrecision.substring(1); - case 'c': - subst = String.fromCharCode(+param || 0); - break; + subst = param; - case 'd': - subst = Math.floor(+param || 0).toFixed(0); - break; + switch(pType) { + case 'b': + subst = Math.floor(+param || 0).toString(2); + break; - case 'u': - n = +param || 0; - subst = Math.floor((n < 0) ? 0x100000000 + n : n).toFixed(0); - break; + case 'c': + subst = String.fromCharCode(+param || 0); + break; - case 'f': - subst = (precision > -1) - ? ((+param || 0.0)).toFixed(precision) - : (+param || 0.0); - break; + case 'd': + subst = Math.floor(+param || 0).toFixed(0); + break; - case 'o': - subst = Math.floor(+param || 0).toString(8); - break; + case 'u': + n = +param || 0; + subst = Math.floor((n < 0) ? 0x100000000 + n : n).toFixed(0); + break; - case 's': - subst = param; - break; + case 'f': + subst = (precision > -1) + ? ((+param || 0.0)).toFixed(precision) + : (+param || 0.0); + break; - case 'x': - subst = Math.floor(+param || 0).toString(16).toLowerCase(); - break; + case 'o': + subst = Math.floor(+param || 0).toString(8); + break; - case 'X': - subst = Math.floor(+param || 0).toString(16).toUpperCase(); - break; + case 's': + subst = param; + break; - case 'h': - subst = esc(param, html_esc); - break; + case 'x': + subst = Math.floor(+param || 0).toString(16).toLowerCase(); + break; - case 'q': - subst = esc(param, quot_esc); - break; + case 'X': + subst = Math.floor(+param || 0).toString(16).toUpperCase(); + break; - case 't': - var td = 0; - var th = 0; - var tm = 0; - var ts = (param || 0); + case 'h': + subst = esc(param, html_esc); + break; - if (ts > 59) { - tm = Math.floor(ts / 60); - ts = (ts % 60); - } + case 'q': + subst = esc(param, quot_esc); + break; - if (tm > 59) { - th = Math.floor(tm / 60); - tm = (tm % 60); - } + case 't': + var td = 0; + var th = 0; + var tm = 0; + var ts = (param || 0); - if (th > 23) { - td = Math.floor(th / 24); - th = (th % 24); - } + if (ts > 59) { + tm = Math.floor(ts / 60); + ts = (ts % 60); + } - subst = (td > 0) - ? String.format('%dd %dh %dm %ds', td, th, tm, ts) - : String.format('%dh %dm %ds', th, tm, ts); + if (tm > 59) { + th = Math.floor(tm / 60); + tm = (tm % 60); + } - break; + if (th > 23) { + td = Math.floor(th / 24); + th = (th % 24); + } - case 'm': - var mf = pMinLength ? +pMinLength : 1000; - var pr = pPrecision ? ~~(10 * +('0' + pPrecision)) : 2; + subst = (td > 0) + ? String.format('%dd %dh %dm %ds', td, th, tm, ts) + : String.format('%dh %dm %ds', th, tm, ts); - var i = 0; - var val = (+param || 0); - var units = [ ' ', ' K', ' M', ' G', ' T', ' P', ' E' ]; + break; - for (i = 0; (i < units.length) && (val > mf); i++) - val /= mf; + case 'm': + var mf = pMinLength ? +pMinLength : 1000; + var pr = pPrecision ? ~~(10 * +('0' + pPrecision)) : 2; - if (i) - subst = val.toFixed(pr) + units[i] + (mf == 1024 ? 'i' : ''); - else - subst = val + ' '; + var i = 0; + var val = (+param || 0); + var units = [ ' ', ' K', ' M', ' G', ' T', ' P', ' E' ]; - pMinLength = null; - break; - } + for (i = 0; (i < units.length) && (val > mf); i++) + val /= mf; + + if (i) + subst = val.toFixed(pr) + units[i] + (mf == 1024 ? 'i' : ''); + else + subst = val + ' '; + + pMinLength = null; + break; } } diff --git a/jsapi/external-String.html b/jsapi/external-String.html index 06756cd851..175f9bff85 100644 --- a/jsapi/external-String.html +++ b/jsapi/external-String.html @@ -1,3 +1,3 @@ External: String
On this page

LuCI.cbi~ String

Methods

format(…args) → {string}

Format a string using positional arguments.

Parameters:
NameTypeAttributesDescription
argsstring<repeatable>
Returns:
Type: 
string

nobr(…args) → {string}

Format a string using positional arguments.

Parameters:
NameTypeAttributesDescription
argsstring<repeatable>
Returns:
Type: 
string

(static) format(…args) → {string}

Format a string using positional arguments.

Parameters:
NameTypeAttributesDescription
argsstring<repeatable>
Returns:
Type: 
string

(static) nobr(…args) → {string}

Format a string using positional arguments.

Parameters:
NameTypeAttributesDescription
argsstring<repeatable>
Returns:
Type: 
string
LuCI Documentation
\ No newline at end of file +
On this page

LuCI.cbi~ String

Methods

format(…args) → {string}

Format a string using positional arguments.

Parameters:
NameTypeAttributesDescription
argsstring<repeatable>
Returns:
Type: 
string

nobr(…args) → {string}

Format a string using positional arguments.

Parameters:
NameTypeAttributesDescription
argsstring<repeatable>
Returns:
Type: 
string

(static) format(…args) → {string}

Format a string using positional arguments.

Parameters:
NameTypeAttributesDescription
argsstring<repeatable>
Returns:
Type: 
string

(static) nobr(…args) → {string}

Format a string using positional arguments.

Parameters:
NameTypeAttributesDescription
argsstring<repeatable>
Returns:
Type: 
string
LuCI Documentation
\ No newline at end of file