From 142f98e03bc3eb6e4c8c4b8ef1033aa015a2d339 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Sat, 18 Dec 2021 09:38:09 +0100 Subject: [PATCH] change stripcalender load per module --- cal.js | 86 ++--------------------------------------------- index.html | 4 +-- stripcalender.mjs | 83 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 85 deletions(-) create mode 100644 stripcalender.mjs diff --git a/cal.js b/cal.js index 796f96d..5b8a34a 100644 --- 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()); diff --git a/index.html b/index.html index 8e1b295..09e8017 100644 --- a/index.html +++ b/index.html @@ -4,9 +4,9 @@ Kalender - + - +
diff --git a/stripcalender.mjs b/stripcalender.mjs new file mode 100644 index 0000000..7dee53e --- /dev/null +++ b/stripcalender.mjs @@ -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); + } + } +} -- 2.39.5