Skip to content

Commit 36ce5e7

Browse files
author
Min-Yen Kan
committed
fix(site): initialize Tablesort from footer for reliable sorting
Move Tablesort scripts to footer_custom.html with a readyState guard. Scope styles to main content tables. Add .gitignore for Bundler paths under docs/ so local cache is not committed. Made-with: Cursor
1 parent e6e5592 commit 36ce5e7

3 files changed

Lines changed: 53 additions & 18 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Bundler / Jekyll (site lives in docs/)
2+
docs/.bundle/
3+
docs/.bundle-cache/
4+
docs/vendor/

docs/_includes/footer_custom.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!-- tablesort: load at end of body so the DOM exists and init cannot miss DOMContentLoaded -->
2+
<script src="{{ '/assets/js/tablesort.min.js' | relative_url }}"></script>
3+
<script src="{{ '/assets/js/tablesort.number.min.js' | relative_url }}"></script>
4+
<script>
5+
(function () {
6+
function initSortableTables() {
7+
if (typeof Tablesort === 'undefined') return;
8+
document.querySelectorAll('main table').forEach(function (table) {
9+
if (table.dataset.tablesortInit === '1') return;
10+
table.dataset.tablesortInit = '1';
11+
try {
12+
new Tablesort(table);
13+
} catch (e) {
14+
console.warn('Tablesort init failed:', e);
15+
}
16+
});
17+
}
18+
if (document.readyState === 'loading') {
19+
document.addEventListener('DOMContentLoaded', initSortableTables);
20+
} else {
21+
initSortableTables();
22+
}
23+
window.addEventListener('pageshow', function (ev) {
24+
if (ev.persisted) initSortableTables();
25+
});
26+
})();
27+
</script>

docs/_includes/head_custom.html

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
1-
<!-- tablesort: client-side column sorting for all markdown tables -->
2-
<script src="{{ '/assets/js/tablesort.min.js' | relative_url }}"></script>
3-
<script src="{{ '/assets/js/tablesort.number.min.js' | relative_url }}"></script>
1+
<!-- tablesort: header affordances (Tablesort adds role="columnheader" after init) -->
42
<style>
5-
/* Sortable table header styling */
6-
table th[role=columnheader] {
3+
main table thead th {
74
cursor: pointer;
85
user-select: none;
96
white-space: nowrap;
7+
position: relative;
8+
touch-action: manipulation;
109
}
11-
table th[role=columnheader]:not(.no-sort)::after {
12-
content: ' \2195'; /* up-down arrow */
10+
main table th[role='columnheader'] {
11+
cursor: pointer;
12+
user-select: none;
13+
white-space: nowrap;
14+
}
15+
main table th[role='columnheader']:not(.no-sort)::after {
16+
content: ' \2195';
1317
font-size: 0.75em;
1418
color: #888;
1519
}
16-
table th[aria-sort=ascending]::after { content: ' \2191' !important; color: #333; }
17-
table th[aria-sort=descending]::after { content: ' \2193' !important; color: #333; }
18-
table tbody tr:hover { background-color: rgba(0,0,0,0.04); }
20+
main table th[aria-sort='ascending']::after {
21+
content: ' \2191' !important;
22+
color: #959396;
23+
}
24+
main table th[aria-sort='descending']::after {
25+
content: ' \2193' !important;
26+
color: #959396;
27+
}
28+
main table tbody tr:hover {
29+
background-color: rgba(128, 128, 128, 0.12);
30+
}
1931
</style>
20-
<script>
21-
document.addEventListener('DOMContentLoaded', function () {
22-
// Apply tablesort to every table on the page
23-
document.querySelectorAll('table').forEach(function (table) {
24-
new Tablesort(table);
25-
});
26-
});
27-
</script>

0 commit comments

Comments
 (0)