-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtable.js
More file actions
44 lines (38 loc) · 1.02 KB
/
table.js
File metadata and controls
44 lines (38 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const table = document.getElementById("projects");
let rows = [];
export function project_link(slug, title) {
const result = document.createElement("a");
result.innerText = title;
result.href = `https://microstudio.dev/i/${user}/${slug}`
return result;
}
export function add_row(title, slug, likes, comments) {
function add_cell(row, content) {
if (!(content instanceof HTMLElement)) {
content = new Text(content);
}
const cell = document.createElement("td");
cell.appendChild(content);
row.appendChild(cell);
}
let row = document.createElement("tr");
add_cell(row, project_link(slug, title))
add_cell(row, slug);
add_cell(row, likes);
add_cell(row, comments);
rows.push([title, slug, likes, comments, row]);
}
export function reset() {
rows = [];
}
export function reload() {
while (table.children.length > 1) {
table.removeChild(table.children[1]);
}
for (const row of rows) {
table.appendChild(row[4]);
}
}
export function sort(compare_fn) {
rows.sort(compare_fn);
}