Add in ability to wrap calendar events to multiple lines

This commit is contained in:
Andrew McOlash
2017-04-02 15:06:58 -05:00
parent 6165a6af6c
commit 63ae2b8095
4 changed files with 34 additions and 7 deletions

View File

@@ -18,6 +18,7 @@ Module.register("calendar", {
displayRepeatingCountTitle: false,
defaultRepeatingCountTitle: "",
maxTitleLength: 25,
wrapEvents: false, // wrap events to multiple lines breaking at maxTitleLength
fetchInterval: 5 * 60 * 1000, // Update every 5 minutes.
animationSpeed: 2000,
fade: true,
@@ -414,15 +415,38 @@ Module.register("calendar", {
*
* argument string string - The string to shorten.
* argument maxLength number - The max length of the string.
* argument wrapEvents - Wrap the text after the line has reached maxLength
*
* return string - The shortened string.
*/
shorten: function (string, maxLength) {
if (string.length > maxLength) {
return string.slice(0, maxLength) + "…";
}
shorten: function (string, maxLength, wrapEvents) {
if (wrapEvents) {
var temp = "";
var currentLine = "";
var words = string.split(" ");
return string;
for (var i = 0; i < words.length; i++) {
var word = words[i];
if (currentLine.length + word.length < 25 - 1) { // max - 1 to account for a space
currentLine += (word + " ");
} else {
if (currentLine.length > 0) {
temp += (currentLine + "<br>" + word + " ");
} else {
temp += (word + "<br>");
}
currentLine = "";
}
}
return temp + currentLine;
} else {
if (string.length > maxLength) {
return string.slice(0, maxLength) + "&hellip;";
} else {
return string;
}
}
},
/* capFirst(string)
@@ -437,7 +461,7 @@ Module.register("calendar", {
/* titleTransform(title)
* Transforms the title of an event for usage.
* Replaces parts of the text as defined in config.titleReplace.
* Shortens title based on config.maxTitleLength
* Shortens title based on config.maxTitleLength and config.wrapEvents
*
* argument title string - The title to transform.
*
@@ -456,7 +480,7 @@ Module.register("calendar", {
title = title.replace(needle, replacement);
}
title = this.shorten(title, this.config.maxTitleLength);
title = this.shorten(title, this.config.maxTitleLength, this.config.wrapEvents);
return title;
},