From bbd6e6e1d4c93691188bde33edf2b38b8c17c8c4 Mon Sep 17 00:00:00 2001
From: Dom Brassey
Date: Sat, 6 Jul 2024 21:06:46 +0100
Subject: [PATCH] multiple calendars works
---
script/scriptEventLists.js | 76 +++++++++++++++++++-------------------
1 file changed, 38 insertions(+), 38 deletions(-)
diff --git a/script/scriptEventLists.js b/script/scriptEventLists.js
index f9c1d93..f4eb528 100644
--- a/script/scriptEventLists.js
+++ b/script/scriptEventLists.js
@@ -80,7 +80,6 @@ $(document).ready(function () {
item.eventType = "event";
}
}
- console.log("hi");
// get items from both gCals and hard-coded cals
// and combine them into one array
// then sort them by date
@@ -93,9 +92,6 @@ $(document).ready(function () {
}
// Sort by start date
combinedAllEvents.sort((a, b) => a.beg - b.beg);
- console.log(
- "there are now " + combinedAllEvents.length + " combinedAllEvents"
- );
showEvents(combinedAllEvents);
return combinedAllEvents;
})();
@@ -105,16 +101,36 @@ $(document).ready(function () {
});
});
+// Show upcoming events on the page
function showEvents(eventsArray) {
- // Show upcoming events:
+ // modify formatting of the events
+ for (let i = 0; i < eventsArray.length; i++) {
+ if (eventsArray[i].description != "") {
+ // remove html in descriptions
+ eventsArray[i].description = eventsArray[i].description.replace(
+ /<[^>]*>/g,
+ ""
+ );
+ // add spaces after periods
+ eventsArray[i].description = eventsArray[i].description.replace(
+ /\.(\S)/g,
+ ". $1"
+ );
+ }
+ // truncate any long titles or desc
+ if (eventsArray[i].name.length > 18) {
+ eventsArray[i].name = eventsArray[i].name.substring(0, 18);
+ }
+ if (eventsArray[i].description.length > 100) {
+ eventsArray[i].description = eventsArray[i].description.substring(0, 100);
+ }
+ }
+ // separate the events into arrays by type
let eHoliday = [];
- let eEvent = [];
let eStudAct = [];
- let textHolidays = "";
- let textEvents = "";
- let textStudActs = "";
- // Collect only future events:
+ let eEvent = [];
for (i in eventsArray) {
+ // Collect only future events
if (eventsArray[i].beg > dateToday) {
// Collect future holidays:
if (eventsArray[i].eventType == "studentHoliday") {
@@ -127,17 +143,14 @@ function showEvents(eventsArray) {
}
}
}
- // Display upcoming events (of both types):
+ // Display upcoming events (of all types):
+ let textHolidays = "";
+ let textEvents = "";
+ let textStudActs = "";
+
for (x in eHoliday) {
- if (eHoliday[x].name.length > 18) {
- textHolidays +=
- "" +
- eHoliday[x].name.substring(0, 18) +
- ".. ";
- } else {
- textHolidays +=
- "" + eHoliday[x].name + " ";
- }
+ textHolidays +=
+ "" + eHoliday[x].name + " ";
textHolidays +=
"" +
eHoliday[x].beg.toLocaleString("en-US", {
@@ -148,15 +161,9 @@ function showEvents(eventsArray) {
"";
}
for (y in eEvent) {
- if (eEvent[y].name.length > 18) {
- textEvents +=
- "" +
- eEvent[y].name.substring(0, 18) +
- ".. ";
- } else {
- textEvents +=
- "" + eEvent[y].name + " ";
- }
+ textEvents +=
+ "" + eEvent[y].name + " ";
+
textEvents +=
"" +
eEvent[y].beg.toLocaleString("en-US", {
@@ -169,15 +176,8 @@ function showEvents(eventsArray) {
"
";
}
for (z in eStudAct) {
- if (eStudAct[z].name.length > 18) {
- textStudActs +=
- "" +
- eStudAct[z].name.substring(0, 18) +
- ".. ";
- } else {
- textStudActs +=
- "" + eStudAct[z].name + " ";
- }
+ textStudActs +=
+ "" + eStudAct[z].name + " ";
textStudActs +=
"" +
eStudAct[z].beg.toLocaleString("en-US", {