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) */
|
/* Würfelspalte und ankreuzbare Praxispunkte (PP) */
|
||||||
.skill-table th.die, .skill-table td.die { width: 3.4rem; white-space: nowrap; }
|
.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; }
|
.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 {
|
.pp-slot {
|
||||||
width: 0.68rem;
|
width: 1.05rem;
|
||||||
height: 0.68rem;
|
height: 1.05rem;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
border: 1px solid rgba(201, 162, 39, 0.55);
|
border: 1px solid rgba(201, 162, 39, 0.55);
|
||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
|
|
@ -827,9 +827,10 @@ input[type="file"] {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
transition: background 0.12s ease, border-color 0.12s ease;
|
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.is-filled { background: var(--gold); border-color: var(--gold); }
|
||||||
.pp-slot:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
|
.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 ------------------------- */
|
/* --- Boni: positiv grün, null grau, negativ rot ------------------------- */
|
||||||
.bonus-pos { color: #79d29a; }
|
.bonus-pos { color: #79d29a; }
|
||||||
|
|
|
||||||
|
|
@ -201,31 +201,42 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Praxispunkte im Charakterbogen: Klick setzt die Punkte ohne Reload
|
// Praxispunkte im Charakterbogen: Klick setzt die Punkte ohne Reload.
|
||||||
document.addEventListener('submit', async function (event) {
|
// Der Klick wird abgefangen, damit die Kästchen sofort reagieren; scheitert
|
||||||
const form = event.target.closest('[data-pp-form]');
|
// der Aufruf, wird das Formular normal abgeschickt (funktioniert ohne JS).
|
||||||
if (!form) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const pressed = event.submitter;
|
const body = new FormData(form);
|
||||||
const want = pressed ? parseInt(pressed.value, 10) || 0 : 0;
|
body.set('pp', slot.value);
|
||||||
try {
|
try {
|
||||||
const response = await fetch(form.action, {
|
const response = await fetch(form.action, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: new FormData(form),
|
body: body,
|
||||||
headers: { 'X-Requested-With': 'fetch' }
|
headers: { 'X-Requested-With': 'fetch' }
|
||||||
});
|
});
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
if (!data || data.ok !== true) {
|
if (!data || data.ok !== true) {
|
||||||
|
form.submit();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
form.querySelectorAll('.pp-slot').forEach(function (slot) {
|
form.querySelectorAll('.pp-slot').forEach(function (button) {
|
||||||
const value = parseInt(slot.value, 10) || 0;
|
const value = parseInt(button.value, 10) || 0;
|
||||||
const filled = value <= data.pp;
|
const filled = value <= data.pp;
|
||||||
slot.classList.toggle('is-filled', filled);
|
button.classList.toggle('is-filled', filled);
|
||||||
slot.setAttribute('aria-pressed', filled ? 'true' : 'false');
|
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) {
|
} catch (error) {
|
||||||
form.submit();
|
form.submit();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -135,6 +135,7 @@ $base = url('/characters/' . $cid);
|
||||||
title="<?= $slot ?> Praxispunkt<?= $slot === 1 ? '' : 'e' ?>"
|
title="<?= $slot ?> Praxispunkt<?= $slot === 1 ? '' : 'e' ?>"
|
||||||
aria-pressed="<?= $slot <= $pp ? 'true' : 'false' ?>"></button>
|
aria-pressed="<?= $slot <= $pp ? 'true' : 'false' ?>"></button>
|
||||||
<?php endfor; ?>
|
<?php endfor; ?>
|
||||||
|
<span class="pp-count"><?= $pp ?>/<?= (int) WS_SKILL_PRACTICE_SLOTS ?></span>
|
||||||
</form>
|
</form>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
|
|
||||||
|
|
@ -189,6 +189,7 @@ $equipped = array_values(array_filter($items, static fn ($item) => (int) $item['
|
||||||
title="<?= $slot ?> Praxispunkt<?= $slot === 1 ? '' : 'e' ?>"
|
title="<?= $slot ?> Praxispunkt<?= $slot === 1 ? '' : 'e' ?>"
|
||||||
aria-pressed="<?= $slot <= $pp ? 'true' : 'false' ?>"></button>
|
aria-pressed="<?= $slot <= $pp ? 'true' : 'false' ?>"></button>
|
||||||
<?php endfor; ?>
|
<?php endfor; ?>
|
||||||
|
<span class="pp-count"><?= $pp ?>/<?= (int) WS_SKILL_PRACTICE_SLOTS ?></span>
|
||||||
</form>
|
</form>
|
||||||
</td>
|
</td>
|
||||||
<td class="muted"><?= e((string) $skill['note']) ?></td>
|
<td class="muted"><?= e((string) $skill['note']) ?></td>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue