File size: 3,903 Bytes
950bce1 |
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 |
// Global JavaScript for Beck-Publishing
document.addEventListener('DOMContentLoaded', function() {
// Initialize animations
initAnimations();
// Initialize form handling
initForms();
// Initialize scroll effects
initScrollEffects();
// Initialize service worker for PWA (optional)
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js')
.then(() => console.log('Service Worker Registered'))
.catch(err => console.log('Service Worker Registration Failed: ', err));
}
});
function initAnimations() {
// Intersection Observer for scroll animations
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('animate-fade-in-up');
observer.unobserve(entry.target);
}
});
}, observerOptions);
// Observe elements with animation class
document.querySelectorAll('.animate-on-scroll').forEach(el => {
observer.observe(el);
});
}
function initForms() {
// Contact form handling
const contactForm = document.getElementById('contactForm');
if (contactForm) {
contactForm.addEventListener('submit', function(e) {
e.preventDefault();
const submitBtn = this.querySelector('button[type="submit"]');
const originalText = submitBtn.textContent;
// Show loading state
submitBtn.disabled = true;
submitBtn.innerHTML = '<div class="loading-spinner"></div> Processing...';
// Simulate form submission (replace with actual API call)
setTimeout(() => {
alert('Thank you for your message! I\'ll get back to you soon.');
contactForm.reset();
submitBtn.disabled = false;
submitBtn.textContent = originalText;
}, 2000);
});
}
}
function initScrollEffects() {
// Navbar scroll effect
let lastScrollY = window.scrollY;
const navbar = document.querySelector('custom-navbar');
window.addEventListener('scroll', () => {
if (!navbar) return;
const currentScrollY = window.scrollY;
if (currentScrollY > lastScrollY && currentScrollY > 100) {
navbar.style.transform = 'translateY(-100%)';
} else {
navbar.style.transform = 'translateY(0)';
}
lastScrollY = currentScrollY;
// Add shadow when scrolled
if (currentScrollY > 50) {
navbar.style.boxShadow = '0 4px 20px rgba(0, 0, 0, 0.1)';
} else {
navbar.style.boxShadow = 'none';
}
});
}
// Utility function for smooth scrolling
function smoothScrollTo(target) {
const element = document.querySelector(target);
if (element) {
element.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
}
// Debounce function for performance
function debounce(func, wait) {
let timeout;
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
}
// Format phone number
function formatPhoneNumber(phone) {
const cleaned = ('' + phone).replace(/\D/g, '');
const match = cleaned.match(/^(\d{3})(\d{3})(\d{4})$/);
if (match) {
return '(' + match[1] + ') ' + match[2] + '-' + match[3];
}
return phone;
}
// Email validation
function isValidEmail(email) {
const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return re.test(email);
} |