-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
95 lines (81 loc) · 2.65 KB
/
Copy pathscript.js
File metadata and controls
95 lines (81 loc) · 2.65 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
let allEvents = [];
// Load events from JSON
async function fetchEvents() {
try {
const res = await fetch("events.json");
allEvents = await res.json();
displayEvents(allEvents);
} catch (err) {
console.error("Failed to load events:", err);
}
}
// Show events
function displayEvents(events) {
const container = document.getElementById("events-container");
container.innerHTML = "";
if (events.length === 0) {
container.innerHTML = "<p>No events found.</p>";
return;
}
events.forEach(event => {
const card = document.createElement("div");
card.className = "event-card";
let icon = "";
if (event.type === "Tech") icon = `<i class="fas fa-microchip"></i>`;
else if (event.type === "Cultural") icon = `<i class="fas fa-theater-masks"></i>`;
else if (event.type === "Sports") icon = `<i class="fas fa-futbol"></i>`;
card.innerHTML = `
<img src="${event.image}" alt="${event.title}" class="event-image" />
<h2>${icon} ${event.title}</h2>
<p><strong>Type:</strong> ${event.type}</p>
<p><strong>Date:</strong> ${event.date}</p>
<p><strong>Time:</strong> ${event.time}</p>
<p><strong>Location:</strong> ${event.location}</p>
<p>${event.description}</p>
`;
container.appendChild(card);
});
}
// Filter search + type
function filterEvents() {
const type = document.getElementById("filter").value.toLowerCase();
const search = document.getElementById("search").value.toLowerCase();
const filtered = allEvents.filter(event => {
const matchType = type === "all" || event.type.toLowerCase() === type;
const matchSearch = event.title.toLowerCase().includes(search);
return matchType && matchSearch;
});
displayEvents(filtered);
}
// Save events
function saveEventsToLocal() {
localStorage.setItem("campusEvents", JSON.stringify(allEvents));
}
// Load saved or fetch
function loadEventsFromLocal() {
const saved = localStorage.getItem("campusEvents");
if (saved) {
allEvents = JSON.parse(saved);
displayEvents(allEvents);
} else {
fetchEvents();
}
}
// 🔄 Reset all
function resetEvents() {
localStorage.removeItem("campusEvents");
fetchEvents();
}
// 🌙 Toggle dark mode
function toggleDarkMode() {
document.body.classList.toggle("dark");
const mode = document.body.classList.contains("dark") ? "dark" : "light";
localStorage.setItem("theme", mode);
}
// When page loads
window.addEventListener("DOMContentLoaded", () => {
loadEventsFromLocal();
if (localStorage.getItem("theme") === "dark") {
document.body.classList.add("dark");
}
});