-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.js
More file actions
79 lines (68 loc) · 2.74 KB
/
menu.js
File metadata and controls
79 lines (68 loc) · 2.74 KB
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
// Logout function (defined globally)
function logout() {
// Remove login status from localStorage
localStorage.removeItem("isDoctorLoggedIn");
localStorage.removeItem("isPatientLoggedIn");
localStorage.removeItem("isAdminLoggedIn");
// Redirect to the login page
window.location.href = "doctor-login.html";
}
function toggleNav() {
var navToggle = document.getElementById("header_navigation");
if (navToggle.style.display === "block") {
navToggle.style.display = "none";
} else {
navToggle.style.display = "block";
}
}
// Check if the user is logged in and show menu parts
if (localStorage.getItem("isAdminLoggedIn") || localStorage.getItem("isPatientLoggedIn") || localStorage.getItem("isDoctorLoggedIn")) {
const adminOnly = document.getElementsByClassName("showloggedin");
// Convert to an array and loop through
Array.from(adminOnly).forEach(element => {
element.style.display = "block"; // Show the menu item
});
}
// If Admin is logged in
if (localStorage.getItem("isAdminLoggedIn")) {
const adminOnly = document.getElementsByClassName("adminonly");
// Convert to an array and loop through
Array.from(adminOnly).forEach(element => {
element.style.display = "block"; // Show the menu item
});
}
// If Patient is logged in
if (localStorage.getItem("isPatientLoggedIn")) {
const adminOnly = document.getElementsByClassName("patientonly");
// Convert to an array and loop through
Array.from(adminOnly).forEach(element => {
element.style.display = "block"; // Show the menu item
});
}
// If Doctor is logged in
if (localStorage.getItem("isDoctorLoggedIn") || localStorage.getItem("isAdminLoggedIn") ) {
const adminOnly = document.getElementsByClassName("docandadmins");
// Convert to an array and loop through
Array.from(adminOnly).forEach(element => {
element.style.display = "block"; // Show the menu item
});
}
else {
const adminOnly = document.getElementsByClassName("loggedoutall");
// Convert to an array and loop through
Array.from(adminOnly).forEach(element => {
element.style.display = "block"; // Show the menu item
});
}
// DOMCONTENTLOADED: run the following code when the html page has been fully loaded
// JavaScript to toggle the submenu
document.addEventListener('DOMContentLoaded', function () {
const toggleButtons = document.querySelectorAll('.toggleMenu');
const submenus = document.querySelectorAll('.submenu');
toggleButtons.forEach((button, index) => {
button.addEventListener('click', function () {
const submenu = submenus[index];
submenu.classList.toggle('show'); // Toggle the 'show' class to display or hide the submenu
});
});
});