Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions site/themes/s2b_hugo_theme/assets/js/cal/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,14 @@
const startString = startDate.format(googleFormat);
const endString = endDate.format(googleFormat);
const calendarDates = `${startString}/${endString}`;


const descr = $.fn.truncateString(event.details, 500) + `\n\n${event.shareable}`;

googleCalUrl.search = new URLSearchParams({
action: "TEMPLATE",
text: `shift2Bikes: ${event.title}`,
location: event.address,
details: `${event.details}\n\n${event.shareable}`,
details: descr,
dates: calendarDates,
// FIX: this seems better than timezoneless but probably should be configurable.
ctz: `America/Los_Angeles`
Expand All @@ -98,6 +100,15 @@
return googleCalUrl.toString();
};

$.fn.truncateString = function ( str, maxLength=250 ) {
let text = str.substring(0,maxLength);
if (str.length > maxLength) {
// replace the last character with an ellipsis
text = text.slice(0, -1) + "…";
}
return text;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could do something like this if you wanted to avoid that first substr call that goes unused if the length is small enough

{
        if (str.length < maxLength) {
            return str; 
        } else {
          // replace the last character with an ellipsis
           let text = str.substring(0,maxLength-1) + "…";
           return text;
        }
    };


$.fn.compareTimes = function ( event1, event2 ) {
if ( event1.time < event2.time ) {
return -1;
Expand Down
6 changes: 1 addition & 5 deletions site/themes/s2b_hugo_theme/assets/js/cal/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,7 @@ $(document).ready(function() {
if (event.printdescr) {
$('meta[property="og:description"]')[0].setAttribute("content", event.printdescr);
} else {
var descr = event.details.substring(0,250);
if (event.details.length > 250) {
// replace the last character with an ellipsis
descr = descr.slice(0, -1) + "…";
}
let descr = container.truncateString(event.details, 250);
$('meta[property="og:description"]')[0].setAttribute("content", descr);
}
document.title = event.title + " - Calendar - " + SITE_TITLE;
Expand Down