mirror of
https://github.com/placeAtlas/atlas.git
synced 2024-12-24 18:44:19 +01:00
Use hash for id highlight
This commit is contained in:
parent
939c39f6c1
commit
e86d3f4258
4 changed files with 20 additions and 6 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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){
|
||||
|
|
|
@ -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,7 +689,10 @@ 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){
|
||||
|
|
Loading…
Reference in a new issue