- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
Latest commit
196 lines (163 loc) · 6.18 KB
/
Copy pathscript.js
File metadata and controls
196 lines (163 loc) · 6.18 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// Function to load HTML components
asyncfunctionloadComponent(id,url){
try{
constresponse=awaitfetch(url);
constcontent=awaitresponse.text();
document.getElementById(id).innerHTML=content;
returntrue;
}catch(error){
console.error(`Error loading component from ${url}:`,error);
returnfalse;
}
}
// Initialize components and related features
asyncfunctioninitApp(){
// Disable automatic browser scroll restoration
if('scrollRestoration'inhistory){
history.scrollRestoration='manual';
}
constheaderLoaded=awaitloadComponent('header-placeholder','components/header.html');
constfooterLoaded=awaitloadComponent('footer-placeholder','components/footer.html');
if(headerLoaded){
setupHeaderFeatures();
}
// Ensure page starts at top if no hash is present
if(!window.location.hash){
window.scrollTo(0,0);
}
}
functionsetupHeaderFeatures(){
// Mobile Menu Toggle
constmenuToggle=document.getElementById('mobile-menu');
constnavLinks=document.querySelector('.nav-links');
if(menuToggle&&navLinks){
menuToggle.addEventListener('click',()=>{
// Toggle hidden class to show/hide menu
navLinks.classList.toggle('hidden');
navLinks.classList.toggle('flex');
// Animation for hamburger menu (simple rotation/transform if needed, or keep as is if CSS handles it)
constspans=menuToggle.querySelectorAll('span');
spans.forEach(span=>span.classList.toggle('bg-accent-gold'));// Example interaction feedback
});
}
// Close mobile menu when a link is clicked
document.querySelectorAll('.nav-links a').forEach(link=>{
link.addEventListener('click',()=>{
if(window.innerWidth<768){// Only on mobile
navLinks.classList.add('hidden');
navLinks.classList.remove('flex');
}
});
});
// Set active navigation link
constpath=window.location.pathname;
constcurrentPage=path.split('/').pop()||'index.html';
document.querySelectorAll('.nav-links a').forEach(link=>{
letnavTarget=link.getAttribute('data-nav');
// Match logic:
// 1. If navTarget is './', it matches 'index.html'
// 2. Exact match
constisHomeMatch=(navTarget==='./'||navTarget==='index.html')&&(currentPage==='index.html');
constisExactMatch=navTarget===currentPage;
if(isHomeMatch||isExactMatch){
link.classList.add('text-accent-gold','border-b-2','border-accent-gold');
link.classList.remove('text-text-dark');
}else{
link.classList.add('text-text-dark');
link.classList.remove('text-accent-gold','border-b-2','border-accent-gold');
}
});
// Navbar background change on scroll
constheader=document.querySelector('header');
if(header){
window.addEventListener('scroll',()=>{
if(window.scrollY>50){
header.classList.remove('py-4');
header.classList.add('py-2','shadow-md');
}else{
header.classList.add('py-4');
header.classList.remove('py-2','shadow-md');
}
});
}
}
// Run initialization
initApp();
// Smooth scrolling for navigation links (delegated to document for dynamic content)
document.addEventListener('click',(e)=>{
constanchor=e.target.closest('a[href^="#"]');
if(anchor){
consthref=anchor.getAttribute('href');
if(href==='#')return;
consttarget=document.querySelector(href);
if(target){
e.preventDefault();
window.scrollTo({
top: target.offsetTop-80,// Account for fixed header
behavior: 'smooth'
});
}
}
});
// Simple Form Submission Handling
// Form Submission Handling
constFORMEASY_URL="https://script.google.com/macros/s/AKfycbzbJOh3FoBl1o1CzJQJJPzVgqx9W0mxVzIwdrDY334gsCfZd1CuUxd68wKOLHQJd4I/exec";
constenquiryForm=document.getElementById('enquiryForm');
if(enquiryForm){
enquiryForm.addEventListener('submit',async(e)=>{
e.preventDefault();
constbtn=enquiryForm.querySelector('button');
constoriginalText=btn.textContent;
// Show loading state
btn.textContent='Sending...';
btn.disabled=true;
try{
constformData=newFormData(enquiryForm);
constdata=Object.fromEntries(formData);
constresponse=awaitfetch(FORMEASY_URL,{
method: 'POST',
headers: {
'Content-Type': 'text/plain;charset=utf-8',
},
body: JSON.stringify(data)
});
if(!response.ok){
thrownewError('Network response was not ok');
}
// Success
btn.textContent='Enquiry Sent Successfully! ✓';
btn.style.background='#28a745';
enquiryForm.reset();
setTimeout(()=>{
btn.textContent=originalText;
btn.style.background='';
btn.disabled=false;
},3000);
}catch(error){
console.error('Error submitting form:',error);
// Error feedback
btn.textContent='Error Sending. Try Again.';
btn.style.background='#dc3545';
setTimeout(()=>{
btn.textContent=originalText;
btn.style.background='';
btn.disabled=false;
},3000);
}
});
}
// Intersection Observer for scroll animations
constobserverOptions={
threshold: 0.1
};
constobserver=newIntersectionObserver((entries)=>{
entries.forEach(entry=>{
if(entry.isIntersecting){
entry.target.classList.add('visible');
}
});
},observerOptions);
document.querySelectorAll('section').forEach(section=>{
section.classList.add('animate-on-scroll');
observer.observe(section);
});