mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 11:50:00 +00:00
Add in cutting of long vertical titles
This commit is contained in:
parent
184164b677
commit
399e171083
@ -14,7 +14,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
### Added
|
### Added
|
||||||
- Italian translation for "Feels"
|
- Italian translation for "Feels"
|
||||||
- Disabled the screensaver on raspbian with installation script
|
- Disabled the screensaver on raspbian with installation script
|
||||||
|
- Added option to truncate the number of vertical lines a calendar item can span if `wrapEvents` is enabled.
|
||||||
|
|
||||||
### Updated
|
### Updated
|
||||||
- Bumped the Electron dependency to v3.0.13 to support the most recent Raspbian. [#1500](https://github.com/MichMich/MagicMirror/issues/1500)
|
- Bumped the Electron dependency to v3.0.13 to support the most recent Raspbian. [#1500](https://github.com/MichMich/MagicMirror/issues/1500)
|
||||||
|
@ -32,6 +32,7 @@ The following properties can be configured:
|
|||||||
| `defaultSymbol` | The default symbol. <br><br> **Possible values:** See [Font Awsome](http://fontawesome.io/icons/) website. <br> **Default value:** `calendar`
|
| `defaultSymbol` | The default symbol. <br><br> **Possible values:** See [Font Awsome](http://fontawesome.io/icons/) website. <br> **Default value:** `calendar`
|
||||||
| `maxTitleLength` | The maximum title length. <br><br> **Possible values:** `10` - `50` <br> **Default value:** `25`
|
| `maxTitleLength` | The maximum title length. <br><br> **Possible values:** `10` - `50` <br> **Default value:** `25`
|
||||||
| `wrapEvents` | Wrap event titles to multiple lines. Breaks lines at the length defined by `maxTitleLength`. <br><br> **Possible values:** `true` or `false` <br> **Default value:** `false`
|
| `wrapEvents` | Wrap event titles to multiple lines. Breaks lines at the length defined by `maxTitleLength`. <br><br> **Possible values:** `true` or `false` <br> **Default value:** `false`
|
||||||
|
| `maxTitleLines` | The maximum number of lines a title will wrap vertically before being cut (Only enabled if `wrapEvents` is also enabled). <br><br> **Possible values:** `0` - `10` <br> **Default value:** `3`
|
||||||
| `fetchInterval` | How often does the content needs to be fetched? (Milliseconds) <br><br> **Possible values:** `1000` - `86400000` <br> **Default value:** `300000` (5 minutes)
|
| `fetchInterval` | How often does the content needs to be fetched? (Milliseconds) <br><br> **Possible values:** `1000` - `86400000` <br> **Default value:** `300000` (5 minutes)
|
||||||
| `animationSpeed` | Speed of the update animation. (Milliseconds) <br><br> **Possible values:** `0` - `5000` <br> **Default value:** `2000` (2 seconds)
|
| `animationSpeed` | Speed of the update animation. (Milliseconds) <br><br> **Possible values:** `0` - `5000` <br> **Default value:** `2000` (2 seconds)
|
||||||
| `fade` | Fade the future events to black. (Gradient) <br><br> **Possible values:** `true` or `false` <br> **Default value:** `true`
|
| `fade` | Fade the future events to black. (Gradient) <br><br> **Possible values:** `true` or `false` <br> **Default value:** `true`
|
||||||
|
@ -19,6 +19,7 @@ Module.register("calendar", {
|
|||||||
defaultRepeatingCountTitle: "",
|
defaultRepeatingCountTitle: "",
|
||||||
maxTitleLength: 25,
|
maxTitleLength: 25,
|
||||||
wrapEvents: false, // wrap events to multiple lines breaking at maxTitleLength
|
wrapEvents: false, // wrap events to multiple lines breaking at maxTitleLength
|
||||||
|
maxTitleLines: 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,
|
||||||
@ -220,7 +221,7 @@ Module.register("calendar", {
|
|||||||
var titleWrapper = document.createElement("td"),
|
var titleWrapper = document.createElement("td"),
|
||||||
repeatingCountTitle = "";
|
repeatingCountTitle = "";
|
||||||
|
|
||||||
if (this.config.displayRepeatingCountTitle && event.firstYear !== undefined) {
|
if (this.config.displayRepeatingCountTitle && event.firstYear !== undefined) {
|
||||||
|
|
||||||
repeatingCountTitle = this.countTitleForUrl(event.url);
|
repeatingCountTitle = this.countTitleForUrl(event.url);
|
||||||
|
|
||||||
@ -584,9 +585,10 @@ Module.register("calendar", {
|
|||||||
* @param {string} string Text string to shorten
|
* @param {string} string Text string to shorten
|
||||||
* @param {number} maxLength The max length of the string
|
* @param {number} maxLength The max length of the string
|
||||||
* @param {boolean} wrapEvents Wrap the text after the line has reached maxLength
|
* @param {boolean} wrapEvents Wrap the text after the line has reached maxLength
|
||||||
|
* @param {number} maxTitleLines The max number of vertical lines before cutting event title
|
||||||
* @returns {string} The shortened string
|
* @returns {string} The shortened string
|
||||||
*/
|
*/
|
||||||
shorten: function (string, maxLength, wrapEvents) {
|
shorten: function (string, maxLength, wrapEvents, maxTitleLines) {
|
||||||
if (typeof string !== "string") {
|
if (typeof string !== "string") {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@ -595,12 +597,19 @@ Module.register("calendar", {
|
|||||||
var temp = "";
|
var temp = "";
|
||||||
var currentLine = "";
|
var currentLine = "";
|
||||||
var words = string.split(" ");
|
var words = string.split(" ");
|
||||||
|
var line = 0;
|
||||||
|
|
||||||
for (var i = 0; i < words.length; i++) {
|
for (var i = 0; i < words.length; i++) {
|
||||||
var word = words[i];
|
var word = words[i];
|
||||||
if (currentLine.length + word.length < (typeof maxLength === "number" ? maxLength : 25) - 1) { // max - 1 to account for a space
|
if (currentLine.length + word.length < (typeof maxLength === "number" ? maxLength : 25) - 1) { // max - 1 to account for a space
|
||||||
currentLine += (word + " ");
|
currentLine += (word + " ");
|
||||||
} else {
|
} else {
|
||||||
|
line++;
|
||||||
|
if (line > maxTitleLines - 1) {
|
||||||
|
if (i < words.length) currentLine += "…";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (currentLine.length > 0) {
|
if (currentLine.length > 0) {
|
||||||
temp += (currentLine + "<br>" + word + " ");
|
temp += (currentLine + "<br>" + word + " ");
|
||||||
} else {
|
} else {
|
||||||
@ -651,7 +660,7 @@ Module.register("calendar", {
|
|||||||
title = title.replace(needle, replacement);
|
title = title.replace(needle, replacement);
|
||||||
}
|
}
|
||||||
|
|
||||||
title = this.shorten(title, this.config.maxTitleLength, this.config.wrapEvents);
|
title = this.shorten(title, this.config.maxTitleLength, this.config.wrapEvents, this.config.maxTitleLines);
|
||||||
return title;
|
return title;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user