File size: 2,525 Bytes
ea6e6ce 3d6e1be | 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 | // Initialize tooltips
document.addEventListener('DOMContentLoaded', function() {
// Initialize any tooltips or popovers
const tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
tooltipTriggerList.map(function (tooltipTriggerEl) {
return new bootstrap.Tooltip(tooltipTriggerEl);
});
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
});
});
});
// Search functionality
function performSearch(query) {
console.log('Searching for:', query);
// In a real implementation, this would fetch search results from an API
// and update the DOM with the results
}
// Load articles from API
async function loadArticles() {
try {
// In a real implementation, this would fetch from your API
const response = await fetch('https://jsonplaceholder.typicode.com/posts?_limit=6');
if (!response.ok) throw new Error('Failed to fetch articles');
return await response.json();
} catch (error) {
console.error('Error loading articles:', error);
return [];
}
}
// Article view tracking
function trackArticleView(articleId) {
console.log('Tracking view for article:', articleId);
// In a real implementation, this would send analytics data
}
// Filter articles by category
function filterArticles(category) {
const articles = document.querySelectorAll('custom-article-card');
articles.forEach(article => {
if (category === 'all' || article.getAttribute('category') === category) {
article.style.display = 'block';
} else {
article.style.display = 'none';
}
});
}
// Initialize category filtering
document.addEventListener('DOMContentLoaded', () => {
const categoryLinks = document.querySelectorAll('[data-filter-category]');
categoryLinks.forEach(link => {
link.addEventListener('click', (e) => {
e.preventDefault();
const category = link.getAttribute('data-filter-category');
filterArticles(category);
// Update active state
categoryLinks.forEach(l => l.classList.remove('text-blue-600'));
link.classList.add('text-blue-600');
});
});
});
|