A few small tweaks
[jkinsey.net.git] / js / script.js
index c5f2c7a4167db351e8af42da240d9cb2ea965c72..c8ea1573b6c8b31f3253847ad536d5aba96dddd7 100644 (file)
@@ -1,27 +1,43 @@
 window.addEventListener('load', function() {
     var links = document.getElementById("links").children[0].children;
     var home = document.getElementsByClassName("home");
-    var directions = [];
-    for(var i = 0; i < links.length - 1; i++) {
-        directions.push(links[i]);
-    }
-    for(var i = 0; i < home.length; i++) {
-        directions.push(home[i]);
-    }
     var menu = document.getElementById("menu");
-    var menuLoc = parseInt(getComputedStyle(menu).getPropertyValue("top"));
+    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 < directions.length; i++) {
-        directions[i].children[0].onclick = function(event) { 
+    for(var i = 0; i < links.length - 1; i++) {
+        links[i].children[0].onclick = function(event) { 
             event.preventDefault();
             var node = event.currentTarget;
-            if(menuLoc != 10) {
-                menuLoc = 0;
-                menu.setAttribute("class", "top");
-                window.history.pushState("object or string", "Title", node.href);
-            } else {
-                window.history.pushState("object or string", "Title", node.href);
-            }
+            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);