mirror of
https://github.com/placeAtlas/atlas.git
synced 2024-12-25 07:24:14 +01:00
Hash (tag) takeover
This commit is contained in:
parent
e86d3f4258
commit
f00f68a17a
3 changed files with 6 additions and 23 deletions
|
@ -31,7 +31,7 @@ function createInfoBlock(entry) {
|
||||||
|
|
||||||
let headerElement = document.createElement("h2");
|
let headerElement = document.createElement("h2");
|
||||||
let linkElement = document.createElement("a");
|
let linkElement = document.createElement("a");
|
||||||
linkElement.href = "#id=" + entry.id;
|
linkElement.href = "#" + entry.id;
|
||||||
linkElement.innerText = entry.name;
|
linkElement.innerText = entry.name;
|
||||||
headerElement.appendChild(linkElement);
|
headerElement.appendChild(linkElement);
|
||||||
|
|
||||||
|
|
|
@ -113,9 +113,9 @@ async function init(){
|
||||||
|
|
||||||
// Backwards compatibility for old links using "search" id arg
|
// Backwards compatibility for old links using "search" id arg
|
||||||
if(args.includes("id=")){
|
if(args.includes("id=")){
|
||||||
let idHash = "id=" + args.split("id=")[1].split("&")[0];
|
let idHash = args.split("id=")[1].split("&")[0];
|
||||||
window.location.hash = idHash;
|
window.location.hash = idHash;
|
||||||
let idArgMatch = new RegExp(`${idHash}&?`); // Patten for the id plus a following & if present
|
let idArgMatch = new RegExp(`id=${idHash}&?`); // Patten for the id plus a following & if present
|
||||||
window.location.search = window.location.search.substring(1).replace(idArgMatch, "");
|
window.location.search = window.location.search.substring(1).replace(idArgMatch, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,6 @@ var defaultSort = "shuffle";
|
||||||
document.getElementById("sort").value = defaultSort;
|
document.getElementById("sort").value = defaultSort;
|
||||||
|
|
||||||
var lastPos = [0, 0];
|
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
|
var fixed = false; // Fix hovered items in place, so that clicking on links is possible
|
||||||
|
|
||||||
|
@ -679,20 +678,7 @@ function highlightEntryFromUrl(){
|
||||||
|
|
||||||
var objectsContainer = document.getElementById("objectsList");
|
var objectsContainer = document.getElementById("objectsList");
|
||||||
|
|
||||||
var id = 0;
|
var id = window.location.hash.substring(1); //Remove hash prefix
|
||||||
|
|
||||||
var args = window.location.hash;
|
|
||||||
if(args){
|
|
||||||
id = args.split("id=")[1];
|
|
||||||
if(id){
|
|
||||||
id = id.split("&")[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(id === idLastHighlight){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
idLastHighlight = id;
|
|
||||||
|
|
||||||
var entries = atlas.filter(function(e){
|
var entries = atlas.filter(function(e){
|
||||||
return e.id === id;
|
return e.id === id;
|
||||||
|
@ -759,12 +745,9 @@ function initView(){
|
||||||
updateLines();
|
updateLines();
|
||||||
|
|
||||||
var args = window.location.hash;
|
var args = window.location.hash;
|
||||||
if(args){
|
if(args){ // both "/" and just "/#" will be an empty hash string
|
||||||
id = args.split("id=")[1];
|
|
||||||
if(id){
|
|
||||||
highlightEntryFromUrl();
|
highlightEntryFromUrl();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue