Skip to content

Commit

Permalink
better link handling in events
Browse files Browse the repository at this point in the history
  • Loading branch information
domlet committed Jul 10, 2024
1 parent ad8811d commit 97363f8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ <h2>Dates to Note:</h2>
</a>
</div>
<div class="col-lg-3 col-md-6 col-sm-12 pt-2">
<a href='https://calendar.google.com/calendar/u/0/embed?src=a71ff6b63e1709ae2bfbcada2b3b64ebeb1f7f5e30787b2bb059725fa17b7b2b@group.calendar.google.com&ctz=America/Los_Angeles&mode=AGENDA' class="lowkey" target="_blank">
<a href='https://calendar.google.com/calendar/u/0/embed?src=a71ff6b63e1709ae2bfbcada2b3b64ebeb1f7f5e30787b2bb059725fa17b7b2b@group.calendar.google.com&ctz=America/Los_Angeles&mode=WEEK' class="lowkey" target="_blank">
<h2>Opportunities:</h2>
<ul id="events-student-opps"></ul>
</a>
<ul id="events-student-opps"></ul>
</div>
</div>
</div>
Expand Down
22 changes: 20 additions & 2 deletions script/scriptEventLists.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@ $(document).ready(function () {
});
});

// Function to convert URLs to linked HTML text
function convertUrlsToLinks(text) {
// Regular expression to find URLs
var urlPattern = /(https?:\/\/[^\s]+)/g;

// Replace URLs with HTML links
var newText = text.replace(
urlPattern,
'<a href="$1" target="_blank" class="event-link">Learn more</a>.'
);

return newText;
}

// Show upcoming events on the page
function showEvents(eventsArray) {
// modify formatting of the events
Expand All @@ -109,6 +123,10 @@ function showEvents(eventsArray) {
/<[^>]*>/g,
" "
);
// convert urls to links
eventsArray[i].description = convertUrlsToLinks(
eventsArray[i].description
);
// add spaces after ':' (except '://')
eventsArray[i].description = eventsArray[i].description.replace(
/\:(?!\s|\/\/\b)/g,
Expand All @@ -119,9 +137,9 @@ function showEvents(eventsArray) {
if (eventsArray[i].name.length > 17) {
eventsArray[i].name = eventsArray[i].name.substring(0, 17) + "..";
}
if (eventsArray[i].description.length > 101) {
if (eventsArray[i].description.length > 170) {
eventsArray[i].description =
eventsArray[i].description.substring(0, 101) + " ...";
eventsArray[i].description.substring(0, 170) + "...";
}
}
// separate the events into arrays by type
Expand Down
7 changes: 6 additions & 1 deletion style/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ iframe {
#events ul {
padding: 0;
}

.event-link {
color: inherit;
text-decoration: underline;
}
.event-date {
font-size: small;
background-color: rgba(255, 255, 255, 0.2);
Expand All @@ -148,7 +153,7 @@ iframe {
#events-student-non-holiday .event-item:nth-child(-n + 5) {
display: list-item;
}
#events-student-opps .event-item:nth-child(-n + 3) {
#events-student-opps .event-item:nth-child(-n + 13) {
display: list-item;
}
.event-item-desc {
Expand Down

0 comments on commit 97363f8

Please sign in to comment.