-
Notifications
You must be signed in to change notification settings - Fork 0
/
backstore_menu.js
48 lines (28 loc) · 1.14 KB
/
backstore_menu.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
let frontMenuButtonsFile;
if (window.location.host.match("localhost")) {
frontMenuButtonsFile = fetch('/Online-Grocery_Web-Programming/backstore-menu-buttons.json');
} else {
frontMenuButtonsFile = fetch('/backstore-menu-buttons.json');
}
window.addEventListener('load', function () {
frontMenuButtonsFile.then(response => {
return response.json();
}).then(jsonData => {
action(jsonData);
});
});
function action(data) {
let isLocalhost = window.location.host.match("localhost");
let frontMenuButtons = data;
let mClass = "menu-button";
let menu = document.getElementById("head");
menu.innerHTML =
"<label for='collapsible' class='menu-label'>Menu</label>";
for (const i in frontMenuButtons) {
if (isLocalhost) {
menu.innerHTML += "<a href=" + "'/Online-Grocery_Web-Programming/" + frontMenuButtons[i]["linkUrl"] + "' class='" + mClass + "'>" + frontMenuButtons[i]["name"] + "</a>";
} else {
menu.innerHTML += "<a href='." + frontMenuButtons[i]["linkUrl"] + "' class='" + mClass + "'>" + frontMenuButtons[i]["name"] + "</a>";
}
}
}