// fixtures/share-link.mjs — the share page's Copy button. // // The published link is shown exactly once (suite ruling 16: the server // keeps a hash, not the URL), so copying it is the whole job of that // moment. Without script the page still works: the link is in a // read-only field that selects on focus, and a person copies it by hand. // With script this reveals the Copy button, writes the link to the // clipboard, and says so in the polite status line beside it. // // It carries no copy of its own: the "copied" wording is rendered by the // server from the catalog into data-copied. export function mountCopy(root) { const input = root.querySelector('[docs-share-url-input]') const button = root.querySelector('[docs-share-copy]') const status = root.querySelector('[docs-share-copy-status]') if (!input || !button) return false input.addEventListener('focus', () => input.select()) button.hidden = false button.addEventListener('click', async () => { input.focus() input.select() let ok = false try { if (navigator.clipboard && navigator.clipboard.writeText) { await navigator.clipboard.writeText(input.value) ok = true } } catch { ok = false } if (!ok) { try { ok = document.execCommand('copy') } catch { ok = false } } if (status) status.textContent = ok ? button.getAttribute('data-copied') || '' : '' }) return true } const root = document.querySelector('[docs-share-public]') if (root) mountCopy(root)