-
Notifications
You must be signed in to change notification settings - Fork 0
/
dm-nav-common.js
127 lines (88 loc) · 3.5 KB
/
dm-nav-common.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Tilføjer logo til headeren
window.onload = function logoElement(){
let logo = document.createElement("img");
logo.setAttribute("src", "../img/logopurepinkbg.png");
logo.setAttribute("class", "logo");
let header = document.getElementById("header");
header.appendChild(logo);
header.innerHTML += "<a href='https://www.linkedin.com/in/paulineholm/' class='personal-link'>Pauline Holm 👩🏻💻</a>"
// Menu
let dmClass = ".dm-nav";
let dmPages = [
["Home", "../index.html"],
["About", "../about/index.html"],
["Contact", "../contact/index.html"],
]
let dmParent = document.querySelector(dmClass);
let dmHTML = `<ul class="dm-menu">`;
let dmUrl = window.location.pathname;
let dmFileName = dmUrl.substring(dmUrl.lastIndexOf("/")+1);
dmPages.forEach(function(element){
let dmLinkClass = "";
if(dmFileName == element[1]){
dmLinkClass = "selected";
}
dmHTML += `
<li class="dm-menu-item">
<a href="${element[1]}" class="${dmLinkClass}">${element[0]}</a>
</li>
`;
});
dmHTML += `</ul>`;
dmParent.innerHTML = dmHTML;
// Søgebar
let search = document.createElement("img");
let closeBtn = document.getElementById("closesrchbtn");
search.setAttribute("src", "../img/searchicon.png");
search.setAttribute("class", "search");
//search.setAttribute("onclick", "openSearch()");
header.appendChild(search);
search.addEventListener("click", function(){
document.getElementById("searchOverlay").style.display = "block";
});
closeBtn.addEventListener("click", function(){
document.getElementById("searchOverlay").style.display = "none";
});
// Sidebar
let sideOverlay = document.getElementById("sideOverlay");
let sideBar = document.getElementById("sideBar");
let bodyBgStyle = document.body.style.backgroundColor;
let openSidebtn = document.createElement("img");
//let closeSideBtn = document.getElementById("closesrchbtn");
openSidebtn.setAttribute("src", "../img/star.png");
openSidebtn.setAttribute("class", "sideopenbtn");
openSidebtn.setAttribute("id", "sideOverOpenBtn");
header.appendChild(openSidebtn);
function openNav() {
sideOverlay.style.width = "100%";
sideBar.style.width= "350px";
//document.querySelector(".main").style.marginRight = "350px";
bodyBgStyle = "rgba(0,0,0,0.4)";
}
openSidebtn.addEventListener("click", function(){
openNav();
});
let closeSidebtn = document.getElementById("closeoverbtn");
function closeNav() {
sideOverlay.style.width = "0";
sideBar.style.width= "0";
bodyBgStyle = "white";
}
closeSidebtn.addEventListener("click",function(){
closeNav();
});
// Media queries dm-menu
let burgerMenu = document.createElement("img");
burgerMenu.setAttribute("src", "../img/burgermenu.png");
burgerMenu.setAttribute("class", "burgermenu");
let menuMobil = document.querySelector(".mobile-menu-overlay");
let mmCloseBtn = document.querySelector(".dmoverclosebtn");
//search.setAttribute("onclick", "openSearch()");
header.appendChild(burgerMenu);
burgerMenu.addEventListener("click", function(){
menuMobil.style.display = "block";
mmCloseBtn.addEventListener("click", function(){
menuMobil.style.display = "none";
});
});
}