Spaces:
Running
Running
File size: 3,767 Bytes
0233a8a | 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 |
// Form handlers and API integration
const handleSignup = async (email, plan = 'free') => {
try {
const response = await fetch('/api/signup', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ email, plan }),
});
if (response.ok) {
window.location.href = '/dashboard';
} else {
const errorData = await response.json();
throw new Error(errorData.message || 'Signup failed');
}
} catch (error) {
alert(error.message);
}
};
const handleDemoRequest = async (email) => {
try {
const response = await fetch('/api/request-demo', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ email }),
});
if (response.ok) {
alert('Demo scheduled! We\'ll contact you shortly.');
} else {
const errorData = await response.json();
throw new Error(errorData.message || 'Request failed');
}
} catch (error) {
alert(error.message);
}
};
// Dark mode toggle functionality
document.addEventListener('DOMContentLoaded', function() {
const darkModeToggle = document.getElementById('darkModeToggle');
// Setup form handlers
document.querySelectorAll('.signup-form').forEach(form => {
form.addEventListener('submit', async (e) => {
e.preventDefault();
const email = form.querySelector('input[type="email"]').value;
const plan = form.dataset.plan || 'free';
await handleSignup(email, plan);
});
});
document.querySelectorAll('.demo-form').forEach(form => {
form.addEventListener('submit', async (e) => {
e.preventDefault();
const email = form.querySelector('input[type="email"]').value;
await handleDemoRequest(email);
});
});
// Check for saved user preference
if (localStorage.getItem('darkMode') === 'enabled') {
document.documentElement.classList.add('dark');
if (darkModeToggle) darkModeToggle.checked = true;
}
// Toggle dark mode
if (darkModeToggle) {
darkModeToggle.addEventListener('change', function() {
if (this.checked) {
document.documentElement.classList.add('dark');
localStorage.setItem('darkMode', 'enabled');
} else {
document.documentElement.classList.remove('dark');
localStorage.setItem('darkMode', 'disabled');
}
});
}
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href');
if (targetId === '#') return;
const targetElement = document.querySelector(targetId);
if (targetElement) {
targetElement.scrollIntoView({
behavior: 'smooth'
});
}
});
});
// Animation for pricing cards
const pricingCards = document.querySelectorAll('.pricing-card');
pricingCards.forEach(card => {
card.addEventListener('mouseenter', () => {
card.classList.add('shadow-lg');
card.classList.remove('shadow-md');
});
card.addEventListener('mouseleave', () => {
card.classList.remove('shadow-lg');
card.classList.add('shadow-md');
});
});
}); |