A few small tweaks
[jkinsey.net.git] / js / script.js
index 1fabcaf40b3a6ce0264fef3bff47136020f7b6b4..c8ea1573b6c8b31f3253847ad536d5aba96dddd7 100644 (file)
@@ -1,14 +1,43 @@
 window.addEventListener('load', function() {
-    var menuLoc = 0;
     var links = document.getElementById("links").children[0].children;
+    var home = document.getElementsByClassName("home");
     var menu = document.getElementById("menu");
-    function menuMove(node) {
-        if(menuLoc) return;
-        menu.setAttribute("class", "top");
-        setTimeout(function() { menu.setAttribute("class", "left") }, 600);
-        menuLoc = 1;
+    var content = document.getElementById("content");
+    var body = document.getElementsByTagName("body")[0];
+
+    function menuOperator(node, position, token="") {
+        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");
+        }
+        var color = node.getAttribute("data-color");
+        if(color) {
+            body.setAttribute("class", color);
+        }
+        window.history.pushState("object or string", "Title", node.href);
     }
-    for(var i = 0; i < links.length; i++) {
-        links[i].onclick = function(node) { menuMove(node); };
+
+    for(var i = 0; i < links.length - 1; i++) {
+        links[i].children[0].onclick = function(event) { 
+            event.preventDefault();
+            var node = event.currentTarget;
+            menuOperator(node, "top");
+        };
+    }
+    for(var i = 0; i < home.length; i++) {
+        home[i].onclick = function(event) {
+            event.preventDefault();
+            var node = event.currentTarget;
+            menuOperator(node, "middle", "home");
+        }
     }
 }, false);