More es6 notations

This commit is contained in:
rejas 2021-02-09 17:37:43 +01:00 committed by veeck
parent 5e6cbeb9ba
commit 85c9d3b331

View File

@ -174,22 +174,22 @@ Module.register("calendar", {
return wrapper; return wrapper;
} }
let currentFadeStep = 0;
let startFade;
let fadeSteps;
if (this.config.fade && this.config.fadePoint < 1) { if (this.config.fade && this.config.fadePoint < 1) {
if (this.config.fadePoint < 0) { if (this.config.fadePoint < 0) {
this.config.fadePoint = 0; this.config.fadePoint = 0;
} }
var startFade = events.length * this.config.fadePoint; startFade = events.length * this.config.fadePoint;
var fadeSteps = events.length - startFade; fadeSteps = events.length - startFade;
} }
var currentFadeStep = 0; let lastSeenDate = "";
var lastSeenDate = "";
var ev;
var needle;
for (var e in events) { events.forEach((event, index) => {
var event = events[e]; const dateAsString = moment(event.startDate, "x").format(this.config.dateFormat);
var dateAsString = moment(event.startDate, "x").format(this.config.dateFormat);
if (this.config.timeFormat === "dateheaders") { if (this.config.timeFormat === "dateheaders") {
if (lastSeenDate !== dateAsString) { if (lastSeenDate !== dateAsString) {
const dateRow = document.createElement("tr"); const dateRow = document.createElement("tr");
@ -202,9 +202,9 @@ Module.register("calendar", {
dateRow.appendChild(dateCell); dateRow.appendChild(dateCell);
wrapper.appendChild(dateRow); wrapper.appendChild(dateRow);
if (e >= startFade) { if (this.config.fade && index >= startFade) {
//fading //fading
currentFadeStep = e - startFade; currentFadeStep = index - startFade;
dateRow.style.opacity = 1 - (1 / fadeSteps) * currentFadeStep; dateRow.style.opacity = 1 - (1 / fadeSteps) * currentFadeStep;
} }
@ -233,9 +233,9 @@ Module.register("calendar", {
const symbols = this.symbolsForEvent(event); const symbols = this.symbolsForEvent(event);
// If symbols are displayed and custom symbol is set, replace event symbol // If symbols are displayed and custom symbol is set, replace event symbol
if (this.config.displaySymbol && this.config.customEvents.length > 0) { if (this.config.displaySymbol && this.config.customEvents.length > 0) {
for (ev in this.config.customEvents) { for (let ev in this.config.customEvents) {
if (typeof this.config.customEvents[ev].symbol !== "undefined" && this.config.customEvents[ev].symbol !== "") { if (typeof this.config.customEvents[ev].symbol !== "undefined" && this.config.customEvents[ev].symbol !== "") {
needle = new RegExp(this.config.customEvents[ev].keyword, "gi"); let needle = new RegExp(this.config.customEvents[ev].keyword, "gi");
if (needle.test(event.title)) { if (needle.test(event.title)) {
symbols[0] = this.config.customEvents[ev].symbol; symbols[0] = this.config.customEvents[ev].symbol;
break; break;
@ -274,9 +274,9 @@ Module.register("calendar", {
// Color events if custom color is specified // Color events if custom color is specified
if (this.config.customEvents.length > 0) { if (this.config.customEvents.length > 0) {
for (ev in this.config.customEvents) { for (let ev in this.config.customEvents) {
if (typeof this.config.customEvents[ev].color !== "undefined" && this.config.customEvents[ev].color !== "") { if (typeof this.config.customEvents[ev].color !== "undefined" && this.config.customEvents[ev].color !== "") {
needle = new RegExp(this.config.customEvents[ev].keyword, "gi"); let needle = new RegExp(this.config.customEvents[ev].keyword, "gi");
if (needle.test(event.title)) { if (needle.test(event.title)) {
// Respect parameter ColoredSymbolOnly also for custom events // Respect parameter ColoredSymbolOnly also for custom events
if (!this.config.coloredSymbolOnly) { if (!this.config.coloredSymbolOnly) {
@ -397,8 +397,8 @@ Module.register("calendar", {
wrapper.appendChild(eventWrapper); wrapper.appendChild(eventWrapper);
// Create fade effect. // Create fade effect.
if (e >= startFade) { if (index >= startFade) {
currentFadeStep = e - startFade; currentFadeStep = index - startFade;
eventWrapper.style.opacity = 1 - (1 / fadeSteps) * currentFadeStep; eventWrapper.style.opacity = 1 - (1 / fadeSteps) * currentFadeStep;
} }
@ -420,13 +420,13 @@ Module.register("calendar", {
wrapper.appendChild(locationRow); wrapper.appendChild(locationRow);
if (e >= startFade) { if (index >= startFade) {
currentFadeStep = e - startFade; currentFadeStep = index - startFade;
locationRow.style.opacity = 1 - (1 / fadeSteps) * currentFadeStep; locationRow.style.opacity = 1 - (1 / fadeSteps) * currentFadeStep;
} }
} }
} }
} });
return wrapper; return wrapper;
}, },
@ -480,10 +480,11 @@ Module.register("calendar", {
const future = moment().startOf("day").add(this.config.maximumNumberOfDays, "days").toDate(); const future = moment().startOf("day").add(this.config.maximumNumberOfDays, "days").toDate();
let events = []; let events = [];
for (var c in this.calendarData) { for (const calendarUrl in this.calendarData) {
var calendar = this.calendarData[c]; const calendar = this.calendarData[calendarUrl];
for (var e in calendar) { console.log(calendar);
var event = JSON.parse(JSON.stringify(calendar[e])); // clone object for (const e in calendar) {
const event = JSON.parse(JSON.stringify(calendar[e])); // clone object
if (event.endDate < now) { if (event.endDate < now) {
continue; continue;
@ -502,7 +503,7 @@ Module.register("calendar", {
if (this.listContainsEvent(events, event)) { if (this.listContainsEvent(events, event)) {
continue; continue;
} }
event.url = c; event.url = calendarUrl;
event.today = event.startDate >= today && event.startDate < today + 24 * 60 * 60 * 1000; event.today = event.startDate >= today && event.startDate < today + 24 * 60 * 60 * 1000;
/* if sliceMultiDayEvents is set to true, multiday events (events exceeding at least one midnight) are sliced into days, /* if sliceMultiDayEvents is set to true, multiday events (events exceeding at least one midnight) are sliced into days,
@ -514,7 +515,7 @@ Module.register("calendar", {
let midnight = moment(event.startDate, "x").clone().startOf("day").add(1, "day").format("x"); let midnight = moment(event.startDate, "x").clone().startOf("day").add(1, "day").format("x");
let count = 1; let count = 1;
while (event.endDate > midnight) { while (event.endDate > midnight) {
var thisEvent = JSON.parse(JSON.stringify(event)); // clone object const thisEvent = JSON.parse(JSON.stringify(event)); // clone object
thisEvent.today = thisEvent.startDate >= today && thisEvent.startDate < today + 24 * 60 * 60 * 1000; thisEvent.today = thisEvent.startDate >= today && thisEvent.startDate < today + 24 * 60 * 60 * 1000;
thisEvent.endDate = midnight; thisEvent.endDate = midnight;
thisEvent.title += " (" + count + "/" + maxCount + ")"; thisEvent.title += " (" + count + "/" + maxCount + ")";
@ -737,13 +738,13 @@ Module.register("calendar", {
} }
if (wrapEvents === true) { if (wrapEvents === true) {
var temp = ""; const words = string.split(" ");
var currentLine = ""; let temp = "";
var words = string.split(" "); let currentLine = "";
var line = 0; let line = 0;
for (var i = 0; i < words.length; i++) { for (let i = 0; i < words.length; i++) {
var word = words[i]; const word = words[i];
if (currentLine.length + word.length < (typeof maxLength === "number" ? maxLength : 25) - 1) { if (currentLine.length + word.length < (typeof maxLength === "number" ? maxLength : 25) - 1) {
// max - 1 to account for a space // max - 1 to account for a space
currentLine += word + " "; currentLine += word + " ";
@ -798,10 +799,10 @@ Module.register("calendar", {
* @returns {string} The transformed title. * @returns {string} The transformed title.
*/ */
titleTransform: function (title, titleReplace, wrapEvents, maxTitleLength, maxTitleLines) { titleTransform: function (title, titleReplace, wrapEvents, maxTitleLength, maxTitleLines) {
for (var needle in titleReplace) { for (let needle in titleReplace) {
var replacement = titleReplace[needle]; const replacement = titleReplace[needle];
var regParts = needle.match(/^\/(.+)\/([gim]*)$/); const regParts = needle.match(/^\/(.+)\/([gim]*)$/);
if (regParts) { if (regParts) {
// the parsed pattern is a regexp. // the parsed pattern is a regexp.
needle = new RegExp(regParts[1], regParts[2]); needle = new RegExp(regParts[1], regParts[2]);
@ -819,11 +820,10 @@ Module.register("calendar", {
* The all events available in one array, sorted on startdate. * The all events available in one array, sorted on startdate.
*/ */
broadcastEvents: function () { broadcastEvents: function () {
var eventList = []; const eventList = [];
for (var url in this.calendarData) { for (const url in this.calendarData) {
var calendar = this.calendarData[url]; for (const ev of this.calendarData[url]) {
for (var e in calendar) { const event = cloneObject(ev);
var event = cloneObject(calendar[e]);
event.symbol = this.symbolsForEvent(event); event.symbol = this.symbolsForEvent(event);
event.calendarName = this.calendarNameForUrl(url); event.calendarName = this.calendarNameForUrl(url);
event.color = this.colorForUrl(url); event.color = this.colorForUrl(url);