You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
First-Website/resources/js/insertNavbar.js

92 lines
2.5 KiB

var c = document.createElement.bind(document);
var d = document.getElementById.bind(document);
var g = document.querySelector.bind(document);
// Insert nav tag
var navigation = c("nav")
navigation.className = "navigation"
5 years ago
var navbarList = c("ul")
navbarList.className = "navbarList"
navigation.appendChild(navbarList)
5 years ago
document.body.appendChild(navigation)
5 years ago
// Opacity
5 years ago
var opacity = c("div")
opacity.className = "opacityMenu lowerIndex menu"
document.body.appendChild(opacity)
5 years ago
// Hamburger Menu
var hamburger = c("i")
hamburger.className = "fas fa-bars fa-2x"
navigation.prepend(hamburger)
5 years ago
// Search
5 years ago
var search = c("input")
search.className = "searchBar"
5 years ago
search.placeholder = "Vul een zoek opdracht of url in"
search.type = "text"
navigation.appendChild(search)
5 years ago
g(".searchBar").addEventListener("keyup",searchEnter)
function searchEnter(key) {
5 years ago
if(key.key == "Enter") {
5 years ago
var search = g(".searchBar").value;
5 years ago
var containsDot = search.indexOf(".");
if (search !== "") {
if (containsDot > -1) {
open("http://" + search);
}
else {
open("https://www.google.com/search?q=" + search);
}
}
}
if (key.key == "Escape") {
closeSearch()
}
}
// Create Navbar
Navbar.forEach(i=>{
var navList = c("li")
navList.className = "navList"
var navButton = c("button");
navButton.className = "navbarbutton"
5 years ago
navButton.innerHTML = "<i class='" + i.icon + " fa-lg'></i>" + i.name
if (i.link) {
var navLink = c("a");
navLink.href = i.link
navLink.appendChild(navButton);
navButton = navLink
}
if (i.desc) {
navButton.title = i.desc
}
navList.appendChild(navButton)
var dropdownList = c("ul")
dropdownList.className = "dropdownList"
5 years ago
dropdownList.style = "display: none;"
if (typeof i.dropdown == "object") {
i.dropdown.forEach(d=>{
var dropdownListItem = c("li");
// Dropdown button
var dropdownButton = c("button");
5 years ago
dropdownButton.innerHTML = "<i class='" + d.icon + " fa-lg'></i>" + d.name
dropdownButton.className = "dropdownButton"
if (d.desc) {
dropdownButton.title = d.desc
}
if (d.link) {
var link = c("a");
link.href = d.link
link.appendChild(dropdownButton);
dropdownButton = link
}
dropdownListItem.appendChild(dropdownButton);
dropdownList.appendChild(dropdownListItem);
})
}
5 years ago
navList.appendChild(dropdownList)
navbarList.appendChild(navList);
})