| |
|
|
| document.addEventListener('DOMContentLoaded', function() { |
| |
| if (typeof feather !== 'undefined') { |
| feather.replace(); |
| } |
|
|
| |
| 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) { |
| window.scrollTo({ |
| top: targetElement.offsetTop - 80, |
| behavior: 'smooth' |
| }); |
| } |
| }); |
| }); |
|
|
| |
| const projectCards = document.querySelectorAll('.project-card'); |
| projectCards.forEach(card => { |
| card.addEventListener('mouseenter', () => { |
| card.classList.add('hover-card'); |
| }); |
| |
| card.addEventListener('mouseleave', () => { |
| card.classList.remove('hover-card'); |
| }); |
| }); |
|
|
| |
| const searchInput = document.querySelector('#navSearch'); |
| if (searchInput) { |
| searchInput.addEventListener('input', debounce(function() { |
| const query = this.value.trim(); |
| if (query.length > 2) { |
| performSearch(query); |
| } |
| }, 300)); |
| } |
|
|
| |
| const themeToggle = document.querySelector('#themeToggle'); |
| if (themeToggle) { |
| themeToggle.addEventListener('click', function() { |
| document.documentElement.classList.toggle('dark'); |
| |
| const isDark = document.documentElement.classList.contains('dark'); |
| localStorage.setItem('theme', isDark ? 'dark' : 'light'); |
| |
| |
| showNotification('Theme switched to ' + (isDark ? 'dark' : 'light') + ' mode'); |
| }); |
| } |
|
|
| |
| const savedTheme = localStorage.getItem('theme'); |
| if (savedTheme === 'dark') { |
| document.documentElement.classList.add('dark'); |
| } |
| }); |
|
|
| |
| function debounce(func, wait) { |
| let timeout; |
| return function executedFunction(...args) { |
| const later = () => { |
| clearTimeout(timeout); |
| func.apply(this, args); |
| }; |
| clearTimeout(timeout); |
| timeout = setTimeout(later, wait); |
| }; |
| } |
|
|
| |
| async function performSearch(query) { |
| console.log('Searching for:', query); |
| |
| |
| |
| |
| |
| } |
|
|
| |
| function showNotification(message, type = 'info') { |
| |
| const notification = document.createElement('div'); |
| notification.className = `fixed top-24 right-6 px-6 py-3 rounded-xl shadow-xl z-50 transform translate-x-full transition-transform duration-300 ${type === 'info' ? 'bg-rose-600' : 'bg-red-600'} text-white`; |
| notification.textContent = message; |
| |
| |
| document.body.appendChild(notification); |
| |
| |
| setTimeout(() => { |
| notification.style.transform = 'translateX(0)'; |
| }, 10); |
| |
| |
| setTimeout(() => { |
| notification.style.transform = 'translateX(100%)'; |
| setTimeout(() => { |
| document.body.removeChild(notification); |
| }, 300); |
| }, 3000); |
| } |
|
|
| |
| async function fetchProjects() { |
| try { |
| |
| const response = await fetch('https://api.github.com/search/repositories?q=topic:frontend&sort=stars&order=desc&per_page=6'); |
| const data = await response.json(); |
| return data.items || []; |
| } catch (error) { |
| console.error('Error fetching projects:', error); |
| return []; |
| } |
| } |
|
|
| |
| document.addEventListener('submit', function(e) { |
| if (e.target.matches('form')) { |
| e.preventDefault(); |
| const formData = new FormData(e.target); |
| const data = Object.fromEntries(formData); |
| |
| |
| const submitBtn = e.target.querySelector('button[type="submit"]'); |
| const originalText = submitBtn.textContent; |
| submitBtn.textContent = 'Processing...'; |
| submitBtn.disabled = true; |
| |
| |
| setTimeout(() => { |
| |
| submitBtn.textContent = originalText; |
| submitBtn.disabled = false; |
| |
| |
| showNotification('Action completed successfully!', 'info'); |
| }, 1000); |
| } |
| }); |
|
|
| |
| let resizeTimer; |
| window.addEventListener('resize', function() { |
| clearTimeout(resizeTimer); |
| resizeTimer = setTimeout(function() { |
| |
| console.log('Window resized - handling responsive adjustments'); |
| }, 250); |
| }); |