Skip to content

Commit

Permalink
Refractored the eventonclick
Browse files Browse the repository at this point in the history
  • Loading branch information
Xalsier committed Jul 18, 2023
1 parent 07cad92 commit b0785ce
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 64 deletions.
2 changes: 1 addition & 1 deletion cal.css
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@
align-items: center;
gap: 10px;
translate: 0px 60px;
}
}
97 changes: 34 additions & 63 deletions cal.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,70 +10,41 @@
}
return clickInside;
};
显示事件 = async (c, evi) => {
const defaultDisplay = `
<img src="${c.description.img}" width="200px" style="margin-top:10px;"></img>
<br> <strong>${c.description.title}</strong>
<br> ${Object.values(c.description.bullets).map(bullet => `- ${bullet}<br>`).join("")}
`;
if (c && c.description) {
try {
const response = await fetch(c.description);
if (!response.ok) throw new Error("Cannot find description");
const text = await response.text();
evi.innerHTML = text;
} catch (error) {
evi.innerHTML = defaultDisplay;
}
}
evi.style.display = evi.style.display === "none" ? "block" : "none"; // Toggle the display
};
= async (e, n, a, s) => {
(d = []("div")),
(i = (a, s)),
(d[] = "cc"),
Array.from({ length: i }).forEach(() => d.appendChild(Object.assign([]("div"), { []: "cd empty" }))),
Array.from({ length: n }, (_, n) => n + 1).forEach(n => {
let o = []("div"),
c = e[`${a}-${(s + 1 + "").padStart(2, "0")}-${(n + "").padStart(2, "0")}`],
t = new Date(a, s, n).setHours(0, 0, 0, 0) == .setHours(0, 0, 0, 0); // Ignore the time, just compare the dates.
o[] = `cd ${t && c ? `event-${c.type}` : (a, s, n) ? "past " + `past-event-${c?.type}` : ""} ${t ? "today" : ""}`,
o.innerHTML = n;
o.onclick = _ => {
let evi = []("evi");
if (c && c.description) {
fetch(c.description) // Fetch the description HTML from the provided URL
.then(response => {
console.log(`Fetched event: ${c.description}`);
if (response.ok) {
return response.text();
} else {
throw new Error("Cannot find description");
}
})
.then(text => {
evi.innerHTML = text;
if (evi.style.display === "none") { // Check if it's hidden
evi.style.display = "block"; // If it's hidden, display it
} else {
evi.style.display = "none"; // If it's displayed, hide it
}
})
.catch(error => {
console.error(error);
console.log("Description URL cannot be found");
evi.innerHTML = `
<img src="${c.description.img}" width="200px" style="margin-top:10px;"></img>
<br> <strong>${c.description.title}</strong>
<br> ${Object.values(c.description.bullets).map(bullet => `- ${bullet}<br>`).join("")}
`;
if (evi.style.display === "none") { // Check if it's hidden
evi.style.display = "block"; // If it's hidden, display it
} else {
evi.style.display = "none"; // If it's displayed, hide it
}
});
} else {
console.log("Description URL cannot be found");
evi.innerHTML = `
<img src="${c.description.img}" width="200px" style="margin-top:10px;"></img>
<br> <strong>${c.description.title}</strong>
<br> ${Object.values(c.description.bullets).map(bullet => `- ${bullet}<br>`).join("")}
`;
if (evi.style.display === "none") { // Check if it's hidden
evi.style.display = "block"; // If it's hidden, display it
} else {
evi.style.display = "none"; // If it's displayed, hide it
}
}
};

d.appendChild(o);
});
return d;
};
let d = []("div"),
i = (a, s),
evi = []("evi");
d[] = "cc";
Array.from({ length: i }).forEach(() => d.appendChild(Object.assign([]("div"), { []: "cd empty" })));
Array.from({ length: n }, (_, n) => n + 1).forEach(n => {
let o = []("div"),
c = e[`${a}-${(s + 1 + "").padStart(2, "0")}-${(n + "").padStart(2, "0")}`],
t = new Date(a, s, n).setHours(0, 0, 0, 0) == .setHours(0, 0, 0, 0);
o[] = `cd ${t && c ? `event-${c.type}` : (a, s, n) ? "past " + `past-event-${c?.type}` : ""} ${t ? "today" : ""}`;
o.innerHTML = n;
o.onclick = () => 显示事件(c, evi);
d.appendChild(o);
});
return d;
};
= null;
= new Date(); // This now always represents today's date
表示 = new Date(); // This new object will represent the displayed date
Expand Down

0 comments on commit b0785ce

Please sign in to comment.