Tippseite: Veralteten Runden-Anker automatisch korrigieren
This commit is contained in:
parent
c4674df14d
commit
7a283029bf
2 changed files with 72 additions and 7 deletions
|
|
@ -10,7 +10,7 @@ Diese Datei ersetzt die Erkundung. Erst hier nachschlagen, dann gezielt mit
|
|||
Abschnitt zu lesen. `docs/legacy/` ist absichtlich ausgeblendet (siehe
|
||||
`.ignore`); dort liegt der alte Laravel-Stand.
|
||||
|
||||
Umfang: 11253 Zeilen in 66 Dateien.
|
||||
Umfang: 11318 Zeilen in 66 Dateien.
|
||||
|
||||
## Einstiegspunkte
|
||||
|
||||
|
|
@ -122,7 +122,7 @@ ohne View.
|
|||
| `tippspiel/src/Views/round.php` | 101 | Tippübersicht aller Spieler bis zu einer Runde |
|
||||
| `tippspiel/src/Views/settings.php` | 293 | Eigene Daten: IBAN/PayPal/Mobilnummer, E-Mail, Erinnerungen |
|
||||
| `tippspiel/src/Views/tipps/game.php` | 80 | Tipp-Formular für ein einzelnes Spiel |
|
||||
| `tippspiel/src/Views/tipps/index.php` | 99 | Tipp-Startseite: Runden mit Spielen, eigenen Tipps und Joker |
|
||||
| `tippspiel/src/Views/tipps/index.php` | 164 | Tipp-Startseite: Runden mit Spielen, eigenen Tipps und Joker |
|
||||
| `tippspiel/src/Views/tipps/no_payment.php` | 9 | Hinweis auf offene Zahlung vor der Tippabgabe |
|
||||
| `tippspiel/src/Views/tipps/round.php` | 105 | Rundenliste mit Spielen, Tipps und Joker |
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,8 @@ $teamLogo = function ($name) {
|
|||
<h1>Tipps</h1>
|
||||
|
||||
<?php foreach ($rounds as $round): ?>
|
||||
<section class="tipp-round" id="round-<?php echo (int)$round['id']; ?>">
|
||||
<section class="tipp-round" id="round-<?php echo (int)$round['id']; ?>"
|
||||
data-lock-time="<?php echo $round['lock_time'] ? (int)$round['lock_time']->getTimestamp() : ''; ?>">
|
||||
<h2><?php echo htmlspecialchars($round['name']); ?></h2>
|
||||
<?php if ($round['lock_time']): ?>
|
||||
<div>Runde sperrt sich: <?php echo $round['lock_time']->format('d.m.Y H:i'); ?></div>
|
||||
|
|
@ -81,10 +82,74 @@ $teamLogo = function ($name) {
|
|||
|
||||
<?php if ($firstTippableRoundId !== null): ?>
|
||||
<script>
|
||||
// Wie im Legacy: ohne Anker zur ersten tippbaren Runde springen
|
||||
if (!location.hash) {
|
||||
document.getElementById('round-<?php echo $firstTippableRoundId; ?>').scrollIntoView();
|
||||
}
|
||||
// Wie im Legacy zur ersten tippbaren Runde springen. Zusätzlich wird ein
|
||||
// veralteter Anker (z. B. #round-981 aus einer früheren Speicherung) erkannt:
|
||||
// Liegt die verlinkte Runde inzwischen hinter der Sperre, springt die Seite
|
||||
// automatisch zur nächsten offenen Runde und korrigiert die Adresse.
|
||||
(function () {
|
||||
const firstTippableId = <?php echo (int)$firstTippableRoundId; ?>;
|
||||
const serverNowMs = <?php echo time() * 1000; ?>;
|
||||
const clientNowAtLoad = Date.now();
|
||||
const sections = Array.from(document.querySelectorAll('.tipp-round'));
|
||||
|
||||
function currentTimeMs() {
|
||||
return serverNowMs + (Date.now() - clientNowAtLoad);
|
||||
}
|
||||
|
||||
function isOpen(section) {
|
||||
const raw = section.dataset.lockTime;
|
||||
if (!raw) {
|
||||
return true; // ohne Sperrzeit (z. B. leere Runde) gilt als offen
|
||||
}
|
||||
const lockMs = Number(raw) * 1000;
|
||||
return Number.isFinite(lockMs) && lockMs > currentTimeMs();
|
||||
}
|
||||
|
||||
function firstOpenRound() {
|
||||
return sections.find(isOpen) || null;
|
||||
}
|
||||
|
||||
function roundFromHash() {
|
||||
const match = location.hash.match(/^#round-(\d+)$/);
|
||||
return match ? document.getElementById('round-' + match[1]) : null;
|
||||
}
|
||||
|
||||
function jumpToOpenRound() {
|
||||
const target = roundFromHash();
|
||||
if (target && isOpen(target)) {
|
||||
return; // bewusst verlinkte, noch offene Runde nicht überschreiben
|
||||
}
|
||||
|
||||
const fallback = firstOpenRound() || document.getElementById('round-' + firstTippableId);
|
||||
if (!fallback || !isOpen(fallback)) {
|
||||
return; // keine offene Runde mehr vorhanden
|
||||
}
|
||||
|
||||
fallback.scrollIntoView();
|
||||
const id = fallback.id.replace('round-', '');
|
||||
if (location.hash !== '#round-' + id) {
|
||||
history.replaceState(null, '', '#round-' + id);
|
||||
}
|
||||
}
|
||||
|
||||
function scheduleJump() {
|
||||
window.requestAnimationFrame(jumpToOpenRound);
|
||||
}
|
||||
|
||||
// Beim Laden: alter oder inzwischen gesperrter Anker wird sofort ersetzt.
|
||||
scheduleJump();
|
||||
|
||||
// Rückkehr aus dem Back-Forward-Cache oder aus dem Hintergrund.
|
||||
window.addEventListener('pageshow', scheduleJump);
|
||||
document.addEventListener('visibilitychange', function () {
|
||||
if (!document.hidden) {
|
||||
scheduleJump();
|
||||
}
|
||||
});
|
||||
|
||||
// Klick auf "Tipps" oder alter Anker, ohne dass die Seite neu lädt.
|
||||
window.addEventListener('hashchange', scheduleJump);
|
||||
})();
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue