diff options
Diffstat (limited to 'usr.sbin/httpd/js.h.in')
-rw-r--r-- | usr.sbin/httpd/js.h.in | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/usr.sbin/httpd/js.h.in b/usr.sbin/httpd/js.h.in new file mode 100644 index 00000000000..8d0ea22af36 --- /dev/null +++ b/usr.sbin/httpd/js.h.in @@ -0,0 +1,18 @@ +static const char *js = +const rowValue = (tr, idx) => tr.children[idx].getAttribute('data-o') || tr.children[idx].innerText || tr.children[idx].textContent; + +const compare = (idx, asc) => (a, b) => ((v1, v2) => + v1 !== '' && v2 !== '' && !isNaN(v1) && !isNaN(v2) ? v1 - v2 : v1.toString().localeCompare(v2) + )(rowValue(asc ? a : b, idx), rowValue(asc ? b : a, idx)); + +// set up the listener +document.querySelectorAll('tr.sort th').forEach(th => th.addEventListener('click', (() => { + const table = th.closest('table'); + // make the sorted column bold + table.querySelectorAll('tr.sort th').forEach(th2 => + th2.className = th2 == th ? 'sorted' : 'unsorted'); + const body = table.querySelector('tbody'); + Array.from(body.querySelectorAll('tr')) + .sort(compare(Array.from(th.parentNode.children).indexOf(th), this.asc = !this.asc)) + .forEach(tr => body.appendChild(tr) ); +}))) |