window.addEventListener('load', function() { var links = document.getElementById("links").children[0].children; var home = document.getElementsByClassName("home"); var menu = document.getElementById("menu"); var content = document.getElementById("content"); var menuLoc = parseInt(getComputedStyle(menu).getPropertyValue("top")); function menuOperator(position, token="") { event.preventDefault(); var node = event.currentTarget; menu.setAttribute("class", position); for(var i = 0; i < links.length; i++) { links[i].children[0].removeAttribute("class"); } node.setAttribute("class", "selected " + token); for(var i = 0; i < content.children.length; i++) { content.children[i].setAttribute("class", "hidden") } var name = node.getAttribute("data-name"); if(name) { var article = document.getElementById(name); article.setAttribute("class", "selected"); } window.history.pushState("object or string", "Title", node.href); } for(var i = 0; i < links.length - 1; i++) { links[i].children[0].onclick = function(event) { menuOperator("top"); }; } for(var i = 0; i < home.length; i++) { home[i].onclick = function(event) { menuOperator("middle", "home"); } } }, false);