Tooltips (v2.4)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 13:52:04 +01:00
parent 406e9fed3a
commit 0e7a39344f
5 changed files with 61 additions and 7 deletions

View File

@ -152,6 +152,8 @@
.iconbtn:hover { border-color: var(--accent-strong); }
.btn .icon { margin-right: .45rem; }
.statusrow { display: flex; align-items: center; gap: .5rem; }
#tooltip { position: fixed; z-index: var(--z-tooltip); max-width: var(--tooltip-max); background: var(--text); color: var(--bg); font-size: var(--font-size-small); padding: .3rem .6rem; border-radius: 6px; overflow-wrap: anywhere; }
#tooltip[hidden] { display: none; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); }
.tabs button { font: inherit; border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 6px 12px; color: var(--muted); cursor: pointer; }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent-strong); font-weight: 600; }
@ -275,10 +277,11 @@
</div>
<h3>Nur Icon (mit zugänglichem Namen)</h3>
<div class="row">
<button class="iconbtn" type="button" aria-label="Suchen" title="Suchen"><svg class="icon" aria-hidden="true"><use href="#i-search"/></svg></button>
<button class="iconbtn" type="button" aria-label="Hinzufügen" title="Hinzufügen"><svg class="icon" aria-hidden="true"><use href="#i-plus"/></svg></button>
<button class="iconbtn" type="button" aria-label="Schließen" title="Schließen"><svg class="icon" aria-hidden="true"><use href="#i-x"/></svg></button>
<button class="iconbtn" type="button" aria-label="Suchen" data-tooltip="Suchen"><svg class="icon" aria-hidden="true"><use href="#i-search"/></svg></button>
<button class="iconbtn" type="button" aria-label="Hinzufügen" data-tooltip="Hinzufügen"><svg class="icon" aria-hidden="true"><use href="#i-plus"/></svg></button>
<button class="iconbtn" type="button" aria-label="Schließen" data-tooltip="Schließen"><svg class="icon" aria-hidden="true"><use href="#i-x"/></svg></button>
</div>
<p class="small">Tooltip per Hover (nach 0,4 s) oder Tastaturfokus; Escape schließt ihn.</p>
<h3>Zustände: Icon plus Text</h3>
<div class="statusrow" style="color:var(--ok)"><svg class="icon" aria-hidden="true"><use href="#i-ok"/></svg><span>Erfolg: Gespeichert</span></div>
<div class="statusrow" style="color:var(--warn)"><svg class="icon" aria-hidden="true"><use href="#i-warn"/></svg><span>Warnung: Verbindung langsam</span></div>
@ -464,6 +467,27 @@
seg("accent-seg", acc, setAccent);
document.getElementById("ind").indeterminate = true;
var tip = document.createElement("div"); tip.id = "tooltip"; tip.setAttribute("role", "tooltip"); tip.setAttribute("aria-hidden", "true"); tip.hidden = true; document.body.appendChild(tip);
var tipTimer = null, graceTimer = null, tipOwner = null;
function showTip(el) {
clearTimeout(tipTimer); clearTimeout(graceTimer);
tip.textContent = el.getAttribute("data-tooltip"); tip.hidden = false; tipOwner = el;
var r = el.getBoundingClientRect(), tr = tip.getBoundingClientRect(), gap = 6;
var top = r.top - tr.height - gap; if (top < 4) top = r.bottom + gap;
var left = Math.min(Math.max(4, r.left + r.width / 2 - tr.width / 2), window.innerWidth - tr.width - 4);
tip.style.top = top + "px"; tip.style.left = left + "px";
}
function hideTip() { clearTimeout(tipTimer); clearTimeout(graceTimer); tip.hidden = true; tipOwner = null; }
function hideSoon() { clearTimeout(tipTimer); graceTimer = setTimeout(hideTip, 120); }
document.querySelectorAll("[data-tooltip]").forEach(function (el) {
el.addEventListener("mouseenter", function () { clearTimeout(tipTimer); tipTimer = setTimeout(function () { showTip(el); }, 400); });
el.addEventListener("mouseleave", hideSoon);
el.addEventListener("focus", function () { showTip(el); });
el.addEventListener("blur", hideTip);
});
tip.addEventListener("mouseenter", function () { clearTimeout(graceTimer); });
tip.addEventListener("mouseleave", hideTip);
document.addEventListener("keydown", function (e) { if (e.key === "Escape" && !tip.hidden) hideTip(); });
var tabs = Array.prototype.slice.call(document.querySelectorAll("#tabs [role=tab]"));
function selectTab(i, focus) {
tabs.forEach(function (b, j) {