Files
OPENBUREAU/layouts/_partials/provenance.html
T
karim c6f5beaa7b ui: Zitieren zeigt Quellenangabe sichtbar + Copy-Fallback für HTTP
Vorher: stiller clipboard.writeText → tut auf HTTP/LAN nichts (Clipboard-API
nur in sicherem Kontext). Jetzt: Klick klappt ein Panel mit der lesbaren
Quellenangabe auf (user-select:all), „Kopieren" nutzt clipboard-API mit
execCommand-Fallback; schlägt das fehl, wird der Text markiert (manuelles
Strg/⌘+C).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-02 01:22:55 +02:00

79 lines
3.5 KiB
HTML

{{/* Herkunft eines Beitrags: Version (→ Commit), Verlauf, Zitieren.
Version/Verlauf nur, wenn Git-Info da ist (enableGitInfo) und repoURL gesetzt.
„Zitieren" kopiert eine Quellenangabe in die Zwischenablage. */}}
{{ $repo := site.Params.repoURL }}
{{ $author := .Params.author | default site.Params.author.name }}
<div class="provenance" aria-label="Herkunft">
{{ with .GitInfo }}
{{ with $repo }}
<a class="prov-version" href="{{ . }}/commit/{{ $.GitInfo.Hash }}" title="Diese Version als Commit ansehen">Version {{ $.GitInfo.AbbreviatedHash }}</a>
<span class="prov-sep">·</span>
<a class="prov-history" href="{{ . }}/commits/branch/main/content/{{ $.File.Path }}">Verlauf</a>
<span class="prov-sep">·</span>
{{ end }}
{{ end }}
<button type="button" class="prov-cite" aria-expanded="false"
data-title="{{ .Title }}"
data-author="{{ $author }}"
data-url="{{ .Permalink }}"
{{ with .GitInfo }}data-version="{{ .AbbreviatedHash }}"{{ end }}>Zitieren</button>
</div>
<div class="prov-citation" hidden>
<p class="prov-citation-text"></p>
<div class="prov-citation-actions">
<button type="button" class="prov-citation-copy">Kopieren</button>
<span class="prov-citation-status" role="status"></span>
</div>
</div>
<script>
(function () {
if (window.__provCite) return; window.__provCite = 1;
var btn = document.querySelector('.prov-cite');
var panel = document.querySelector('.prov-citation');
if (!btn || !panel) return;
var textEl = panel.querySelector('.prov-citation-text');
var copyBtn = panel.querySelector('.prov-citation-copy');
var statusEl = panel.querySelector('.prov-citation-status');
var d = btn.dataset;
var today = new Date().toLocaleDateString('de-CH');
var v = d.version ? ', Version ' + d.version : '';
// Format: Autor: Titel. OPENBUREAU, Version xxx. Abgerufen am TT.MM.JJJJ, URL
var cite = d.author + ': ' + d.title + '. OPENBUREAU' + v + '. Abgerufen am ' + today + ', ' + d.url;
textEl.textContent = cite;
function selectText() {
var r = document.createRange(); r.selectNodeContents(textEl);
var sel = window.getSelection(); sel.removeAllRanges(); sel.addRange(r);
}
function copy() {
if (navigator.clipboard && navigator.clipboard.writeText) {
return navigator.clipboard.writeText(cite);
}
// Fallback für unsichere Kontexte (HTTP/LAN): execCommand auf Auswahl.
return new Promise(function (resolve, reject) {
try {
var ta = document.createElement('textarea');
ta.value = cite; ta.style.position = 'fixed'; ta.style.opacity = '0';
document.body.appendChild(ta); ta.focus(); ta.select();
var ok = document.execCommand('copy');
document.body.removeChild(ta);
ok ? resolve() : reject();
} catch (e) { reject(e); }
});
}
btn.addEventListener('click', function () {
var open = panel.hasAttribute('hidden');
if (open) { panel.removeAttribute('hidden'); selectText(); }
else { panel.setAttribute('hidden', ''); }
btn.setAttribute('aria-expanded', String(open));
});
copyBtn.addEventListener('click', function () {
copy().then(function () { statusEl.textContent = 'Kopiert ✓'; })
.catch(function () { statusEl.textContent = 'Markiert — bitte mit Strg/⌘+C kopieren.'; selectText(); });
setTimeout(function () { statusEl.textContent = ''; }, 3000);
});
})();
</script>