-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththreeMonthCalender.html
221 lines (212 loc) · 6.43 KB
/
threeMonthCalender.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<!DOCTYPE html>
<html lang="de-DE">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<title>Dreimonats Kalender</title>
<script>
var Months = ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"];
function prepareSite()
{
document.getElementById('pickedMonth').addEventListener("change",function(){changeDate();});
document.getElementById('today').addEventListener("click",function(){gotoToday();});
document.getElementById('prev').addEventListener("click",function(){gotoNext(-1);});
document.getElementById('next').addEventListener("click",function(){gotoNext(1);});
gotoToday();
}
function changeDate()
{
let pickedMonth = new Date(document.getElementById('pickedMonth').value + "-01");
let lastMonth = new Date(pickedMonth.getFullYear(), pickedMonth.getMonth()-1, 1);
let nextMonth = new Date(pickedMonth.getFullYear(), pickedMonth.getMonth()+1, 1);
let divLast = document.getElementById('letzter');
let divCurrent = document.getElementById('dieser');
let divNext = document.getElementById('naechster');
buildMonthTable(divLast,lastMonth);
buildMonthTable(divCurrent,pickedMonth);
buildMonthTable(divNext,nextMonth);
}
Date.prototype.getWeekNumber = function(){
var d = new Date(Date.UTC(this.getFullYear(), this.getMonth(), this.getDate()));
var dayNum = d.getUTCDay() || 7;
d.setUTCDate(d.getUTCDate() + 4 - dayNum);
var yearStart = new Date(Date.UTC(d.getUTCFullYear(),0,1));
return Math.ceil((((d - yearStart) / 86400000) + 1)/7)
};
function buildMonthTable(parentDiv, buildMonth)
{
//Clar old content
parentDiv.innerHTML = '';
//Caption of Month Table
let caption = document.createElement("h2");
caption.innerText = Months[buildMonth.getMonth()] + " " + buildMonth.getFullYear();
parentDiv.appendChild(caption);
let tempDay = new Date(buildMonth);
tempDay.setHours(0,0,0,0);
//Table
let tempWeekday = tempDay.getDay();
if(tempWeekday != 1)
{
tempWeekday -= 1;
if(tempWeekday < 0)
{
tempWeekday = 6;
}
tempDay.setDate(tempDay.getDate() - tempWeekday);
}
let tempTable = document.createElement("table");
let tempLine = document.createElement("tr");
let tempField;
['KW','Mo','Di','Mi','Do','Fr','Sa','So'].forEach((column) => {
tempField = document.createElement("th");
if(column === 'KW')
{
tempField.classList.add('calenderWeek');
}
tempField.innerText = column;
tempLine.appendChild(tempField);
});
tempTable.appendChild(tempLine);
do
{
tempLine = document.createElement("tr");
tempField = document.createElement("td");
tempField.classList.add('calenderWeek');
tempField.innerText = tempDay.getWeekNumber();
tempLine.appendChild(tempField);
do
{
tempField = document.createElement("td");
if(tempDay.getMonth() != buildMonth.getMonth())
{
tempField.classList.add('outsideMonth');
}
if(tempDay.valueOf()===new Date().setHours(0,0,0,0).valueOf())
{
tempField.classList.add('today');
}
tempField.innerText = tempDay.getDate();
tempLine.appendChild(tempField);
tempDay.setDate(tempDay.getDate() + 1);
} while (tempDay.getDay() !== 1);
tempTable.appendChild(tempLine);
} while (tempDay.getMonth() === buildMonth.getMonth());
parentDiv.appendChild(tempTable);
}
function gotoToday()
{
let today = new Date();
document.getElementById('pickedMonth').value = today.getFullYear() + "-" + (today.getMonth()<9?"0":"") + (today.getMonth()+1);
changeDate();
}
function gotoNext(addMonth)
{
let pickedMonth = new Date(document.getElementById('pickedMonth').value + "-01");
pickedMonth.setMonth(pickedMonth.getMonth() + addMonth);
document.getElementById('pickedMonth').value = pickedMonth.getFullYear() + "-" + (pickedMonth.getMonth()<9?"0":"") + (pickedMonth.getMonth()+1);
changeDate();
}
window.onload = prepareSite;
</script>
<style>
body {
background-color: rgb(10,148,255);
}
div.wrapper {
background-color: white;
width: 60%;
margin: 0 auto;
}
div#config {
width: fit-content;
padding: 0;
}
div.content div {
width: fit-content;
padding: 5px 1.3em ;
margin: 0 auto;
}
div.content div:not(#config) {
height: 14em;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
td {
text-align: center;
padding: 3px;
border-style: solid;
border-width: 2px;
border-color: rgb(192,192,192);
font-weight: bold;
}
td.today {
background: rgb(255,127,127);
border-color: rgb(255,0,0);
}
td.outsideMonth {
color: rgb(120,120,120);
font-weight: normal;
}
td.calenderWeek {
font-style: italic;
border-style: none;
font-weight: normal;
padding-right: 0.4em;
text-align: left;
}
th {
border-style: solid;
border-width: 2px;
border-color: rgb(192,192,192);
border-top: none;
}
th.calenderWeek {
border-style: none;
font-style: italic;
padding-right: 0.4em;
text-align: left;
}
h1 {
width: fit-content;
margin: 0.4em auto 1em auto;
}
h2 {
margin-top: 0.4em;
margin-bottom: 0.2em;
}
div.calenderWrapper {
width: fit-content;
display: inline-flex;
align-items: center;
}
</style>
</head>
<body>
<div class="wrapper">
<h1>Dreimonats Kalender</h1>
<div class="content">
<div id="config">
<lable for="pickedMonth">Aktueller Monat: </lable>
<input id="pickedMonth" type="month">
<button type="button" id="today">heute</button>
</div>
</div>
<div class="content" id="kalender">
<div id="letzter"></div>
<hr>
<div>
<div class="calenderWrapper">
<button type="button" id="prev">zurück</button>
<div id="dieser"></div>
<button type="button" id="next">weiter</button>
</div>
</div>
<hr>
<div id="naechster"></div>
</div>
</div>
</body>
</html>