Praxispunkte: groessere Klickflaeche, Zaehler und Klick-Handler statt Submit
This commit is contained in:
parent
3795c517fb
commit
1acb99dc51
4 changed files with 29 additions and 15 deletions
|
|
@ -816,10 +816,10 @@ input[type="file"] {
|
|||
/* Würfelspalte und ankreuzbare Praxispunkte (PP) */
|
||||
.skill-table th.die, .skill-table td.die { width: 3.4rem; white-space: nowrap; }
|
||||
.skill-table td.pp-cell { white-space: nowrap; vertical-align: baseline; }
|
||||
.pp-slots { display: inline-flex; gap: 0.16rem; margin: 0; padding: 0; border: 0; }
|
||||
.pp-slots { display: inline-flex; gap: 0.2rem; margin: 0; padding: 0; border: 0; }
|
||||
.pp-slot {
|
||||
width: 0.68rem;
|
||||
height: 0.68rem;
|
||||
width: 1.05rem;
|
||||
height: 1.05rem;
|
||||
padding: 0;
|
||||
border: 1px solid rgba(201, 162, 39, 0.55);
|
||||
border-radius: 2px;
|
||||
|
|
@ -827,9 +827,10 @@ input[type="file"] {
|
|||
cursor: pointer;
|
||||
transition: background 0.12s ease, border-color 0.12s ease;
|
||||
}
|
||||
.pp-slot:hover { border-color: var(--gold); }
|
||||
.pp-slot:hover { border-color: var(--gold); background: rgba(201, 162, 39, 0.18); }
|
||||
.pp-slot.is-filled { background: var(--gold); border-color: var(--gold); }
|
||||
.pp-slot:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
|
||||
.pp-count { margin-left: 0.4rem; font-size: 0.78rem; color: var(--parchment-dim); font-variant-numeric: tabular-nums; }
|
||||
|
||||
/* --- Boni: positiv grün, null grau, negativ rot ------------------------- */
|
||||
.bonus-pos { color: #79d29a; }
|
||||
|
|
|
|||
|
|
@ -201,31 +201,42 @@
|
|||
});
|
||||
}
|
||||
|
||||
// Praxispunkte im Charakterbogen: Klick setzt die Punkte ohne Reload
|
||||
document.addEventListener('submit', async function (event) {
|
||||
const form = event.target.closest('[data-pp-form]');
|
||||
if (!form) {
|
||||
// Praxispunkte im Charakterbogen: Klick setzt die Punkte ohne Reload.
|
||||
// Der Klick wird abgefangen, damit die Kästchen sofort reagieren; scheitert
|
||||
// der Aufruf, wird das Formular normal abgeschickt (funktioniert ohne JS).
|
||||
document.addEventListener('click', async function (event) {
|
||||
const slot = event.target.closest('.pp-slot');
|
||||
if (!slot) {
|
||||
return;
|
||||
}
|
||||
const form = slot.closest('[data-pp-form]');
|
||||
if (!form || typeof window.fetch !== 'function') {
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
const pressed = event.submitter;
|
||||
const want = pressed ? parseInt(pressed.value, 10) || 0 : 0;
|
||||
const body = new FormData(form);
|
||||
body.set('pp', slot.value);
|
||||
try {
|
||||
const response = await fetch(form.action, {
|
||||
method: 'POST',
|
||||
body: new FormData(form),
|
||||
body: body,
|
||||
headers: { 'X-Requested-With': 'fetch' }
|
||||
});
|
||||
const data = await response.json();
|
||||
if (!data || data.ok !== true) {
|
||||
form.submit();
|
||||
return;
|
||||
}
|
||||
form.querySelectorAll('.pp-slot').forEach(function (slot) {
|
||||
const value = parseInt(slot.value, 10) || 0;
|
||||
form.querySelectorAll('.pp-slot').forEach(function (button) {
|
||||
const value = parseInt(button.value, 10) || 0;
|
||||
const filled = value <= data.pp;
|
||||
slot.classList.toggle('is-filled', filled);
|
||||
slot.setAttribute('aria-pressed', filled ? 'true' : 'false');
|
||||
button.classList.toggle('is-filled', filled);
|
||||
button.setAttribute('aria-pressed', filled ? 'true' : 'false');
|
||||
});
|
||||
const count = form.querySelector('.pp-count');
|
||||
if (count) {
|
||||
count.textContent = data.pp + '/' + form.querySelectorAll('.pp-slot').length;
|
||||
}
|
||||
} catch (error) {
|
||||
form.submit();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -135,6 +135,7 @@ $base = url('/characters/' . $cid);
|
|||
title="<?= $slot ?> Praxispunkt<?= $slot === 1 ? '' : 'e' ?>"
|
||||
aria-pressed="<?= $slot <= $pp ? 'true' : 'false' ?>"></button>
|
||||
<?php endfor; ?>
|
||||
<span class="pp-count"><?= $pp ?>/<?= (int) WS_SKILL_PRACTICE_SLOTS ?></span>
|
||||
</form>
|
||||
</td>
|
||||
<td>
|
||||
|
|
|
|||
|
|
@ -189,6 +189,7 @@ $equipped = array_values(array_filter($items, static fn ($item) => (int) $item['
|
|||
title="<?= $slot ?> Praxispunkt<?= $slot === 1 ? '' : 'e' ?>"
|
||||
aria-pressed="<?= $slot <= $pp ? 'true' : 'false' ?>"></button>
|
||||
<?php endfor; ?>
|
||||
<span class="pp-count"><?= $pp ?>/<?= (int) WS_SKILL_PRACTICE_SLOTS ?></span>
|
||||
</form>
|
||||
</td>
|
||||
<td class="muted"><?= e((string) $skill['note']) ?></td>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue