mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-07-04 22:58:03 +00:00
Merge pull request #2214 from Alvinger/customEvents
Custom events - Use custom symbol/color based on keyword in title
This commit is contained in:
commit
db874a011c
@ -17,6 +17,8 @@ _This release is scheduled to be released on 2021-01-01._
|
|||||||
- Chuvash translation.
|
- Chuvash translation.
|
||||||
- Calendar: new options "limitDays" and "coloredEvents"
|
- Calendar: new options "limitDays" and "coloredEvents"
|
||||||
|
|
||||||
|
- Added new option "customEvents" - use custom symbol/color based on keyword in event title
|
||||||
|
|
||||||
### Updated
|
### Updated
|
||||||
|
|
||||||
- Weather module - forecast now show TODAY and TOMORROW instead of weekday, to make it easier to understand.
|
- Weather module - forecast now show TODAY and TOMORROW instead of weekday, to make it easier to understand.
|
||||||
|
@ -38,7 +38,7 @@ Module.register("calendar", {
|
|||||||
hideOngoing: false,
|
hideOngoing: false,
|
||||||
colored: false,
|
colored: false,
|
||||||
coloredSymbolOnly: false,
|
coloredSymbolOnly: false,
|
||||||
coloredEvents: [], // Array of Keyword/Color where Keyword is a regexp and color the color code to use when regexp matches
|
customEvents: [], // Array of {keyword: "", symbol: "", color: ""} where Keyword is a regexp and symbol/color are to be applied for matched
|
||||||
tableClass: "small",
|
tableClass: "small",
|
||||||
calendars: [
|
calendars: [
|
||||||
{
|
{
|
||||||
@ -181,6 +181,8 @@ Module.register("calendar", {
|
|||||||
|
|
||||||
var currentFadeStep = 0;
|
var currentFadeStep = 0;
|
||||||
var lastSeenDate = "";
|
var lastSeenDate = "";
|
||||||
|
var ev;
|
||||||
|
var needle;
|
||||||
|
|
||||||
for (var e in events) {
|
for (var e in events) {
|
||||||
var event = events[e];
|
var event = events[e];
|
||||||
@ -226,6 +228,19 @@ Module.register("calendar", {
|
|||||||
symbolWrapper.className = "symbol align-right " + symbolClass;
|
symbolWrapper.className = "symbol align-right " + symbolClass;
|
||||||
|
|
||||||
var symbols = this.symbolsForEvent(event);
|
var symbols = this.symbolsForEvent(event);
|
||||||
|
// If symbols are displayed and custom symbol is set, replace event symbol
|
||||||
|
if (this.config.displaySymbol && this.config.customEvents.length > 0) {
|
||||||
|
for (ev in this.config.customEvents) {
|
||||||
|
if (typeof this.config.customEvents[ev].symbol !== "undefined" && this.config.customEvents[ev].symbol !== "") {
|
||||||
|
needle = new RegExp(this.config.customEvents[ev].keyword, "gi");
|
||||||
|
if (needle.test(event.title)) {
|
||||||
|
symbols[0] = this.config.customEvents[ev].symbol;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (var i = 0; i < symbols.length; i++) {
|
for (var i = 0; i < symbols.length; i++) {
|
||||||
var symbol = document.createElement("span");
|
var symbol = document.createElement("span");
|
||||||
symbol.className = "fa fa-fw fa-" + symbols[i];
|
symbol.className = "fa fa-fw fa-" + symbols[i];
|
||||||
@ -256,15 +271,21 @@ Module.register("calendar", {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.config.coloredEvents.length > 0) {
|
// Color events if custom color is specified
|
||||||
for (var ev in this.config.coloredEvents) {
|
if (this.config.customEvents.length > 0) {
|
||||||
var needle = new RegExp(this.config.coloredEvents[ev].keyword, "gi");
|
for (ev in this.config.customEvents) {
|
||||||
|
if (typeof this.config.customEvents[ev].color !== "undefined" && this.config.customEvents[ev].color !== "") {
|
||||||
|
needle = new RegExp(this.config.customEvents[ev].keyword, "gi");
|
||||||
if (needle.test(event.title)) {
|
if (needle.test(event.title)) {
|
||||||
eventWrapper.style.cssText = "color:" + this.config.coloredEvents[ev].color;
|
eventWrapper.style.cssText = "color:" + this.config.customEvents[ev].color;
|
||||||
titleWrapper.style.cssText = "color:" + this.config.coloredEvents[ev].color;
|
titleWrapper.style.cssText = "color:" + this.config.customEvents[ev].color;
|
||||||
if (this.config.displaySymbol) symbolWrapper.style.cssText = "color:" + this.config.coloredEvents[ev].color;
|
if (this.config.displaySymbol) {
|
||||||
|
symbolWrapper.style.cssText = "color:" + this.config.customEvents[ev].color;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user