From: Bastian Dehn Date: Sat, 18 Dec 2021 21:01:30 +0000 (+0100) Subject: change: mark weekend and fist last monthday X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=a051f29aab38d08b029f075cdcbfa6e724e0d292;p=calender.git change: mark weekend and fist last monthday --- diff --git a/stripcalender.mjs b/stripcalender.mjs index 6ad0ede..882678d 100644 --- a/stripcalender.mjs +++ b/stripcalender.mjs @@ -69,12 +69,10 @@ export class StripCalender let th = null; for (let i = 1; i <= days; i++) { - this._date.setDate(i); th = document.createElement("th"); - if (this._date.getDay() == 0 - || this._date.getDay() == 6) - th.classList.add("weekend"); + this.markFirstAndLastDayOfMonth(th, i, days); + this.markWeekendDays(th, i); th.innerText = i; tr.appendChild(th); @@ -105,12 +103,27 @@ export class StripCalender this._date.setDate(i); th = document.createElement("th"); - if (this._date.getDay() == 0 - || this._date.getDay() == 6) - th.classList.add("weekend"); + this.markFirstAndLastDayOfMonth(th, i, days); + this.markWeekendDays(th, i); th.innerText = weekday[this._date.getDay()]; tr.appendChild(th); } } + + markFirstAndLastDayOfMonth(th, day, maxdays) + { + if (day == 1) + th.classList.add("first"); + if (day == maxdays) + th.classList.add("last"); + } + + markWeekendDays(th, day) + { + this._date.setDate(day); + + if (this._date.getDay() == 0 || this._date.getDay() == 6) + th.classList.add("weekend"); + } }