| | |
| |
|
| | |
| | document.addEventListener('DOMContentLoaded', function() { |
| | initializeApp(); |
| | }); |
| |
|
| | function initializeApp() { |
| | console.log('CreatorVerse Hub initialized'); |
| | |
| | |
| | setupScrollAnimations(); |
| | |
| | |
| | setupInteractiveElements(); |
| | |
| | |
| | setupMobileNavigation(); |
| | } |
| |
|
| | |
| | function setupScrollAnimations() { |
| | const observerOptions = { |
| | threshold: 0.1, |
| | rootMargin: '0px 0px -50px 0px' |
| | }; |
| |
|
| | const observer = new IntersectionObserver(function(entries) { |
| | entries.forEach(function(entry) { |
| | if (entry.isIntersecting) { |
| | entry.target.classList.add('fade-in-up'); |
| | } |
| | }); |
| | }, observerOptions); |
| |
|
| | |
| | document.querySelectorAll('.animate-on-scroll').forEach(function(el) { |
| | observer.observe(el); |
| | }); |
| | } |
| |
|
| | |
| | function setupInteractiveElements() { |
| | |
| | const creatorCards = document.querySelectorAll('.creator-card'); |
| | creatorCards.forEach(function(card) { |
| | card.addEventListener('click', function() { |
| | const creatorLink = this.querySelector('a').href; |
| | window.location.href = creatorLink; |
| | }); |
| | }); |
| |
|
| | |
| | const searchInput = document.getElementById('searchInput'); |
| | if (searchInput) { |
| | searchInput.addEventListener('input', debounce(function(e) { |
| | performSearch(e.target.value); |
| | }, 300)); |
| | } |
| | } |
| |
|
| | |
| | function setupMobileNavigation() { |
| | const mobileMenuButton = document.getElementById('mobileMenuButton'); |
| | const mobileMenu = document.getElementById('mobileMenu'); |
| |
|
| | if (mobileMenuButton && mobileMenu) { |
| | mobileMenuButton.addEventListener('click', function() { |
| | mobileMenu.classList.toggle('hidden'); |
| | }); |
| | } |
| | } |
| |
|
| | |
| | function performSearch(query) { |
| | if (query.length < 2) return; |
| |
|
| | console.log('Searching for:', query); |
| | |
| | |
| | |
| | showNotification(`Searching for "${query}"...`); |
| | } |
| |
|
| | |
| | function showNotification(message, type = 'info') { |
| | |
| | const notification = document.createElement('div'); |
| | notification.className = `fixed top-4 right-4 p-4 rounded-lg shadow-lg z-50 transform transition-transform duration-300 ${ |
| | type === 'error' ? 'bg-red-500' : |
| | type === 'success' ? 'bg-green-500' : 'bg-primary' |
| | } text-white`; |
| | notification.textContent = message; |
| | |
| | document.body.appendChild(notification); |
| | |
| | |
| | setTimeout(function() { |
| | notification.style.transform = 'translateX(100%)'; |
| | setTimeout(function() { |
| | if (notification.parentNode) { |
| | notification.parentNode.removeChild(notification); |
| | }, 300); |
| | }, 3000); |
| | } |
| |
|
| | |
| | function debounce(func, wait) { |
| | let timeout; |
| | return function executedFunction(...args) { |
| | const later = function() { |
| | clearTimeout(timeout); |
| | func(...args); |
| | }; |
| | clearTimeout(timeout); |
| | timeout = setTimeout(later, wait); |
| | }; |
| | } |
| |
|
| | |
| | async function fetchFeaturedCreators() { |
| | try { |
| | |
| | const response = await fetch('/api/creators/featured'); |
| | const creators = await response.json(); |
| | return creators; |
| | } catch (error) { |
| | console.error('Error fetching featured creators:', error); |
| | return []; |
| | } |
| | } |
| |
|
| | |
| | function checkAuthState() { |
| | const token = localStorage.getItem('authToken'); |
| | if (token) { |
| | updateUIForLoggedInUser(); |
| | } else { |
| | updateUIForGuest(); |
| | } |
| | } |
| |
|
| | function updateUIForLoggedInUser() { |
| | const authButtons = document.querySelectorAll('.auth-buttons'); |
| | authButtons.forEach(function(container) { |
| | container.innerHTML = ` |
| | <a href="/profile" class="bg-secondary hover:bg-yellow-500 text-white font-bold py-2 px-6 rounded-full transition duration-300"> |
| | My Profile |
| | </a> |
| | `; |
| | }); |
| | } |
| |
|
| | function updateUIForGuest() { |
| | const authButtons = document.querySelectorAll('.auth-buttons'); |
| | authButtons.forEach(function(container) { |
| | container.innerHTML = ` |
| | <a href="/login" class="text-dark hover:text-primary font-semibold transition duration-300"> |
| | Log In |
| | </a> |
| | <a href="/signup" class="bg-primary hover:bg-purple-600 text-white font-bold py-2 px-6 rounded-full transition duration-300"> |
| | Sign Up |
| | </a> |
| | `; |
| | }); |
| | } |
| |
|
| | |
| | window.CreatorVerse = { |
| | showNotification, |
| | fetchFeaturedCreators, |
| | checkAuthState |
| | }; |