Use hash for id highlight

This commit is contained in:
Wayland-Smithy 2022-04-09 12:09:57 -07:00 committed by Hans5958
parent 939c39f6c1
commit e86d3f4258
4 changed files with 20 additions and 6 deletions

View file

@ -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);

View file

@ -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

View file

@ -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){

View file

@ -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){