diff --git a/share/js/navigation.js b/share/js/navigation.js index 4472092..5cfc772 100644 --- a/share/js/navigation.js +++ b/share/js/navigation.js @@ -14,7 +14,11 @@ function Navigation(modules) { } ); }); - window.addEventListener('popstate', function(e) {navigate(e.state.url);}); + window.addEventListener('popstate', function(e) { + if(e.state != undefined) { + navigate(e.state.url); + } + }); history.replaceState({url: window.location.pathname}, 'Blog - title', window.location.pathname); return { hijackLinks: hijackLinks @@ -25,7 +29,8 @@ function Navigation(modules) { var links = domElem.getElementsByTagName('a'); for(var i = 0; i < links.length; i++) { var a = links[i]; - if(a.classList.contains("navigation")) { + var href = a.getAttribute("href"); + if(href[0] == "/" || href[0] == "#") { a.addEventListener('click', visit(a.getAttribute("href"))); } } @@ -34,8 +39,13 @@ function Navigation(modules) { function visit(url) { return function(e) { e.preventDefault(); - history.pushState({url: url}, 'Blog - title', url); - navigate(url); + if(url[0] == '#') { + window.location = url; + history.replaceState({url: window.location.pathname}, 'Blog - title', url); + } else { + navigate(url); + history.pushState({url: url}, 'Blog - title', url); + } }; }