luci-base: cbi.js: fix cbi_row_swap() after recent table markup changes

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
Jo-Philipp Wich 2018-05-30 15:59:52 +02:00
parent 0d2ae8d653
commit d1df5a6b7d

View file

@ -1244,44 +1244,44 @@ function cbi_validate_field(cbid, optional, type)
function cbi_row_swap(elem, up, store) function cbi_row_swap(elem, up, store)
{ {
var tr = elem.parentNode; var tr = elem.parentNode;
while (tr && tr.nodeName.toLowerCase() != 'tr')
while (tr && !tr.classList.contains('cbi-section-table-row'))
tr = tr.parentNode; tr = tr.parentNode;
if (!tr) if (!tr)
return false; return false;
var table = tr.parentNode; if (up) {
while (table && table.nodeName.toLowerCase() != 'table') var prev = tr.previousElementSibling;
table = table.parentNode;
if (!table) if (prev && prev.classList.contains('cbi-section-table-row'))
return false; tr.parentNode.insertBefore(tr, prev);
else
return;
}
else {
var next = tr.nextElementSibling ? tr.nextElementSibling.nextElementSibling : null;
var s = up ? 3 : 2; if (next && next.classList.contains('cbi-section-table-row'))
var e = up ? table.rows.length : table.rows.length - 1; tr.parentNode.insertBefore(tr, next);
else if (!next)
for (var idx = s; idx < e; idx++) tr.parentNode.appendChild(tr);
{ else
if (table.rows[idx] == tr) return;
{
if (up)
tr.parentNode.insertBefore(table.rows[idx], table.rows[idx-1]);
else
tr.parentNode.insertBefore(table.rows[idx+1], table.rows[idx]);
break;
}
} }
var ids = [ ]; var ids = [ ];
for (idx = 2; idx < table.rows.length; idx++)
{
table.rows[idx].className = table.rows[idx].className.replace(
/cbi-rowstyle-[12]/, 'cbi-rowstyle-' + (1 + (idx % 2))
);
if (table.rows[idx].id && table.rows[idx].id.match(/-([^\-]+)$/) ) for (var i = 0, n = 0; i < tr.parentNode.childNodes.length; i++) {
ids.push(RegExp.$1); var node = tr.parentNode.childNodes[i];
if (node.classList && node.classList.contains('cbi-section-table-row')) {
node.classList.remove('cbi-rowstyle-1');
node.classList.remove('cbi-rowstyle-2');
node.classList.add((n++ % 2) ? 'cbi-rowstyle-2' : 'cbi-rowstyle-1');
if (/-([^\-]+)$/.test(node.id))
ids.push(RegExp.$1);
}
} }
var input = document.getElementById(store); var input = document.getElementById(store);