-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
773 lines (660 loc) · 27.7 KB
/
script.js
File metadata and controls
773 lines (660 loc) · 27.7 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
// Small Batch Maps - Interactive JavaScript
// Namespace for all SBM functionality
window.SBM = {
// Debounce utility for performance
debounce: function(func, wait) {
let timeout;
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
},
// Scroll to section utility
scrollToSection: function(sectionId) {
const targetSection = document.getElementById(sectionId);
if (targetSection) {
const headerHeight = 80;
const targetPosition = targetSection.offsetTop - headerHeight;
window.scrollTo({
top: targetPosition,
behavior: 'smooth'
});
}
},
// Handle keyboard navigation for project items
handleProjectKeydown: function(event, url) {
if (event.key === 'Enter' || event.key === ' ') {
event.preventDefault();
window.open(url, '_blank');
}
},
// Show notification function
showNotification: function(message, type = 'info') {
const template = document.getElementById('notification-template');
if (!template) return;
const notification = template.querySelector('.notification').cloneNode(true);
// Set up notification
notification.classList.add(type);
notification.querySelector('.notification-message').textContent = message;
// Add close functionality
const closeBtn = notification.querySelector('.notification-close');
closeBtn.addEventListener('click', function() {
notification.classList.remove('show');
setTimeout(() => notification.remove(), 300);
});
// Add to DOM
document.body.appendChild(notification);
// Animate in
setTimeout(() => {
notification.classList.add('show');
}, 100);
// Auto remove after 5 seconds
setTimeout(() => {
if (notification.parentElement) {
notification.classList.remove('show');
setTimeout(() => notification.remove(), 300);
}
}, 5000);
},
// Toggle curriculum details
toggleCurriculumDetails: function() {
const details = document.getElementById('curriculum-details');
const toggle = document.getElementById('curriculum-toggle');
const expandText = toggle.querySelector('.expand-text');
const isExpanded = toggle.getAttribute('aria-expanded') === 'true';
if (isExpanded) {
// Collapse
details.classList.add('hidden');
toggle.setAttribute('aria-expanded', 'false');
expandText.textContent = 'View Curriculum Details';
} else {
// Expand
details.classList.remove('hidden');
toggle.setAttribute('aria-expanded', 'true');
expandText.textContent = 'Hide Curriculum Details';
}
},
// Toggle experience accordion
toggleExperienceAccordion: function(header) {
const isExpanded = header.getAttribute('aria-expanded') === 'true';
const contentId = header.getAttribute('aria-controls');
const content = document.getElementById(contentId);
if (isExpanded) {
// Collapse
header.setAttribute('aria-expanded', 'false');
content.classList.remove('expanded');
} else {
// Expand
header.setAttribute('aria-expanded', 'true');
content.classList.add('expanded');
}
}
};
document.addEventListener('DOMContentLoaded', function() {
// Mobile menu functionality
const mobileMenuBtn = document.getElementById('mobile-menu-btn');
const mobileMenu = document.getElementById('mobile-menu');
const hamburger = mobileMenuBtn.querySelector('.hamburger');
const header = document.querySelector('.header');
const hero = document.querySelector('#hero');
mobileMenuBtn.addEventListener('click', function() {
const isExpanded = mobileMenuBtn.getAttribute('aria-expanded') === 'true';
mobileMenuBtn.setAttribute('aria-expanded', !isExpanded);
mobileMenu.classList.toggle('hidden');
hamburger.classList.toggle('active');
// Focus management for accessibility
if (!isExpanded) {
// Menu is opening, focus first link
const firstLink = mobileMenu.querySelector('.nav-link');
if (firstLink) {
setTimeout(() => firstLink.focus(), 100);
}
}
});
// Close mobile menu when clicking on nav links
const mobileNavLinks = mobileMenu.querySelectorAll('a');
mobileNavLinks.forEach(link => {
link.addEventListener('click', function() {
mobileMenu.classList.add('hidden');
hamburger.classList.remove('active');
mobileMenuBtn.setAttribute('aria-expanded', 'false');
});
});
// Logo click handler
const logoLink = document.querySelector('.logo-link');
if (logoLink) {
logoLink.addEventListener('click', function(e) {
e.preventDefault();
// Show nav logo when logo is clicked
showNavLogo();
// Close any open service expansion
closeServiceExpansion();
// Scroll to top
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});
}
// Show nav logo when navigation is used
function showNavLogo() {
const navLogo = document.querySelector('.logo-image');
if (navLogo) {
navLogo.classList.add('visible');
}
}
// Smooth scrolling for navigation links
const navLinks = document.querySelectorAll('a[href^="#"]');
navLinks.forEach(link => {
link.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href').substring(1);
const targetSection = document.getElementById(targetId);
if (targetSection) {
// Show nav logo when any nav link is clicked
showNavLogo();
// Fixed header height
const headerHeight = 80;
const targetPosition = targetSection.offsetTop - headerHeight;
window.scrollTo({
top: targetPosition,
behavior: 'smooth'
});
}
});
});
// Experience accordion functionality
const experienceHeaders = document.querySelectorAll('.entry-header[role="button"]');
experienceHeaders.forEach(header => {
header.addEventListener('click', function() {
SBM.toggleExperienceAccordion(this);
});
header.addEventListener('keydown', function(event) {
if (event.key === 'Enter' || event.key === ' ') {
event.preventDefault();
SBM.toggleExperienceAccordion(this);
}
});
});
// Legacy service expansion functionality removed -
// New geospatial section uses direct navigation instead
// New geospatial section uses static layout - no expansion needed
// Intersection Observer for scroll animations
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver(function(entries) {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
}
});
}, observerOptions);
// Observe sections for animation
const sections = document.querySelectorAll('section');
sections.forEach(section => {
section.classList.add('fade-in-up');
observer.observe(section);
});
// Form validation utilities
const formValidation = {
validateName: function(value) {
if (!value.trim()) return 'Name is required';
if (value.trim().length < 2) return 'Name must be at least 2 characters';
return null;
},
validateEmail: function(value) {
if (!value.trim()) return 'Email is required';
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(value)) return 'Please enter a valid email address';
return null;
},
validateComment: function(value) {
if (!value.trim()) return 'Comment is required';
if (value.trim().length < 10) return 'Please provide more details (at least 10 characters)';
return null;
},
showFieldError: function(field, message) {
const errorElement = document.getElementById(field.id + '-error');
if (errorElement) {
errorElement.textContent = message;
field.classList.add('error');
field.classList.remove('success');
field.setAttribute('aria-invalid', 'true');
}
},
clearFieldError: function(field) {
const errorElement = document.getElementById(field.id + '-error');
if (errorElement) {
errorElement.textContent = '';
field.classList.remove('error');
field.classList.add('success');
field.setAttribute('aria-invalid', 'false');
}
},
validateField: function(field) {
let validator;
switch(field.id) {
case 'name':
validator = this.validateName;
break;
case 'email':
validator = this.validateEmail;
break;
case 'comment':
validator = this.validateComment;
break;
default:
return true;
}
const error = validator(field.value);
if (error) {
this.showFieldError(field, error);
return false;
} else {
this.clearFieldError(field);
return true;
}
}
};
// Add real-time validation to form fields
const formFields = document.querySelectorAll('#contact-form .form-input');
formFields.forEach(field => {
// Validate on blur (when user leaves field)
field.addEventListener('blur', function() {
formValidation.validateField(this);
});
// Clear error on input (as user types)
field.addEventListener('input', function() {
if (this.classList.contains('error')) {
// Only clear error state, don't validate until blur
this.classList.remove('error');
const errorElement = document.getElementById(this.id + '-error');
if (errorElement) {
errorElement.textContent = '';
}
this.setAttribute('aria-invalid', 'false');
}
});
});
// Contact form handling with Web3Forms
const contactForm = document.getElementById('contact-form');
contactForm.addEventListener('submit', function(e) {
e.preventDefault();
// Validate all fields before submission
let isValid = true;
formFields.forEach(field => {
if (!formValidation.validateField(field)) {
isValid = false;
}
});
if (!isValid) {
SBM.showNotification('Please correct the errors above and try again.', 'error');
// Focus first invalid field
const firstError = this.querySelector('.form-input.error');
if (firstError) {
firstError.focus();
}
return;
}
// Add loading state
const submitButton = this.querySelector('button[type="submit"]');
const buttonText = submitButton.querySelector('.button-text');
const buttonLoading = submitButton.querySelector('.button-loading');
submitButton.classList.add('loading');
submitButton.disabled = true;
// Collect form data
const formData = new FormData(this);
// Submit to Web3Forms
fetch(this.action, {
method: 'POST',
body: formData,
headers: {
'Accept': 'application/json'
}
})
.then(response => {
// Remove loading state
submitButton.classList.remove('loading');
submitButton.disabled = false;
if (response.ok) {
// Reset form and clear all validation states
this.reset();
formFields.forEach(field => {
field.classList.remove('success', 'error');
field.setAttribute('aria-invalid', 'false');
const errorElement = document.getElementById(field.id + '-error');
if (errorElement) {
errorElement.textContent = '';
}
});
// Show success message
showNotification('Thank you! Your message has been sent. I\'ll get back to you within 24 hours.', 'success');
// Focus back to the form for screen reader users
contactForm.focus();
} else {
response.json().then(data => {
if (Object.hasOwnProperty.call(data, 'errors')) {
showNotification(data["errors"].map(error => error["message"]).join(", "), 'error');
} else {
showNotification('Oops! There was a problem submitting your form', 'error');
}
});
}
})
.catch(error => {
// Remove loading state
submitButton.classList.remove('loading');
submitButton.disabled = false;
showNotification('Oops! There was a problem submitting your form', 'error');
});
});
// Active navigation highlight
function updateActiveNav() {
const sections = ['services', 'about', 'projects', 'contact'];
const navLinks = document.querySelectorAll('.nav-link');
const scrollPosition = window.scrollY + 100; // Offset for better detection
let currentSection = '';
sections.forEach(sectionId => {
const section = document.getElementById(sectionId);
if (section) {
const sectionTop = section.offsetTop;
const sectionHeight = section.offsetHeight;
if (scrollPosition >= sectionTop && scrollPosition < sectionTop + sectionHeight) {
currentSection = sectionId;
}
}
});
// Update nav link states
navLinks.forEach(link => {
const href = link.getAttribute('href');
if (href && href.startsWith('#')) {
const targetSection = href.substring(1);
if (targetSection === currentSection) {
link.classList.add('active');
} else {
link.classList.remove('active');
}
}
});
}
// Hero logo visibility based on scroll
function updateHeroLogoVisibility() {
const heroSection = document.getElementById('hero');
const heroContent = document.querySelector('.hero-content');
const heroLogo = document.querySelector('.hero-logo');
const navLogo = document.querySelector('.logo-image');
const logoLink = document.querySelector('.logo-link');
const headerHeight = 80;
if (heroSection && heroContent && heroLogo && navLogo && logoLink) {
const heroContentBottom = heroContent.offsetTop + heroContent.offsetHeight;
const heroBottom = heroSection.offsetTop + heroSection.offsetHeight;
const scrollPosition = window.scrollY + headerHeight;
// Show logo-link when hero-content is scrolled above the bottom of the nav
if (scrollPosition > heroContentBottom) {
logoLink.classList.add('visible');
} else {
logoLink.classList.remove('visible');
}
// Show logos when hero section is scrolled past the viewport (minus nav height)
if (scrollPosition > heroBottom) {
heroLogo.classList.add('visible');
navLogo.classList.add('visible');
} else {
heroLogo.classList.remove('visible');
navLogo.classList.remove('visible');
}
}
}
// Optimized scroll listener using debounce
const debouncedScrollHandler = SBM.debounce(() => {
updateActiveNav();
updateHeroLogoVisibility();
}, 16); // ~60fps
window.addEventListener('scroll', debouncedScrollHandler, { passive: true });
// Make showNotification available globally for backward compatibility
window.showNotification = SBM.showNotification;
// Enhanced keyboard navigation
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') {
// Close mobile menu
if (!mobileMenu.classList.contains('hidden')) {
mobileMenu.classList.add('hidden');
hamburger.classList.remove('active');
mobileMenuBtn.setAttribute('aria-expanded', 'false');
// Return focus to menu button
mobileMenuBtn.focus();
}
// Close expanded service section
if (serviceExpansion && !serviceExpansion.classList.contains('hidden')) {
closeServiceExpansion();
// Return focus to the expanded service button
const expandedButton = document.querySelector('.learn-more-btn[aria-expanded="true"]');
if (expandedButton) {
expandedButton.focus();
}
}
}
// Handle Enter and Space for project items (already handled in HTML with onkeydown)
// Handle Tab navigation for better accessibility
if (e.key === 'Tab') {
// Let the browser handle tab navigation naturally
// This ensures proper focus order
}
});
// Parallax effect for hero section (subtle) - integrated with main scroll handler
function updateParallax() {
if (hero) {
const scrolled = window.pageYOffset;
const parallax = scrolled * 0.5;
const heroBackground = hero.querySelector('.hero-bg');
if (heroBackground) {
heroBackground.style.transform = `translateY(${parallax}px)`;
}
}
}
// Update the scroll handler to include parallax
const debouncedScrollHandlerWithParallax = SBM.debounce(() => {
updateActiveNav();
updateHeroLogoVisibility();
updateParallax();
}, 16); // ~60fps
// Replace the previous scroll handler
window.removeEventListener('scroll', debouncedScrollHandler);
window.addEventListener('scroll', debouncedScrollHandlerWithParallax, { passive: true });
// Initialize active navigation
updateActiveNav();
// Service card expansion functionality
const serviceCards = document.querySelectorAll('.service-card');
const serviceExpansion = document.getElementById('service-expansion');
const expansionTitle = document.getElementById('expansion-title');
const closeExpansionBtn = document.getElementById('close-expansion');
// Handle service card clicks (entire card is clickable)
serviceCards.forEach(card => {
card.addEventListener('click', function() {
const button = this.querySelector('.learn-more-btn');
const serviceType = button.getAttribute('data-service');
const serviceTitle = this.getAttribute('data-title');
showServiceExpansion(serviceType, serviceTitle, button);
});
});
// Show service expansion with proper scroll positioning
function showServiceExpansion(serviceType, serviceTitle, button) {
// Update ARIA states for all buttons first
document.querySelectorAll('.learn-more-btn').forEach(btn => {
btn.setAttribute('aria-expanded', 'false');
});
// Hide all content sections first
const allContent = document.querySelectorAll('.expansion-content');
allContent.forEach(content => content.classList.add('hidden'));
// Show the selected content section
const selectedContent = document.getElementById(serviceType + '-content');
if (selectedContent) {
selectedContent.classList.remove('hidden');
}
// Update ARIA state for the clicked button
if (button) {
button.setAttribute('aria-expanded', 'true');
}
// Update title from data attribute
expansionTitle.textContent = serviceTitle || 'Service Details';
// Show expansion section with animation
serviceExpansion.classList.remove('hidden');
setTimeout(() => {
serviceExpansion.classList.add('show');
// Scroll to expansion after it's fully rendered
setTimeout(() => {
const headerHeight = 80;
const expansionRect = serviceExpansion.getBoundingClientRect();
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
const expansionTop = expansionRect.top + scrollTop - headerHeight - 20;
window.scrollTo({
top: expansionTop,
behavior: 'smooth'
});
// Focus the expansion for screen reader users
serviceExpansion.focus();
}, 200);
}, 10);
}
// Close expansion functionality
function closeServiceExpansion() {
if (serviceExpansion && !serviceExpansion.classList.contains('hidden')) {
// Reset all ARIA states
document.querySelectorAll('.learn-more-btn').forEach(btn => {
btn.setAttribute('aria-expanded', 'false');
});
// First scroll back to services section
const servicesSection = document.getElementById('services');
if (servicesSection) {
const headerHeight = 80;
const servicesTop = servicesSection.offsetTop - headerHeight;
window.scrollTo({
top: servicesTop,
behavior: 'smooth'
});
// Wait for scroll to complete, then hide expansion
setTimeout(() => {
serviceExpansion.classList.remove('show');
setTimeout(() => {
serviceExpansion.classList.add('hidden');
}, 300);
}, 500); // Wait for scroll animation to finish
} else {
// Fallback if services section not found
serviceExpansion.classList.remove('show');
setTimeout(() => {
serviceExpansion.classList.add('hidden');
}, 300);
}
}
}
if (closeExpansionBtn) {
closeExpansionBtn.addEventListener('click', closeServiceExpansion);
}
// Header scroll state functionality
function handleScroll() {
const scrollPosition = window.scrollY;
if (scrollPosition > 0) {
header.classList.add('scrolled');
} else {
header.classList.remove('scrolled');
}
// Update active navigation
updateActiveNav();
}
// Listen for scroll events
window.addEventListener('scroll', handleScroll);
// Initial check in case page is reloaded at a scroll position
handleScroll();
// Initial active nav update
updateActiveNav();
});
// Keep legacy function for backwards compatibility, but redirect to namespaced version
function scrollToSection(sectionId) {
SBM.scrollToSection(sectionId);
}
// Add to SBM namespace
SBM.copyEmailToClipboard = function(event) {
event.preventDefault();
const email = 'rgdonohue@gmail.com';
// Try to use the modern Clipboard API first
if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard.writeText(email).then(() => {
SBM.showNotification('Email copied to clipboard!', 'success');
}).catch(err => {
console.error('Failed to copy email: ', err);
fallbackCopyTextToClipboard(email);
});
} else {
// Fallback for older browsers or non-secure contexts
fallbackCopyTextToClipboard(email);
}
};
// Global function for copying email to clipboard (legacy compatibility)
function copyEmailToClipboard(event) {
SBM.copyEmailToClipboard(event);
}
// Fallback function for copying text to clipboard
function fallbackCopyTextToClipboard(text) {
const textArea = document.createElement('textarea');
textArea.value = text;
// Avoid scrolling to bottom
textArea.style.top = '0';
textArea.style.left = '0';
textArea.style.position = 'fixed';
textArea.style.opacity = '0';
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
const successful = document.execCommand('copy');
if (successful) {
SBM.showNotification('Email copied to clipboard!', 'success');
} else {
SBM.showNotification('Failed to copy email. Please copy manually: rgdonohue@gmail.com', 'error');
}
} catch (err) {
console.error('Fallback: Oops, unable to copy', err);
SBM.showNotification('Failed to copy email. Please copy manually: rgdonohue@gmail.com', 'error');
}
document.body.removeChild(textArea);
}
// Add cartographic animation enhancements when page loads
document.addEventListener('DOMContentLoaded', function() {
// Add subtle cartographic interactions to workflow steps
const workflowSteps = document.querySelectorAll('.workflow-step');
workflowSteps.forEach((step, index) => {
// Stagger the initial animation slightly
step.style.animationDelay = `${index * 0.1}s`;
// Add hover enhancement for cartographic feel
step.addEventListener('mouseenter', function() {
this.style.transform = 'translateY(-8px) rotateX(2deg) rotateY(2deg)';
});
step.addEventListener('mouseleave', function() {
this.style.transform = '';
});
});
// Enhanced compass rose interactivity
const compassRose = document.querySelector('.compass-rose');
if (compassRose) {
let compassRotation = 0;
compassRose.addEventListener('click', function() {
compassRotation += 45;
this.style.transform = `rotate(${compassRotation}deg) scale(1.1)`;
setTimeout(() => {
this.style.transform = `rotate(${compassRotation}deg)`;
}, 200);
});
}
});
// Preload images and resources
window.addEventListener('load', function() {
// Add any resource preloading logic here
console.log('Small Batch Maps website loaded successfully!');
});