File size: 1,655 Bytes
d6c8af7 |
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 |
// Shared functionality
document.addEventListener('DOMContentLoaded', () => {
// Scroll animations
const animateOnScroll = () => {
const elements = document.querySelectorAll('.scroll-animate');
elements.forEach(el => {
const elTop = el.getBoundingClientRect().top;
const isVisible = (elTop - window.innerHeight) < -100;
if (isVisible && !el.classList.contains('animate-fade-in')) {
el.classList.add('animate-fade-in');
}
});
};
window.addEventListener('scroll', animateOnScroll);
animateOnScroll(); // Run once on load
// Theme switcher
const themeToggle = document.getElementById('theme-toggle');
if (themeToggle) {
themeToggle.addEventListener('click', () => {
document.documentElement.classList.toggle('dark');
localStorage.setItem('theme', document.documentElement.classList.contains('dark') ? 'dark' : 'light');
});
}
});
// API Client
class AIForgeAPI {
constructor() {
this.baseUrl = 'https://api.aiforge.com/v1';
}
async getTemplates(category) {
const response = await fetch(`${this.baseUrl}/templates?category=${category}`);
return response.json();
}
async createProject(config) {
const response = await fetch(`${this.baseUrl}/projects`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${localStorage.getItem('token')}`
},
body: JSON.stringify(config)
});
return response.json();
}
} |