fix: open linked entry row when the hash changes after load

An entry link like /categories/caching/#entry-diskcache did not open its row when only the hash changed on an already-loaded page (editing the URL, back/forward), because the row-opening logic ran only on initial load.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Vinta Chen
2026-10-27 21:07:51 +08:00
co-authored by Claude
parent b91f2ab950
commit 9beb5d68b5
+9 -4
View File
@@ -332,6 +332,14 @@ function openEntryRow(row) {
setRowOpen(row, true);
}
function openHashedRow() {
const linkedRow = document.getElementById(decodeURIComponent(location.hash.slice(1)));
if (linkedRow && linkedRow.matches("tr.row")) openEntryRow(linkedRow);
}
// Editing the hash or going back/forward on the same page does not reload it
window.addEventListener("hashchange", openHashedRow);
// Group headings are hidden while sorted flat or filtered out by search, so a link to one must restore them first
document.addEventListener("click", function (e) {
const link = e.target.closest('a[href*="#"]');
@@ -447,8 +455,5 @@ if (backToTop) {
}
updateSortIndicators();
// Filtering collapses rows, so open a linked entry after restoring URL state.
if (location.hash) {
const linkedRow = document.getElementById(decodeURIComponent(location.hash.slice(1)));
if (linkedRow && linkedRow.matches("tr.row")) openEntryRow(linkedRow);
}
if (location.hash) openHashedRow();
})();