]> gitweb.hhaalo.de Git - calender.git/commitdiff
change: mark weekend and fist last monthday
authorBastian Dehn <hhaalo@arcor.de>
Sat, 18 Dec 2021 21:01:30 +0000 (22:01 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 18 Dec 2021 21:01:30 +0000 (22:01 +0100)
stripcalender.mjs

index 6ad0edef47ffd47546d5e81d7612d3cc27a9286e..882678d9d6c59545bfdf80defd6e91bbae2cf0a3 100644 (file)
@@ -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");
+       }
 }