Merge pull request #9 from mattr555/master

Added linking to entries via url hash
This commit is contained in:
Roland Rytz 2017-04-06 00:58:13 +02:00 committed by GitHub
commit f1031a9035

View file

@ -23,6 +23,28 @@
========================================================================
*/
function createInfoBlock(entry){
var element = document.createElement("div");
element.className = "object";
var html = '<h2><a href="#id'+entry.id+'">'+entry.name+'</a></h2>';
if(entry.description){
html += '<p>'+entry.description+'</p>';
}
if(entry.website){
html += '<a target="_blank" href='+entry.website+'>Website</a>';
}
if(entry.subreddit){
if(entry.subreddit.substring(0, 2) == "r/"){
entry.subreddit = "/" + entry.subreddit;
} else if(entry.subreddit.substring(0, 1) != "/"){
entry.subreddit = "/r/" + entry.subreddit;
}
html += '<a target="_blank" href=https://reddit.com'+entry.subreddit+'>'+entry.subreddit+'</a>';
}
element.innerHTML = html;
return element;
}
function initView(){
@ -61,6 +83,31 @@ function initView(){
buildObjectsList();
// parse linked atlas entry id from link hash
if (window.location.hash.substring(3)){
var id = parseInt(window.location.hash.substring(3));
var entry = atlas.filter(function(e){
return e.id === id;
});
if (entry.length === 1){
entry = entry[0];
var infoElement = createInfoBlock(entry);
objectsContainer.appendChild(infoElement);
zoomOrigin = [
(-(container.clientWidth/2 - innerContainer.clientWidth/2) + container.clientWidth/2 - entry.center[0]* zoom)
,(-(container.clientHeight/2 - innerContainer.clientHeight/2) + container.clientHeight/2 + 50 - entry.center[1]* zoom)
]
applyView();
hovered = [entry];
fixed = true;
render();
hovered[0].element = infoElement;
updateLines();
}
}
container.addEventListener("mousemove", function(e){
updateHovering(e);
});
@ -117,25 +164,7 @@ function initView(){
objectsContainer.innerHTML = "";
for(var i in hovered){
var element = document.createElement("div");
element.className = "object";
var html = '<h2>'+hovered[i].name+'</h2>';
if(hovered[i].description){
html += '<p>'+hovered[i].description+'</p>';
}
if(hovered[i].website){
html += '<a target="_blank" href='+hovered[i].website+'>Website</a>';
}
if(hovered[i].subreddit){
if(hovered[i].subreddit.substring(0, 2) == "r/"){
hovered[i].subreddit = "/" + hovered[i].subreddit;
} else if(hovered[i].subreddit.substring(0, 1) != "/"){
hovered[i].subreddit = "/r/" + hovered[i].subreddit;
}
html += '<a target="_blank" href=https://reddit.com'+hovered[i].subreddit+'>'+hovered[i].subreddit+'</a>';
}
element.innerHTML = html;
var element = createInfoBlock(hovered[i]);
objectsContainer.appendChild(element);
@ -259,25 +288,7 @@ function initView(){
}
var element = document.createElement("div");
element.className = "object";
var html = '<h2>'+sortedAtlas[i].name+'</h2>';
if(sortedAtlas[i].description){
html += '<p>'+sortedAtlas[i].description+'</p>';
}
if(sortedAtlas[i].website){
html += '<a target="_blank" href='+sortedAtlas[i].website+'>Website</a>';
}
if(sortedAtlas[i].subreddit){
if(sortedAtlas[i].subreddit.substring(0, 2) == "r/"){
sortedAtlas[i].subreddit = "/" + sortedAtlas[i].subreddit;
} else if(sortedAtlas[i].subreddit.substring(0, 1) != "/"){
sortedAtlas[i].subreddit = "/r/" + sortedAtlas[i].subreddit;
}
html += '<a target="_blank" href=https://reddit.com'+sortedAtlas[i].subreddit+'>'+sortedAtlas[i].subreddit+'</a>';
}
element.innerHTML = html;
var element = createInfoBlock(sortedAtlas[i]);
element.foo = sortedAtlas[i];
@ -453,4 +464,3 @@ function initView(){
});
}