site: multi-page structure with shared nav; rework services, keys, contact
This commit is contained in:
parent
03f38ab908
commit
82fc1c6e17
12 changed files with 143 additions and 151 deletions
21
public/copy.js
Normal file
21
public/copy.js
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
// One copy button per [data-copy] element. Copies the data-copy value when
|
||||
// set, otherwise the element's original text. Clipboard API needs a secure
|
||||
// context — https in prod, localhost in dev; both hold.
|
||||
document.querySelectorAll('[data-copy]').forEach(function (el) {
|
||||
var text = el.getAttribute('data-copy') || el.textContent.trim();
|
||||
|
||||
var btn = document.createElement('span');
|
||||
btn.innerText = 'Copy';
|
||||
btn.classList.add('copy-button');
|
||||
el.appendChild(btn);
|
||||
|
||||
btn.addEventListener('click', function () {
|
||||
navigator.clipboard.writeText(text).then(function () {
|
||||
btn.innerText = 'Copied!';
|
||||
setTimeout(function () { btn.innerText = 'Copy'; }, 2000);
|
||||
}, function () {
|
||||
btn.innerText = 'Failed';
|
||||
setTimeout(function () { btn.innerText = 'Copy'; }, 2000);
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue