-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
102 lines (87 loc) · 3.75 KB
/
script.js
File metadata and controls
102 lines (87 loc) · 3.75 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Filter functionality for news posts
document.addEventListener('DOMContentLoaded', function() {
const filterButtons = document.querySelectorAll('.tab-btn');
const yearButtons = document.querySelectorAll('.year-btn');
const newsPosts = document.querySelectorAll('.news-post');
let activeCategory = 'all';
let activeYear = 'all';
// Category filter functionality
filterButtons.forEach(button => {
button.addEventListener('click', function() {
// Remove active class from all buttons
filterButtons.forEach(btn => btn.classList.remove('active'));
// Add active class to clicked button
this.classList.add('active');
// Get filter value
activeCategory = this.getAttribute('data-filter');
// Apply filters
applyFilters();
});
});
// Year filter functionality
yearButtons.forEach(button => {
button.addEventListener('click', function() {
// Remove active class from all year buttons
yearButtons.forEach(btn => btn.classList.remove('active'));
// Add active class to clicked button
this.classList.add('active');
// Get year value
activeYear = this.getAttribute('data-year');
// Apply filters
applyFilters();
});
});
// Apply both category and year filters
function applyFilters() {
newsPosts.forEach(post => {
const postCategory = post.getAttribute('data-category');
const postYear = post.getAttribute('data-year');
const categoryMatch = (activeCategory === 'all' || postCategory === activeCategory);
const yearMatch = (activeYear === 'all' || postYear === activeYear);
if (categoryMatch && yearMatch) {
post.style.display = 'block';
} else {
post.style.display = 'none';
}
});
}
// Search functionality (basic implementation)
const searchBtn = document.querySelector('.search-btn');
if (searchBtn) {
searchBtn.addEventListener('click', function() {
const searchTerm = prompt('Enter search term:');
if (searchTerm) {
// Reset filters when searching
activeCategory = 'all';
activeYear = 'all';
filterButtons.forEach(btn => btn.classList.remove('active'));
yearButtons.forEach(btn => btn.classList.remove('active'));
document.querySelector('.tab-btn[data-filter="all"]').classList.add('active');
document.querySelector('.year-btn[data-year="all"]').classList.add('active');
// Simple search implementation
newsPosts.forEach(post => {
const postText = post.textContent.toLowerCase();
if (postText.includes(searchTerm.toLowerCase())) {
post.style.display = 'block';
post.style.backgroundColor = '#fffacd';
} else {
post.style.display = 'none';
}
});
}
});
}
// Smooth scroll for navigation links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
});