-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
58 lines (51 loc) · 1.93 KB
/
Copy pathscript.js
File metadata and controls
58 lines (51 loc) · 1.93 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
// WebInstant Base Script
document.addEventListener('DOMContentLoaded', () => {
/* ===== Dynamic Year Update ===== */
const currentYear = new Date().getFullYear();
document.querySelectorAll('[id^="year"]').forEach(el => {
el.textContent = currentYear;
});
/* ===== Navigation Toggle (Hamburger Menu) ===== */
const hamburgerBtn = document.getElementById('hamburger');
const mainNav = document.getElementById('mainNav');
if (hamburgerBtn && mainNav) {
hamburgerBtn.addEventListener('click', (e) => {
e.stopPropagation(); // Prevent event from bubbling up
mainNav.classList.toggle('show');
hamburgerBtn.classList.toggle('active');
});
// Close nav when clicking outside (mobile only)
document.addEventListener('click', (e) => {
if (!mainNav.contains(e.target) && !hamburgerBtn.contains(e.target)) {
mainNav.classList.remove('show');
hamburgerBtn.classList.remove('active');
}
});
// Close nav when clicking a link (mobile UX)
mainNav.querySelectorAll('.nav-link').forEach(link => {
link.addEventListener('click', () => {
if (mainNav.classList.contains('show')) {
mainNav.classList.remove('show');
hamburgerBtn.classList.remove('active');
}
});
});
}
/* ===== Highlight Active Navigation Link ===== */
const navLinks = document.querySelectorAll('.main-nav .nav-link');
const currentPath = location.pathname.split('/').pop() || 'index.html';
navLinks.forEach(link => {
if (link.getAttribute('href') === currentPath) {
link.classList.add('active');
}
});
/* ===== Form Submission Handler ===== */
const forms = document.querySelectorAll('form');
forms.forEach(form => {
form.addEventListener('submit', e => {
e.preventDefault();
alert('✅ Thanks! Your message is ready to send.');
form.reset();
});
});
});