-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevents.js
More file actions
172 lines (148 loc) · 5.9 KB
/
events.js
File metadata and controls
172 lines (148 loc) · 5.9 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// Events page specific JavaScript
document.addEventListener("DOMContentLoaded", () => {
const searchInput = document.getElementById("searchInput")
const categoryFilter = document.getElementById("categoryFilter")
const eventsGrid = document.getElementById("eventsGrid")
const noResults = document.getElementById("noResults")
const tabBtns = document.querySelectorAll(".tab-btn")
const tabContents = document.querySelectorAll(".tab-content")
// Tab functionality
tabBtns.forEach((btn) => {
btn.addEventListener("click", function () {
const targetTab = this.getAttribute("data-tab")
// Remove active class from all tabs and contents
tabBtns.forEach((b) => b.classList.remove("active"))
tabContents.forEach((c) => c.classList.remove("active"))
// Add active class to clicked tab and corresponding content
this.classList.add("active")
const targetContent = document.getElementById(targetTab + "-tab")
if (targetContent) {
targetContent.classList.add("active")
}
})
})
// Search and filter functionality
function filterEvents() {
const searchTerm = searchInput.value.toLowerCase()
const selectedCategory = categoryFilter.value
const eventCards = eventsGrid.querySelectorAll(".event-card")
let visibleCount = 0
eventCards.forEach((card) => {
const title = card.querySelector(".event-title").textContent.toLowerCase()
const description = card.querySelector(".event-description").textContent.toLowerCase()
const club = card.querySelector(".event-club span").textContent.toLowerCase()
const category = card.getAttribute("data-category")
const matchesSearch = title.includes(searchTerm) || description.includes(searchTerm) || club.includes(searchTerm)
const matchesCategory = selectedCategory === "all" || category === selectedCategory
if (matchesSearch && matchesCategory) {
card.style.display = "block"
visibleCount++
} else {
card.style.display = "none"
}
})
// Show/hide no results message
if (visibleCount === 0) {
noResults.style.display = "block"
eventsGrid.style.display = "none"
} else {
noResults.style.display = "none"
eventsGrid.style.display = "grid"
}
}
// Event listeners for search and filter
if (searchInput) {
searchInput.addEventListener("input", filterEvents)
}
if (categoryFilter) {
categoryFilter.addEventListener("change", filterEvents)
}
// Clear filters function
window.clearFilters = () => {
if (searchInput) searchInput.value = ""
if (categoryFilter) categoryFilter.value = "all"
filterEvents()
window.showNotification("Filters cleared!", "info")
}
// Handle event registration
document.addEventListener("click", (e) => {
if (e.target.matches(".event-register")) {
const isRegistered = e.target.classList.contains("registered")
if (isRegistered) {
e.target.textContent = "Register"
e.target.classList.remove("registered")
e.target.classList.remove("btn-outline")
e.target.classList.add("btn-primary")
window.showNotification("Unregistered from event!", "info")
} else {
e.target.textContent = "Registered"
e.target.classList.add("registered")
e.target.classList.remove("btn-primary")
e.target.classList.add("btn-outline")
window.showNotification("Successfully registered for event!", "success")
}
}
})
// Handle share buttons
document.addEventListener("click", (e) => {
if (e.target.matches(".fa-share") || e.target.closest(".action-btn")?.querySelector(".fa-share")) {
e.preventDefault()
const eventCard = e.target.closest(".event-card")
const eventTitle = eventCard.querySelector(".event-title").textContent
if (navigator.share) {
navigator.share({
title: eventTitle,
text: `Check out this event: ${eventTitle}`,
url: window.location.href,
})
} else {
// Fallback for browsers that don't support Web Share API
navigator.clipboard.writeText(window.location.href).then(() => {
window.showNotification("Event link copied to clipboard!", "success")
})
}
}
})
// Animate event cards on scroll
const eventCards = document.querySelectorAll(".event-card")
const cardObserver = new IntersectionObserver((entries) => {
entries.forEach((entry, index) => {
if (entry.isIntersecting) {
setTimeout(() => {
entry.target.style.opacity = "1"
entry.target.style.transform = "translateY(0)"
}, index * 100)
}
})
})
eventCards.forEach((card) => {
card.style.opacity = "0"
card.style.transform = "translateY(20px)"
card.style.transition = "opacity 0.5s ease, transform 0.5s ease"
cardObserver.observe(card)
})
// Declare showNotification function
window.showNotification = (message, type) => {
// Implementation of showNotification function
console.log(`Notification (${type}): ${message}`)
}
// Theme Toggle Functionality
const themeToggle = document.getElementById('themeToggle');
const themeIcon = themeToggle.querySelector('i');
// Check for saved theme preference
const savedTheme = localStorage.getItem('theme') || 'light';
document.documentElement.setAttribute('data-theme', savedTheme);
updateThemeIcon(savedTheme);
// Theme toggle click handler
themeToggle.addEventListener('click', () => {
const currentTheme = document.documentElement.getAttribute('data-theme');
const newTheme = currentTheme === 'light' ? 'dark' : 'light';
document.documentElement.setAttribute('data-theme', newTheme);
localStorage.setItem('theme', newTheme);
updateThemeIcon(newTheme);
});
// Update theme icon based on current theme
function updateThemeIcon(theme) {
themeIcon.className = theme === 'light' ? 'fas fa-moon' : 'fas fa-sun';
}
})