return (0x100000000 + hash).toString(16).substr(1);
}
-function _(s) {
- return (window.TR && TR[sfh(s)]) || s;
+var plural_function = null;
+
+function trimws(s) {
+ return String(s).trim().replace(/[ \t\n]+/g, ' ');
+}
+
+function _(s, c) {
+ var k = (c != null ? trimws(c) + '\u0001' : '') + trimws(s);
+ return (window.TR && TR[sfh(k)]) || s;
+}
+
+function N_(n, s, p, c) {
+ if (plural_function == null && window.TR)
+ plural_function = new Function('n', (TR['00000000'] || 'plural=(n != 1);') + 'return +plural');
+
+ var i = plural_function ? plural_function(n) : (n != 1),
+ k = (c != null ? trimws(c) + '\u0001' : '') + trimws(s) + '\u0002' + i.toString();
+
+ return (window.TR && TR[sfh(k)]) || (i ? p : s);
}
node.getAttribute('data-type'));
}
- document.querySelectorAll('[data-browser]').forEach(cbi_browser_init);
-
document.querySelectorAll('.cbi-tooltip:not(:empty)').forEach(function(s) {
s.parentNode.classList.add('cbi-tooltip-container');
});
i.addEventListener('mouseout', handler);
});
+ var tasks = [];
+
document.querySelectorAll('[data-ui-widget]').forEach(function(node) {
var args = JSON.parse(node.getAttribute('data-ui-widget') || '[]'),
widget = new (Function.prototype.bind.apply(L.ui[args[0]], args)),
markup = widget.render();
- markup.addEventListener('widget-change', cbi_d_update);
- node.parentNode.replaceChild(markup, node);
+ tasks.push(Promise.resolve(markup).then(function(markup) {
+ markup.addEventListener('widget-change', cbi_d_update);
+ node.parentNode.replaceChild(markup, node);
+ }));
});
- cbi_d_update();
-}
-
-function cbi_filebrowser(id, defpath) {
- var field = L.dom.elem(id) ? id : document.getElementById(id);
- var browser = window.open(
- cbi_strings.path.browser + (field.value || defpath || '') + '?field=' + field.id,
- "luci_filebrowser", "width=300,height=400,left=100,top=200,scrollbars=yes"
- );
-
- browser.focus();
-}
-
-function cbi_browser_init(field)
-{
- field.parentNode.insertBefore(
- E('img', {
- 'src': L.resource('cbi/folder.gif'),
- 'class': 'cbi-image-button',
- 'click': function(ev) {
- cbi_filebrowser(field, field.getAttribute('data-browser'));
- ev.preventDefault();
- }
- }), field.nextSibling);
+ Promise.all(tasks).then(cbi_d_update);
}
function cbi_validate_form(form, errmsg)
return true;
}
+function cbi_validate_named_section_add(input)
+{
+ var button = input.parentNode.parentNode.querySelector('.cbi-button-add');
+ if (input.value !== '') {
+ button.disabled = false;
+ }
+ else {
+ button.disabled = true;
+ }
+}
+
function cbi_validate_reset(form)
{
window.setTimeout(
switch(pType) {
case 'b':
- subst = (+param || 0).toString(2);
+ subst = Math.floor(+param || 0).toString(2);
break;
case 'c':
break;
case 'd':
- subst = ~~(+param || 0);
+ subst = Math.floor(+param || 0).toFixed(0);
break;
case 'u':
- subst = ~~Math.abs(+param || 0);
+ var n = +param || 0;
+ subst = Math.floor((n < 0) ? 0x100000000 + n : n).toFixed(0);
break;
case 'f':
break;
case 'o':
- subst = (+param || 0).toString(8);
+ subst = Math.floor(+param || 0).toString(8);
break;
case 's':
break;
case 'x':
- subst = ('' + (+param || 0).toString(16)).toLowerCase();
+ subst = Math.floor(+param || 0).toString(16).toLowerCase();
break;
case 'X':
- subst = ('' + (+param || 0).toString(16)).toUpperCase();
+ subst = Math.floor(+param || 0).toString(16).toUpperCase();
break;
case 'h':
var tm = 0;
var ts = (param || 0);
- if (ts > 60) {
+ if (ts > 59) {
tm = Math.floor(ts / 60);
ts = (ts % 60);
}
- if (tm > 60) {
+ if (tm > 59) {
th = Math.floor(tm / 60);
tm = (tm % 60);
}
- if (th > 24) {
+ if (th > 23) {
td = Math.floor(th / 24);
th = (th % 24);
}
for (i = 0; (i < units.length) && (val > mf); i++)
val /= mf;
- subst = (i ? val.toFixed(pr) : val) + units[i];
+ if (i)
+ subst = val.toFixed(pr) + units[i] + (mf == 1024 ? 'i' : '');
+ else
+ subst = val + ' ';
+
pMinLength = null;
break;
}
}
function cbi_dropdown_init(sb) {
+ if (sb && L.dom.findClassInstance(sb) instanceof L.ui.Dropdown)
+ return;
+
var dl = new L.ui.Dropdown(sb, null, { name: sb.getAttribute('name') });
return dl.bind(sb);
}
if (!isElem(target))
return;
- target.querySelectorAll('.tr.table-titles, .cbi-section-table-titles').forEach(function(thead) {
+ target.querySelectorAll('tr.table-titles, .tr.table-titles, .cbi-section-table-titles').forEach(function(thead) {
var titles = [];
- thead.querySelectorAll('.th').forEach(function(th) {
+ thead.querySelectorAll('th, .th').forEach(function(th) {
titles.push(th);
});
if (Array.isArray(data)) {
- var n = 0, rows = target.querySelectorAll('.tr');
+ var n = 0, rows = target.querySelectorAll('tr, .tr'), trows = [];
data.forEach(function(row) {
- var trow = E('div', { 'class': 'tr' });
+ var trow = E('tr', { 'class': 'tr' });
for (var i = 0; i < titles.length; i++) {
var text = (titles[i].innerText || '').trim();
- var td = trow.appendChild(E('div', {
+ var td = trow.appendChild(E('td', {
'class': titles[i].className,
'data-title': (text !== '') ? text : null
- }, row[i] || ''));
+ }, (row[i] != null) ? row[i] : ''));
td.classList.remove('th');
td.classList.add('td');
trow.classList.add('cbi-rowstyle-%d'.format((n++ % 2) ? 2 : 1));
- if (rows[n])
- target.replaceChild(trow, rows[n]);
- else
- target.appendChild(trow);
+ trows[n] = trow;
});
+ for (var i = 1; i <= n; i++) {
+ if (rows[i])
+ target.replaceChild(trows[i], rows[i]);
+ else
+ target.appendChild(trows[i]);
+ }
+
while (rows[++n])
target.removeChild(rows[n]);
if (placeholder && target.firstElementChild === target.lastElementChild) {
- var trow = target.appendChild(E('div', { 'class': 'tr placeholder' }));
- var td = trow.appendChild(E('div', { 'class': titles[0].className }, placeholder));
+ var trow = target.appendChild(E('tr', { 'class': 'tr placeholder' }));
+ var td = trow.appendChild(E('td', { 'class': titles[0].className }, placeholder));
td.classList.remove('th');
td.classList.add('td');
else {
thead.parentNode.style.display = 'none';
- thead.parentNode.querySelectorAll('.tr, .cbi-section-table-row').forEach(function(trow) {
+ thead.parentNode.querySelectorAll('tr, .tr, .cbi-section-table-row').forEach(function(trow) {
if (trow !== thead) {
var n = 0;
- trow.querySelectorAll('.th, .td').forEach(function(td) {
+ trow.querySelectorAll('th, td, .th, .td').forEach(function(td) {
if (n < titles.length) {
var text = (titles[n++].innerText || '').trim();
if (text !== '')