-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommon.js
More file actions
51 lines (46 loc) · 2.01 KB
/
common.js
File metadata and controls
51 lines (46 loc) · 2.01 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
// Mobile menu toggle
document.addEventListener('DOMContentLoaded', function() {
const mobileMenuButton = document.getElementById('mobileMenuButton');
const navLinks = document.getElementById('navLinks');
if (mobileMenuButton && navLinks) {
mobileMenuButton.addEventListener('click', function(e) {
e.preventDefault();
e.stopPropagation();
navLinks.classList.toggle('active');
});
// Close menu when clicking outside
document.addEventListener('click', function(event) {
if (!event.target.closest('.navbar') && navLinks.classList.contains('active')) {
navLinks.classList.remove('active');
}
});
// Close menu when clicking a link
const navItems = navLinks.querySelectorAll('a');
navItems.forEach(item => {
item.addEventListener('click', function() {
if (!item.parentElement.classList.contains('tutdropdown')) {
navLinks.classList.remove('active');
}
});
});
// Handle dropdown menus on mobile
const dropdowns = document.querySelectorAll('.tutdropdown');
dropdowns.forEach(dropdown => {
const dropdownLink = dropdown.querySelector('a');
if (dropdownLink) {
dropdownLink.addEventListener('click', function(e) {
if (window.innerWidth <= 768) {
e.preventDefault();
dropdown.classList.toggle('active');
// Close other open dropdowns
dropdowns.forEach(otherDropdown => {
if (otherDropdown !== dropdown && otherDropdown.classList.contains('active')) {
otherDropdown.classList.remove('active');
}
});
}
});
}
});
}
});