Spaces:
Running
Running
Download script.js from Persovt/conversion-catalyst-pro: direct link, hf CLI and curl.
- Browser
- Download file 10.5 kB
-
https://huggingface.co/spaces/Persovt/conversion-catalyst-pro/resolve/main/script.js
- Command line
-
hf download hf://spaces/Persovt/conversion-catalyst-pro/script.js
-
curl -L -o script.js https://huggingface.co/spaces/Persovt/conversion-catalyst-pro/resolve/main/script.js
10.5 kB
| // Main JavaScript for Conversion Catalyst Pro | |
| document.addEventListener('DOMContentLoaded', function() { | |
| // Initialize Feather Icons | |
| if (typeof feather !== 'undefined') { | |
| feather.replace(); | |
| } | |
| // Contact Form Handling | |
| const contactForm = document.getElementById('contactForm'); | |
| const formSuccess = document.getElementById('formSuccess'); | |
| const formError = document.getElementById('formError'); | |
| if (contactForm) { | |
| contactForm.addEventListener('submit', async function(e) { | |
| e.preventDefault(); | |
| // Get form data | |
| const formData = new FormData(contactForm); | |
| const data = Object.fromEntries(formData); | |
| // Simple validation | |
| if (!data.name || !data.email || !data.service || !data.message) { | |
| showFormError('Please fill in all required fields.'); | |
| return; | |
| } | |
| // Disable submit button and show loading | |
| const submitBtn = contactForm.querySelector('button[type="submit"]'); | |
| const originalText = submitBtn.innerHTML; | |
| submitBtn.innerHTML = '<i data-feather="loader" class="w-5 h-5 mr-2 animate-spin"></i>Sending...'; | |
| submitBtn.disabled = true; | |
| try { | |
| // In a real application, this would be an API call | |
| // For demo purposes, we'll simulate an API call | |
| await simulateApiCall(data); | |
| // Show success message | |
| showFormSuccess(); | |
| contactForm.reset(); | |
| // Hide success message after 5 seconds | |
| setTimeout(() => { | |
| formSuccess.classList.add('hidden'); | |
| }, 5000); | |
| } catch (error) { | |
| showFormError('Failed to send message. Please try again.'); | |
| } finally { | |
| // Reset button | |
| submitBtn.innerHTML = originalText; | |
| submitBtn.disabled = false; | |
| feather.replace(); | |
| } | |
| }); | |
| } | |
| // Form success/error functions | |
| function showFormSuccess() { | |
| formSuccess.classList.remove('hidden'); | |
| formError.classList.add('hidden'); | |
| } | |
| function showFormError(message) { | |
| formError.classList.remove('hidden'); | |
| formSuccess.classList.add('hidden'); | |
| if (message && formError.querySelector('p')) { | |
| formError.querySelector('p').textContent = message; | |
| } | |
| } | |
| // Simulate API call | |
| function simulateApiCall(data) { | |
| return new Promise((resolve) => { | |
| setTimeout(() => { | |
| console.log('Form submitted with data:', data); | |
| resolve({ success: true }); | |
| }, 1500); | |
| }); | |
| } | |
| // Animate stats counters on scroll | |
| const stats = document.querySelectorAll('.counter'); | |
| const observerOptions = { | |
| threshold: 0.5, | |
| rootMargin: '0px 0px -50px 0px' | |
| }; | |
| const observer = new IntersectionObserver((entries) => { | |
| entries.forEach(entry => { | |
| if (entry.isIntersecting) { | |
| const stat = entry.target; | |
| const targetValue = parseInt(stat.textContent); | |
| if (!stat.hasAttribute('data-animated')) { | |
| animateCounter(stat, targetValue); | |
| stat.setAttribute('data-animated', 'true'); | |
| } | |
| } | |
| }); | |
| }, observerOptions); | |
| stats.forEach(stat => observer.observe(stat)); | |
| function animateCounter(element, target) { | |
| let current = 0; | |
| const increment = target / 50; | |
| const timer = setInterval(() => { | |
| current += increment; | |
| if (current >= target) { | |
| current = target; | |
| clearInterval(timer); | |
| } | |
| element.textContent = Math.round(current) + (element.textContent.includes('+') ? '+' : | |
| element.textContent.includes('x') ? 'x' : ''); | |
| }, 30); | |
| } | |
| // Smooth scroll for anchor links | |
| document.querySelectorAll('a[href^="#"]').forEach(anchor => { | |
| anchor.addEventListener('click', function(e) { | |
| const href = this.getAttribute('href'); | |
| // Skip if it's just "#" | |
| if (href === '#') return; | |
| const targetElement = document.querySelector(href); | |
| if (targetElement) { | |
| e.preventDefault(); | |
| const headerHeight = document.querySelector('custom-navbar')?.offsetHeight || 80; | |
| const targetPosition = targetElement.getBoundingClientRect().top + window.pageYOffset - headerHeight; | |
| window.scrollTo({ | |
| top: targetPosition, | |
| behavior: 'smooth' | |
| }); | |
| // Update URL without page reload | |
| history.pushState(null, null, href); | |
| } | |
| }); | |
| }); | |
| // Add active class to nav links based on scroll position | |
| const sections = document.querySelectorAll('section[id]'); | |
| const navLinks = document.querySelectorAll('custom-navbar a[href^="#"]'); | |
| function highlightNavLink() { | |
| let current = ''; | |
| const scrollPos = window.scrollY + 100; | |
| sections.forEach(section => { | |
| const sectionTop = section.offsetTop; | |
| const sectionHeight = section.clientHeight; | |
| if (scrollPos >= sectionTop && scrollPos < sectionTop + sectionHeight) { | |
| current = section.getAttribute('id'); | |
| } | |
| }); | |
| navLinks.forEach(link => { | |
| link.classList.remove('active'); | |
| if (link.getAttribute('href') === `#${current}`) { | |
| link.classList.add('active'); | |
| } | |
| }); | |
| } | |
| window.addEventListener('scroll', highlightNavLink); | |
| // Parallax effect for hero section | |
| const heroSection = document.querySelector('section:first-of-type'); | |
| if (heroSection) { | |
| window.addEventListener('scroll', () => { | |
| const scrolled = window.pageYOffset; | |
| const rate = scrolled * -0.5; | |
| heroSection.style.transform = `translate3d(0px, ${rate}px, 0px)`; | |
| }); | |
| } | |
| // Initialize tooltips for icons | |
| const tooltips = document.querySelectorAll('[data-tooltip]'); | |
| tooltips.forEach(element => { | |
| element.addEventListener('mouseenter', function() { | |
| const tooltip = document.createElement('div'); | |
| tooltip.className = 'absolute z-50 px-3 py-2 text-sm font-medium text-white bg-gray-900 rounded-lg shadow-sm tooltip'; | |
| tooltip.textContent = this.getAttribute('data-tooltip'); | |
| tooltip.style.top = `${this.getBoundingClientRect().top - 40}px`; | |
| tooltip.style.left = `${this.getBoundingClientRect().left + this.offsetWidth / 2}px`; | |
| tooltip.style.transform = 'translateX(-50%)'; | |
| tooltip.setAttribute('id', 'current-tooltip'); | |
| document.body.appendChild(tooltip); | |
| }); | |
| element.addEventListener('mouseleave', function() { | |
| const tooltip = document.getElementById('current-tooltip'); | |
| if (tooltip) { | |
| tooltip.remove(); | |
| } | |
| }); | |
| }); | |
| // Add fade-in animations to elements on scroll | |
| const fadeElements = document.querySelectorAll('.fade-in-up'); | |
| const fadeObserver = new IntersectionObserver((entries) => { | |
| entries.forEach(entry => { | |
| if (entry.isIntersecting) { | |
| entry.target.classList.add('animate-fade-in'); | |
| } | |
| }); | |
| }, { | |
| threshold: 0.1, | |
| rootMargin: '0px 0px -50px 0px' | |
| }); | |
| fadeElements.forEach(element => fadeObserver.observe(element)); | |
| // Form validation improvements | |
| const emailInput = document.getElementById('email'); | |
| if (emailInput) { | |
| emailInput.addEventListener('blur', function() { | |
| const email = this.value; | |
| const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; | |
| if (email && !emailRegex.test(email)) { | |
| this.classList.add('border-red-500'); | |
| showInputError(this, 'Please enter a valid email address.'); | |
| } else { | |
| this.classList.remove('border-red-500'); | |
| removeInputError(this); | |
| } | |
| }); | |
| } | |
| function showInputError(input, message) { | |
| removeInputError(input); | |
| const errorDiv = document.createElement('div'); | |
| errorDiv.className = 'mt-1 text-sm text-red-400'; | |
| errorDiv.textContent = message; | |
| errorDiv.id = `${input.id}-error`; | |
| input.parentNode.appendChild(errorDiv); | |
| } | |
| function removeInputError(input) { | |
| const existingError = document.getElementById(`${input.id}-error`); | |
| if (existingError) { | |
| existingError.remove(); | |
| } | |
| } | |
| // Initialize service dropdown with Feather icon | |
| const serviceSelect = document.getElementById('service'); | |
| if (serviceSelect) { | |
| serviceSelect.addEventListener('change', function() { | |
| if (this.value) { | |
| this.classList.remove('text-gray-500'); | |
| this.classList.add('text-white'); | |
| } else { | |
| this.classList.add('text-gray-500'); | |
| this.classList.remove('text-white'); | |
| } | |
| }); | |
| } | |
| }); | |
| // Utility function to debounce scroll events | |
| function debounce(func, wait) { | |
| let timeout; | |
| return function executedFunction(...args) { | |
| const later = () => { | |
| clearTimeout(timeout); | |
| func(...args); | |
| }; | |
| clearTimeout(timeout); | |
| timeout = setTimeout(later, wait); | |
| }; | |
| } | |
| // Export functions for use in components if needed | |
| window.appUtils = { | |
| debounce, | |
| animateCounter: function(element, target) { | |
| let current = 0; | |
| const increment = target / 50; | |
| const timer = setInterval(() => { | |
| current += increment; | |
| if (current >= target) { | |
| current = target; | |
| clearInterval(timer); | |
| } | |
| element.textContent = Math.round(current) + (element.textContent.includes('+') ? '+' : | |
| element.textContent.includes('x') ? 'x' : ''); | |
| }, 30); | |
| } | |
| }; |