-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
20 lines (19 loc) · 721 Bytes
/
index.js
File metadata and controls
20 lines (19 loc) · 721 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function adaptTableToMobile({
tables = document.querySelectorAll('table.adaptToMobile'),
classes = ["inline-block", "sm:hidden", "w-1/4", "font-bold"]
} = {}) {
tables.forEach(table => {
const titles = Array.from(table.querySelectorAll('th')).map(th => th.textContent);
table.querySelectorAll('tr').forEach(row => {
row.querySelectorAll('td').forEach((td, i) => {
const span = document.createElement('span');
span.className = classes.join(' ');
span.textContent = `${titles[i]}:`;
td.prepend(span);
});
});
});
}
if (typeof module !== 'undefined') {
module.exports = adaptTableToMobile;
}