diff --git a/server/content/regattas.php b/server/content/regattas.php index 465b908..1950863 100644 --- a/server/content/regattas.php +++ b/server/content/regattas.php @@ -14,6 +14,11 @@ $sp['output'] .= $tpl->load('card', [$content]); + // To today + $content = $tpl->load('button', [' Heute ', '#', 'html-id' => 'button-totoday']); + + $sp['output'] .= $tpl->load('card', [$content]); + // Regattas $content = '

'; $content .= $tpl->load('input', ['html-id' => 'input-search', 'placeholder' => 'Suche', 'type' => 'text', 'css-class' => 'mt-2']); diff --git a/server/scripts/regattas.js b/server/scripts/regattas.js index 076b786..17adcf0 100644 --- a/server/scripts/regattas.js +++ b/server/scripts/regattas.js @@ -1,3 +1,10 @@ +Element.prototype.documentOffsetTop = function() { + return this.offsetTop + (this.offsetParent ? this.offsetParent.documentOffsetTop() : 0); +}; +function scrollToToday() { + window.scrollTo({ top: document.getElementById('div-today').documentOffsetTop() - (window.innerHeight / 2), behavior: 'smooth' }); +} + function selectChange(callSiteScript = true) { var val = $('#select-year').val(); if (val == "user") { @@ -60,7 +67,7 @@ async function drawList () { var list = ''; rows.forEach(function (entry) { if (entry == null) { - list += '
Heute ist der ' + formatDate('d.m.Y', today) + '
'; + list += '
Heute ist der ' + formatDate('d.m.Y', today) + '
'; } else if (search($('#input-search').val(), entry.keywords)) { list += entry.content; } @@ -76,6 +83,7 @@ var siteScript = async function() { $('#select-year').change(selectChange); $('#button-show').click(buttonShowPressed); $('#input-search').on('input', drawList); + $('#button-totoday').click(scrollToToday); } today = getToday(); @@ -84,6 +92,9 @@ var siteScript = async function() { var maxDate = parseDate($('#input-to').val()); var regattas = await dbGetRegattasRange(minDate, maxDate); + if (minDate <= today && maxDate >= today) $('#button-totoday').parent().parent().show(); + else $('#button-totoday').parent().parent().hide(); + var selectedYear = $('#select-year').val(); var years = await dbGetData('years');