diff --git a/web/_js/infoblock.js b/web/_js/infoblock.js index 32f6cb29..3cfe7d5c 100644 --- a/web/_js/infoblock.js +++ b/web/_js/infoblock.js @@ -31,7 +31,7 @@ function createInfoBlock(entry) { let headerElement = document.createElement("h2"); let linkElement = document.createElement("a"); - linkElement.href = "?id=" + entry.id; + linkElement.href = "#id=" + entry.id; linkElement.innerText = entry.name; headerElement.appendChild(linkElement); diff --git a/web/_js/main.js b/web/_js/main.js index 9b4fd788..199684fd 100644 --- a/web/_js/main.js +++ b/web/_js/main.js @@ -110,6 +110,14 @@ async function init(){ } else { mode = "view"; } + + // Backwards compatibility for old links using "search" id arg + if(args.includes("id=")){ + let idHash = "id=" + args.split("id=")[1].split("&")[0]; + window.location.hash = idHash; + let idArgMatch = new RegExp(`${idHash}&?`); // Patten for the id plus a following & if present + window.location.search = window.location.search.substring(1).replace(idArgMatch, ""); + } } document.body.dataset.mode = mode diff --git a/web/_js/overlap.js b/web/_js/overlap.js index c92d41cd..4f5735c7 100644 --- a/web/_js/overlap.js +++ b/web/_js/overlap.js @@ -27,7 +27,7 @@ function initOverlap(){ render(); updateLines(); - var args = window.location.search; + var args = window.location.hash; if(args){ id = args.split("id=")[1]; if(id){ diff --git a/web/_js/view.js b/web/_js/view.js index 655e23e2..2d626622 100644 --- a/web/_js/view.js +++ b/web/_js/view.js @@ -53,6 +53,7 @@ var defaultSort = "shuffle"; document.getElementById("sort").value = defaultSort; var lastPos = [0, 0]; +var idLastHighlight; // track the last id to prevent highlighting from different hash arg updates var fixed = false; // Fix hovered items in place, so that clicking on links is possible @@ -672,13 +673,15 @@ function updateHovering(e, tapped){ } } +window.addEventListener("hashchange", highlightEntryFromUrl); + function highlightEntryFromUrl(){ var objectsContainer = document.getElementById("objectsList"); var id = 0; - var args = window.location.search; + var args = window.location.hash; if(args){ id = args.split("id=")[1]; if(id){ @@ -686,8 +689,11 @@ function highlightEntryFromUrl(){ } } - //var id = parseInt(window.location.hash.substring(3)); - + if(id === idLastHighlight){ + return; + } + idLastHighlight = id; + var entries = atlas.filter(function(e){ return e.id === id; }); @@ -752,7 +758,7 @@ function initView(){ render(); updateLines(); - var args = window.location.search; + var args = window.location.hash; if(args){ id = args.split("id=")[1]; if(id){