// ShortForge AI – Landing page JS document.getElementById('demoBtn').addEventListener('click', () => { document.getElementById('demoSection').classList.toggle('hidden'); }); async loadTemplates() { this.showLoading(true); // Simulate API call with generated images const categories = ['nature', 'technology', 'people', 'abstract', 'minimal']; const sizes = ['200x200', '320x240', '640x360', '1024x576', '1200x630']; const templates = []; for (let i = 0; i < 20; i++) { const category = categories[Math.floor(Math.random() * categories.length)]; const size = sizes[Math.floor(Math.random() * sizes.length)]; const seed = Math.floor(Math.random() * 999) + 1; templates.push({ id: i + 1, title: `${category.charAt(0).toUpperCase() + category.slice(1)} Template ${i + 1}`, category: category, size: size, image: `http://static.photos/${category}/${size}/${seed}`, downloads: Math.floor(Math.random() * 1000), likes: Math.floor(Math.random() * 500), tags: [category, 'template', 'ai-generated'] }); } this.templates = templates; this.renderTemplates(); this.showLoading(false); } renderTemplates() { const container = document.getElementById('templatesContainer'); const filteredTemplates = this.filterTemplates(); container.innerHTML = filteredTemplates.map(template => `
${template.title}
${template.size}

${template.title}

${template.downloads} ${template.likes}
${template.tags.map(tag => ` ${tag} `).join('')}
`).join(''); this.attachCardEvents(); feather.replace(); } filterTemplates() { return this.templates.filter(template => { const categoryMatch = !this.currentCategory || template.category === this.currentCategory; const sizeMatch = !this.currentSize || template.size === this.currentSize; return categoryMatch && sizeMatch; }); } attachCardEvents() { document.querySelectorAll('.template-card').forEach(card => { card.addEventListener('click', (e) => { if (!e.target.closest('.like-btn')) { const templateId = card.dataset.id; this.openTemplateModal(templateId); } }); }); document.querySelectorAll('.like-btn').forEach(btn => { btn.addEventListener('click', (e) => { e.stopPropagation(); const templateId = btn.dataset.id; this.toggleLike(templateId); }); }); } openTemplateModal(templateId) { const template = this.templates.find(t => t.id == templateId); if (!template) return; const modal = document.createElement('div'); modal.className = 'fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4'; modal.innerHTML = `
${template.title}

${template.title}

Category

${template.category}

Size

${template.size}

Downloads

${template.downloads}

Likes

${template.likes}

`; document.body.appendChild(modal); modal.querySelector('button').addEventListener('click', () => { document.body.removeChild(modal); }); modal.addEventListener('click', (e) => { if (e.target === modal) { document.body.removeChild(modal); } }); feather.replace(); } toggleLike(templateId) { const template = this.templates.find(t => t.id == templateId); if (template) { template.likes += 1; this.renderTemplates(); } } setupEventListeners() { document.getElementById('gridView').addEventListener('click', () => { this.currentView = 'grid'; document.getElementById('gridView').className = 'px-6 py-3 bg-blue-500 text-white rounded-lg hover:bg-blue-600 transition-colors'; document.getElementById('listView').className = 'px-6 py-3 bg-gray-300 dark:bg-gray-700 text-gray-700 dark:text-gray-300 rounded-lg hover:bg-gray-400 dark:hover:bg-gray-600 transition-colors'; }); document.getElementById('listView').addEventListener('click', () => { this.currentView = 'list'; document.getElementById('listView').className = 'px-6 py-3 bg-blue-500 text-white rounded-lg hover:bg-blue-600 transition-colors'; document.getElementById('gridView').className = 'px-6 py-3 bg-gray-300 dark:bg-gray-700 text-gray-700 dark:text-gray-300 rounded-lg hover:bg-gray-400 dark:hover:bg-gray-600 transition-colors'; }); document.getElementById('categoryFilter').addEventListener('change', (e) => { this.currentCategory = e.target.value; this.renderTemplates(); }); document.getElementById('sizeFilter').addEventListener('change', (e) => { this.currentSize = e.target.value; this.renderTemplates(); }); } setupThemeToggle() { const themeToggle = document.createElement('button'); themeToggle.id = 'themeToggle'; themeToggle.className = 'fixed bottom-4 right-4 bg-gray-800 dark:bg-gray-200 text-white dark:text-gray-800 p-3 rounded-full shadow-lg hover:shadow-xl transition-all'; themeToggle.innerHTML = ''; document.body.appendChild(themeToggle); themeToggle.addEventListener('click', () => { document.documentElement.classList.toggle('dark'); const isDark = document.documentElement.classList.contains('dark'); themeToggle.innerHTML = isDark ? '' : ''; feather.replace(); }); } showLoading(show) { const spinner = document.getElementById('loadingSpinner'); spinner.classList.toggle('hidden', !show); } } // Initialize the app document.addEventListener('DOMContentLoaded', () => { new TemplateManager(); });