-
Notifications
You must be signed in to change notification settings - Fork 0
/
load-page.js
134 lines (130 loc) · 5.42 KB
/
load-page.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
128
129
130
131
132
133
134
function navBarLoad(type, page) {
const navBar = document.querySelector(".nav-links");
var list = [//Button icon is the homepage for index.html and about.html
'<div class="dropdown">',// ---dropdown 0
'<button class="dropbtn">Front End</button>',// button 1
'<div class="panel">',// panel 2
'<a class="nav-drop-link" href="front-end-about.html">What is Front end?</a>',
'<a class="nav-drop-link" href="html-about.html">HTML</a>',//3
'<a class="nav-drop-link" href="css-about.html">CSS</a>',//4
'<a class="nav-drop-link" href="js-about.html">Javascript</a>',//5
'</div>',//panel 6
'</div>',// --------dropdown 7
'<div class="dropdown">',// --------dropdown 8
'<button class="dropbtn">Back End</button>',// button 9
'<div class="panel">',// panel 10
'<a class="nav-drop-link" href="back-about.html">Coming Soon</a>',//11
'</div>',//panel 12
'</div>'//-------dropdown 13
];
if (type == "index") {
list.unshift('<a class="nav-link-home" href="about.html">About</a>')
}
if (type == "html") {
if (page == "about") {
list.unshift(
'<div class="dropdown">',
'<button class="dropbtn"><span class="selected">HTML</span></button> <',
'<div class="panel">',
'<a class="nav-drop-link active" href="html-about.html">About HTML</a>',
'<a class="nav-drop-link" href="html-tutorial.html">HTML Tutorial</a>',
'</div>',
'</div>'
)
}
if (page == "tutorial") {
list.unshift(
'<div class="dropdown">',
'<button class="dropbtn">HTML</button> <',
'<div class="panel">',
'<a class="nav-drop-link" href="html-about.html">About HTML</a>',
'<a class="nav-drop-link active" href="html-tutorial.html">HTML Tutorial</a>',
'</div>',
'</div>'
)
list.unshift(
'<div class="dropdown">',
'<button class="dropbtn"><span class="selected">Tutorials</span></button> < ',
'<div class="panel">',
'<a class="nav-drop-link" href="html-basics.html">The Basics</a>',
'<a class="nav-drop-link" href="html-semantics-and-non-semantics.html">Semantics and Non-Semantics</a>',
'</div>',
'</div>'
)
}
}
if (type == "css") {
if (page == "about") {
list.unshift(
'<div class="dropdown">',
'<button class="dropbtn"><span class="selected">CSS</span></button> <',
'<div class="panel">',
'<a class="nav-drop-link active" href="css-about.html">About CSS</a>',
'<a class="nav-drop-link" href="css-tutorial.html">CSS Tutorial</a>',
'</div>',
'</div>'
)
}
if (page == "tutorial") {
list.unshift(
'<div class="dropdown">',
'<button class="dropbtn">CSS</button> <',
'<div class="panel">',
'<a class="nav-drop-link" href="css-about.html">About CSS</a>',
'<a class="nav-drop-link active" href="css-tutorial.html">CSS Tutorial</a>',
'</div>',
'</div>'
)
list.unshift(
'<div class="dropdown">',
'<button class="dropbtn"><span class="selected">Tutorials</span></button> < ',
'<div class="panel">',
'<a class="nav-drop-link" href="css-basics.html">The Basics</a>',
'<a class="nav-drop-link" href="css-kinds-of-selectors.html">Kinds of Selectors</a>',
'</div>',
'</div>'
)
}
}
navBar.innerHTML = list.toString().replaceAll(",", " ");
//Program for the dropdown
var acc = document.getElementsByClassName("dropbtn");
var dropdown = document.getElementsByClassName("dropdown");
//Toggles the panel class
for (var i = 0; i < acc.length; i++) {
acc[i].addEventListener("click", function () {
var panel = this.nextElementSibling;
if (panel.style.display === "block") {
panel.style.display = "none"
} else {
removeAll();
panel.style.display = "block";
}
this.classList.toggle("active");
})
}
//Checks if a dropdown class is over the mouse
let isCursorInside = false
for (var i = 0; i < dropdown.length; i++) {
dropdown[i].addEventListener("mouseover", () => {
isCursorInside = true;
});
dropdown[i].addEventListener("mouseout", () => {
isCursorInside = false;
})
}
//Closes the dropdown and its class
document.addEventListener("click", () => {
if (!isCursorInside) {
removeAll(true);
}
})
//the function for closing the dropdown and its class
function removeAll(type) {
for (var i = 0; i < acc.length; i++) {
acc[i].classList.remove("active");
var panel = acc[i].nextElementSibling;
panel.style.display = "none";
}
}
}