Reworked titleTransform.

This commit is contained in:
Kristof Rado 2020-06-01 22:25:07 +02:00
parent efbb9648c4
commit a692d6be09

View File

@ -17,8 +17,11 @@ Module.register("calendar", {
displayRepeatingCountTitle: false, displayRepeatingCountTitle: false,
defaultRepeatingCountTitle: "", defaultRepeatingCountTitle: "",
maxTitleLength: 25, maxTitleLength: 25,
maxLocationTitleLength: 25,
wrapEvents: false, // wrap events to multiple lines breaking at maxTitleLength wrapEvents: false, // wrap events to multiple lines breaking at maxTitleLength
wrapLocationEvents: false,
maxTitleLines: 3, maxTitleLines: 3,
maxEventTitleLines: 3,
fetchInterval: 5 * 60 * 1000, // Update every 5 minutes. fetchInterval: 5 * 60 * 1000, // Update every 5 minutes.
animationSpeed: 2000, animationSpeed: 2000,
fade: true, fade: true,
@ -45,6 +48,9 @@ Module.register("calendar", {
"De verjaardag van ": "", "De verjaardag van ": "",
"'s birthday": "" "'s birthday": ""
}, },
locationTitleReplace: {
"street ": ""
},
broadcastEvents: true, broadcastEvents: true,
excludedEvents: [], excludedEvents: [],
sliceMultiDayEvents: false, sliceMultiDayEvents: false,
@ -241,7 +247,7 @@ Module.register("calendar", {
} }
} }
titleWrapper.innerHTML = this.titleTransform(event.title) + repeatingCountTitle; titleWrapper.innerHTML = this.titleTransform(event.title, this.config.titleReplace, this.config.wrapEvents, this.config.maxTitleLength, this.config.maxTitleLines) + repeatingCountTitle;
var titleClass = this.titleClassForUrl(event.url); var titleClass = this.titleClassForUrl(event.url);
@ -389,7 +395,7 @@ Module.register("calendar", {
var descCell = document.createElement("td"); var descCell = document.createElement("td");
descCell.className = "location"; descCell.className = "location";
descCell.colSpan = "2"; descCell.colSpan = "2";
descCell.innerHTML = this.locationTitleShorten(event.location); descCell.innerHTML = this.titleTransform(event.location, this.config.locationTitleReplace, this.config.wrapLocationEvents, this.config.maxLocationTitleLength, this.config.maxEventTitleLines);
locationRow.appendChild(descCell); locationRow.appendChild(descCell);
wrapper.appendChild(locationRow); wrapper.appendChild(locationRow);
@ -719,9 +725,9 @@ Module.register("calendar", {
* *
* return string - The transformed title. * return string - The transformed title.
*/ */
titleTransform: function (title) { titleTransform: function (title, titleReplace, wrapEvents, maxTitleLength, maxTitleLines) {
for (var needle in this.config.titleReplace) { for (var needle in titleReplace) {
var replacement = this.config.titleReplace[needle]; var replacement = titleReplace[needle];
var regParts = needle.match(/^\/(.+)\/([gim]*)$/); var regParts = needle.match(/^\/(.+)\/([gim]*)$/);
if (regParts) { if (regParts) {
@ -732,20 +738,7 @@ Module.register("calendar", {
title = title.replace(needle, replacement); title = title.replace(needle, replacement);
} }
title = this.shorten(title, this.config.maxTitleLength, this.config.wrapEvents, this.config.maxTitleLines); title = this.shorten(title, maxTitleLength, wrapEvents, maxTitleLines);
return title;
},
/*
* locationTitleShorten(title)
* Shortens the event location title based on config.maxTitleLength and config.wrapEvents
*
* argument title string - the event location title to shorten
*
* return string - The shortened title.
*/
locationTitleShorten: function (title) {
title = this.shorten(title, this.config.maxTitleLength, this.config.wrapEvents, this.config.maxTitleLines);
return title; return title;
}, },