diff options
author | Jo-Philipp Wich <jo@mein.io> | 2018-05-30 15:59:52 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2018-05-30 15:59:52 +0200 |
commit | d1df5a6b7d39dea0fcc9ace778d15dce6682a36a (patch) | |
tree | 4f2b69eee3d1d727beaa9986aeeb7d830d1898fd /modules/luci-base | |
parent | 0d2ae8d65360d052cb45db9897e042fb388ba447 (diff) |
luci-base: cbi.js: fix cbi_row_swap() after recent table markup changes
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules/luci-base')
-rw-r--r-- | modules/luci-base/htdocs/luci-static/resources/cbi.js | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/modules/luci-base/htdocs/luci-static/resources/cbi.js b/modules/luci-base/htdocs/luci-static/resources/cbi.js index 47eead5d8a..724691ace2 100644 --- a/modules/luci-base/htdocs/luci-static/resources/cbi.js +++ b/modules/luci-base/htdocs/luci-static/resources/cbi.js @@ -1244,44 +1244,44 @@ function cbi_validate_field(cbid, optional, type) function cbi_row_swap(elem, up, store) { var tr = elem.parentNode; - while (tr && tr.nodeName.toLowerCase() != 'tr') + + while (tr && !tr.classList.contains('cbi-section-table-row')) tr = tr.parentNode; if (!tr) return false; - var table = tr.parentNode; - while (table && table.nodeName.toLowerCase() != 'table') - table = table.parentNode; - - if (!table) - return false; - - var s = up ? 3 : 2; - var e = up ? table.rows.length : table.rows.length - 1; + if (up) { + var prev = tr.previousElementSibling; - for (var idx = s; idx < e; idx++) - { - if (table.rows[idx] == tr) - { - if (up) - tr.parentNode.insertBefore(table.rows[idx], table.rows[idx-1]); - else - tr.parentNode.insertBefore(table.rows[idx+1], table.rows[idx]); + if (prev && prev.classList.contains('cbi-section-table-row')) + tr.parentNode.insertBefore(tr, prev); + else + return; + } + else { + var next = tr.nextElementSibling ? tr.nextElementSibling.nextElementSibling : null; - break; - } + if (next && next.classList.contains('cbi-section-table-row')) + tr.parentNode.insertBefore(tr, next); + else if (!next) + tr.parentNode.appendChild(tr); + else + return; } 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(/-([^\-]+)$/) ) - ids.push(RegExp.$1); + for (var i = 0, n = 0; i < tr.parentNode.childNodes.length; i++) { + 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); |