-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtimetable.html
executable file
·57 lines (45 loc) · 1.56 KB
/
timetable.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
---
layout: default
---
{% assign lehrveranstaltungen = site.lehrveranstaltungen | sort: 'title' %}
{% assign cards = "" | split: "" %} {% for lehrveranstaltung in lehrveranstaltungen %}
{% if lehrveranstaltung.typ != "other" %}
{% capture card %}
{% include veranstaltungsinfo-klein.html lehrveranstaltung=lehrveranstaltung %}
{% endcapture %}
{% assign cards = cards | push: card %}
{% endif %}
{% endfor %}
<section class="section">
<div class="container" data-starting-date="date-{{site.data.dates["week-1"]["day-1"]["datum"]}}">
<h2 class="title is-1">Zeitplan</h2>
{% include /functions/zeitplan.html %}
</div>
</section>
<script>
Date.getWeeksBetween = function (date1, date2) {
const ONE_WEEK = 1000 * 60 * 60 * 24 * 7;
const date1_ms = date1.getTime();
const date2_ms = date2.getTime();
const difference_ms = Math.abs(date1_ms - date2_ms);
return Math.floor(difference_ms / ONE_WEEK);
}
Date.prototype.getFirstDayOfWeek = function () {
const day = this.getDay();
const currDate = this.getDate();
const tempDate = new Date(this.toString());
if (day > 0) {
tempDate.setDate(currDate - (day - 1))
}
return tempDate;
}
const startingDateData = document.querySelector("[data-starting-date]").dataset.startingDate.replace("date-", "");
const startingDate = new Date(startingDateData);
const today = new Date();
// counting starts at 1
let diffWeek = Date.getWeeksBetween(startingDate.getFirstDayOfWeek(), today) + 1;
let scrollTarget = `#week-${diffWeek}`;
document.querySelector(scrollTarget).scrollIntoView({
behavior: 'smooth'
});
</script>