Spaces:
Running
Running
File size: 3,392 Bytes
9bd490f 0e82ba4 9bd490f 0e82ba4 9bd490f aa084dd 50f82ff 0e82ba4 9bd490f aa084dd 22782e5 9bd490f 22782e5 50f82ff 22782e5 9bd490f 0e82ba4 a70d513 0e82ba4 c2c4409 a70d513 c2c4409 a70d513 0e82ba4 |
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 |
document.addEventListener('DOMContentLoaded', function() {
// Initialize language
const defaultLanguage = 'es';
let currentLanguage = localStorage.getItem('language') || defaultLanguage;
updateLanguage(currentLanguage);
// Handle language change from any component
document.addEventListener('languageChange', (e) => {
updateLanguage(e.detail);
});
// Blog filter functionality with event delegation
document.addEventListener('click', function(e) {
// Handle blog category buttons
if (e.target.closest('[data-category]')) {
const button = e.target.closest('[data-category]');
const category = button.getAttribute('data-category');
// Update all buttons in the document
document.querySelectorAll('[data-category]').forEach(btn => {
btn.classList.remove('active-category');
btn.classList.add('bg-white', 'text-gray-700');
});
// Update clicked button
button.classList.remove('bg-white', 'text-gray-700');
button.classList.add('active-category');
// Update category contents with animation
document.querySelectorAll('[data-category-content]').forEach(content => {
if (content.getAttribute('data-category-content') === category) {
content.style.display = 'block';
content.style.animation = 'fadeIn 0.5s ease-out';
} else {
content.style.display = 'none';
}
});
feather.replace();
}
});
// Form submission handling
const contactForm = document.getElementById('contact-form');
if (contactForm) {
contactForm.addEventListener('submit', function(e) {
e.preventDefault();
// Here you would typically send the form data
// For demo purposes, we'll just show an alert
alert('Thank you for your message! I will get back to you soon.');
this.reset();
});
}
});
function updateLanguage(language) {
// Update all elements with data-i18n attributes
document.querySelectorAll('[data-i18n]').forEach(element => {
const key = element.getAttribute('data-i18n');
if (translations[language] && translations[language][key]) {
element.textContent = translations[language][key];
} else if (translations['es'][key]) {
// Fallback to Spanish if translation missing
element.textContent = translations['es'][key];
}
});
// Update HTML lang attribute
document.documentElement.lang = language;
// Update active language in selector
document.querySelectorAll('.language-option').forEach(option => {
if (option.getAttribute('data-lang') === language) {
option.classList.add('active');
} else {
option.classList.remove('active');
}
});
}
function filterBlogPosts(category) {
const blogPosts = document.querySelectorAll('.blog-post');
blogPosts.forEach(post => {
const postCategories = post.getAttribute('data-categories').split(' ');
if (category === 'all' || postCategories.includes(category)) {
post.style.display = 'block';
} else {
post.style.display = 'none';
}
});
} |