]> gitweb.hhaalo.de Git - calender.git/commitdiff
change: class to strip calender
authorBastian Dehn <hhaalo@arcor.de>
Fri, 17 Dec 2021 17:23:49 +0000 (18:23 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Fri, 17 Dec 2021 17:23:49 +0000 (18:23 +0100)
cal.js

diff --git a/cal.js b/cal.js
index b38e9a3c24425d47f1b8b874c4fde1a419d92fd4..1092b16ac3cd4e25c472227244a5b1d003e6e865 100644 (file)
--- a/cal.js
+++ b/cal.js
@@ -1,81 +1,69 @@
-class Month
+class StripCalender
 {
-       constructor(year, month) {
-               let date = new Date(year, month, 0)
-               this.year = year;
-               this.number = date.getMonth();
-               this.days = date.getDate();
-               const monthnames = [ "Januar", "Februar", "März", "April",
-                       "Mai", "Juni", "Juli", "August", "September", "Oktober",
-                       "November", "Dezember" ];
-               this.name = monthnames[this.number];
-       }
-
-       createMonthHeader() {
-               let month = document.createElement("th");
-               let span = document.createAttribute("colspan");
-
-               month.innerText = this.name;
-               span.value = this.days
-
-               month.setAttributeNode(span);
-
-               return month;
+       constructor(year)
+       {
+               this._year = year;
+               this._date = new Date(year);
        }
 
-       createDaysHeader(tr) {
+       createMonthHeader()
+       {
+               let tr = document.createElement("tr");
+               tr.classList.add("row");
+               tr.classList.add("month");
                let th = null;
+               let attr = null;
+               const monthnames = [ "Januar", "Februar", "März", "April",
+                       "Mai", "Juni", "Juli", "August", "September", "Oktober",
+                       "November", "Dezember" ];
 
-               for (let i = 1; i < this.days + 1; i++) {
+               for (let i = 1; i <= 12; i++) {
+                       this._date.setMonth(i, 0);
                        th = document.createElement("th");
-                       th.innerText = i;
+                       attr = document.createAttribute("colspan");
+                       attr.value = this._date.getDate();
+                       th.setAttributeNode(attr);
+                       th.innerText = monthnames[i - 1];
                        tr.appendChild(th);
                }
 
-               return th;
+               return tr;
        }
-}
 
+       createMonthDaysHeader()
+       {
+               let tr = document.createElement("tr");
+               tr.classList.add("row");
+               tr.classList.add("monthday");
 
-function addMonthDaysHeader()
-{
-       let date = new Date();
-       let month = null;
-       let monthdaysheader = document.createElement("tr");
-       monthdaysheader.classList.add("row");
-       monthdaysheader.classList.add("monthday");
+               for (let i = 1; i <= 12; i++) {
+                       this._date.setMonth(i, 0);
+                       this.appendOneMonthDaysHeader(tr, this._date.getDate());
+               }
 
-       for (let i = 0; i < 12; i++) {
-               month = new Month(date.getYear(), i);
-               month.createDaysHeader(monthdaysheader);
+               return tr;
        }
 
-       return monthdaysheader;
-}
-
-function addMonthHeader()
-{
-       let date = new Date();
-       let month = null;
-       let header = document.createElement("tr");
-       header.classList.add("row");
-       header.classList.add("month");
+       appendOneMonthDaysHeader(tr, days)
+       {
+               let th = null;
 
-       for (let i = 0; i < 12; i++) {
-               month = new Month(date.getYear(), i);
-               header.appendChild(month.createMonthHeader());
+               for (let i = 1; i <= days; i++) {
+                       th = document.createElement("th");
+                       th.innerText = i;
+                       tr.appendChild(th);
+               }
        }
-
-       return header;
 }
 
 function calender()
 {
        let cal = document.getElementById("cal");
        let table = document.createElement("table");
+       let calender = new StripCalender((new Date()).getYear());
 
-       table.appendChild(addMonthHeader());
-       table.appendChild(addMonthDaysHeader());
+       table.appendChild(calender.createMonthHeader());
+       table.appendChild(calender.createMonthDaysHeader());
 
        cal.appendChild(table);
 }