]> nos-oignons.net Git - website.git/blobdiff - scripts.js
Menu + amélioration responsive.
[website.git] / scripts.js
diff --git a/scripts.js b/scripts.js
new file mode 100644 (file)
index 0000000..28f09b5
--- /dev/null
@@ -0,0 +1,32 @@
+document.addEventListener("DOMContentLoaded", function() {
+
+    // Add JS class
+    document.querySelector('body').classList.add('js');
+
+    // Create the dropdown base
+    var select = document.createElement("select");
+
+    // Create default option "Go to..."
+    var opt = document.createElement("option")
+    opt.setAttribute("selected", "selected")
+    opt.setAttribute("value", "")
+    opt.innerHTML = "Aller à ...";
+    select.appendChild(opt);
+
+    // Populate dropdown with menu items
+    [].forEach.call(document.querySelectorAll('nav.menu a'), function(el) {
+        var opt = document.createElement("option");
+        opt.setAttribute("value", el.href)
+        opt.innerHTML = el.text;
+        select.appendChild(opt);
+    });
+
+    // To make dropdown actually work
+    // To make more unobtrusive: http://css-tricks.com/4064-unobtrusive-page-changer/
+    select.addEventListener('change', function(el) {
+      window.location = select.value
+    });
+
+    // Add select to menuWrapper
+    document.querySelectorAll('nav.menu')[0].appendChild(select);
+});
\ No newline at end of file