Add style components for zebra-tables and responsive-tables.

This commit is contained in:
Fredrik Jonsson 2023-04-23 16:47:57 +02:00
commit a5e759d988

28
assets/js/tables.js Normal file
View file

@ -0,0 +1,28 @@
/**
* @file
* A JavaScript file for responsive tables.
*/
(function () {
'use strict';
const tables = document.querySelectorAll('.responsive-table');
tables.forEach(function (table) {
const headers = table.querySelectorAll('th');
const rows = table.querySelectorAll('tr:has(td)');
rows.forEach(function (row) {
const cells = row.querySelectorAll('td');
cells.forEach(function (cell, i) {
cell.setAttribute('role','cell');
if (headers[i].innerText) {
cell.setAttribute('aria-label', headers[i].innerText);
}
});
});
});
})();