]> gitweb.hhaalo.de Git - calender.git/commitdiff
change stripcalender load per module
authorBastian Dehn <hhaalo@arcor.de>
Sat, 18 Dec 2021 08:38:09 +0000 (09:38 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 18 Dec 2021 08:38:09 +0000 (09:38 +0100)
cal.js
index.html
stripcalender.mjs [new file with mode: 0644]

diff --git a/cal.js b/cal.js
index 796f96d8113c45162a1783732ddcaf13b8f6eef9..5b8a34aad483ea3a3be7401d61aef371e4d759fa 100644 (file)
--- a/cal.js
+++ b/cal.js
@@ -1,86 +1,4 @@
-class StripCalender
-{
-       constructor(year)
-       {
-               this._date = new Date(year);
-       }
-
-       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 <= 12; i++) {
-                       this._date.setMonth(i, 0);
-                       th = document.createElement("th");
-                       attr = document.createAttribute("colspan");
-                       attr.value = this._date.getDate();
-                       th.setAttributeNode(attr);
-                       th.innerText = monthnames[i - 1];
-                       tr.appendChild(th);
-               }
-
-               return tr;
-       }
-
-       createMonthDaysHeader()
-       {
-               let tr = document.createElement("tr");
-               tr.classList.add("row");
-               tr.classList.add("monthday");
-
-               for (let i = 1; i <= 12; i++) {
-                       this._date.setMonth(i, 0);
-                       this.appendOneMonthDaysHeader(tr, this._date.getDate());
-               }
-
-               return tr;
-       }
-
-       appendOneMonthDaysHeader(tr, days)
-       {
-               let th = null;
-
-               for (let i = 1; i <= days; i++) {
-                       th = document.createElement("th");
-                       th.innerText = i;
-                       tr.appendChild(th);
-               }
-       }
-
-       createMonthWeekdayHeader()
-       {
-               let tr = document.createElement("tr");
-               tr.classList.add("row");
-               tr.classList.add("weekday");
-
-               for (let i = 1; i <= 12; i++) {
-                       this._date.setMonth(i, 0);
-                       this.appendOneMonthWeekdayHeader(tr, this._date.getDate());
-               }
-
-               return tr;
-       }
-
-       appendOneMonthWeekdayHeader(tr, days)
-       {
-               let th = null;
-               const weekday = [ "Mo", "Di", "Mi", "Do", "Fr", "Sa", "So" ]
-
-               for (let i = 1; i <= days; i++) {
-                       this._date.setDate(i);
-                       th = document.createElement("th");
-                       th.innerText = weekday[this._date.getDay()];
-                       tr.appendChild(th);
-               }
-       }
-}
+import { StripCalender } from './stripcalender.mjs';
 
 function calender()
 {
@@ -94,3 +12,5 @@ function calender()
 
        cal.appendChild(table);
 }
+
+document.addEventListener("onload", calender());
index 8e1b295163f66e8350dc021e95bf161b318cf2ee..09e8017066caeb51bbb54478db3672b49754dfcc 100644 (file)
@@ -4,9 +4,9 @@
                <title>Kalender</title>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                <link rel="stylesheet" type="text/css" href="cal.css" />
-               <script src="cal.js" type="text/javascript"></script>
+               <script src="cal.js" type="module"></script>
        </head>
-       <body onload="calender()">
+       <body>
                <div id=cal>
                </div>
        </body>
diff --git a/stripcalender.mjs b/stripcalender.mjs
new file mode 100644 (file)
index 0000000..7dee53e
--- /dev/null
@@ -0,0 +1,83 @@
+export class StripCalender
+{
+       constructor(year)
+       {
+               this._date = new Date(year);
+       }
+
+       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 <= 12; i++) {
+                       this._date.setMonth(i, 0);
+                       th = document.createElement("th");
+                       attr = document.createAttribute("colspan");
+                       attr.value = this._date.getDate();
+                       th.setAttributeNode(attr);
+                       th.innerText = monthnames[i - 1];
+                       tr.appendChild(th);
+               }
+
+               return tr;
+       }
+
+       createMonthDaysHeader()
+       {
+               let tr = document.createElement("tr");
+               tr.classList.add("row");
+               tr.classList.add("monthday");
+
+               for (let i = 1; i <= 12; i++) {
+                       this._date.setMonth(i, 0);
+                       this.appendOneMonthDaysHeader(tr, this._date.getDate());
+               }
+
+               return tr;
+       }
+
+       appendOneMonthDaysHeader(tr, days)
+       {
+               let th = null;
+
+               for (let i = 1; i <= days; i++) {
+                       th = document.createElement("th");
+                       th.innerText = i;
+                       tr.appendChild(th);
+               }
+       }
+
+       createMonthWeekdayHeader()
+       {
+               let tr = document.createElement("tr");
+               tr.classList.add("row");
+               tr.classList.add("weekday");
+
+               for (let i = 1; i <= 12; i++) {
+                       this._date.setMonth(i, 0);
+                       this.appendOneMonthWeekdayHeader(tr, this._date.getDate());
+               }
+
+               return tr;
+       }
+
+       appendOneMonthWeekdayHeader(tr, days)
+       {
+               let th = null;
+               const weekday = [ "Mo", "Di", "Mi", "Do", "Fr", "Sa", "So" ]
+
+               for (let i = 1; i <= days; i++) {
+                       this._date.setDate(i);
+                       th = document.createElement("th");
+                       th.innerText = weekday[this._date.getDay()];
+                       tr.appendChild(th);
+               }
+       }
+}