-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
64 lines (56 loc) · 2.67 KB
/
script.js
File metadata and controls
64 lines (56 loc) · 2.67 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
/**
* file: script.js
*
* Global client-side JavaScript for the Levensloop application.
* Handles UI interactions such as the responsive hamburger menu and dropdowns.
*/
document.addEventListener('DOMContentLoaded', () => {
/**
* Initializes the Hamburger Menu functionality.
* Toggles the 'active' class on the main navigation menu when the hamburger icon is clicked.
*/
const hamburgerMenu = document.getElementById('hamburger-menu');
const mainNav = document.querySelector('.main-nav');
if (hamburgerMenu && mainNav) {
hamburgerMenu.addEventListener('click', (event) => {
event.stopPropagation(); // Prevent this click from triggering document click
mainNav.classList.toggle('active');
});
}
/**
* Initializes the Media Dropdown Menu functionality.
* Toggles the 'open' class on the dropdown list item when the toggle link is clicked.
* Closes the dropdown when clicking outside.
*/
const mediaMenuToggle = document.getElementById('media-menu-toggle');
const mediaDropdown = document.getElementById('media-dropdown');
if (mediaMenuToggle && mediaDropdown) {
mediaMenuToggle.addEventListener('click', (event) => {
event.preventDefault(); // Prevent default link behavior
event.stopPropagation(); // Prevent this click from triggering document click immediately
const isOpen = mediaDropdown.classList.contains('open');
// Toggle the open class
if (isOpen) {
mediaDropdown.classList.remove('open');
mediaMenuToggle.setAttribute('aria-expanded', 'false');
} else {
mediaDropdown.classList.add('open');
mediaMenuToggle.setAttribute('aria-expanded', 'true');
}
});
// Close dropdown when clicking outside
document.addEventListener('click', (event) => {
if (mediaDropdown.classList.contains('open') && !mediaDropdown.contains(event.target)) {
mediaDropdown.classList.remove('open');
mediaMenuToggle.setAttribute('aria-expanded', 'false');
}
// Also close the mobile menu if clicking outside of it (optional but good UX)
// Checking if mainNav is active and click is outside mainNav and hamburger
if (mainNav && mainNav.classList.contains('active') &&
!mainNav.contains(event.target) &&
!hamburgerMenu.contains(event.target)) {
// mainNav.classList.remove('active'); // Commented out to be safe with existing behavior, strictly addressing Media dropdown
}
});
}
});