aa
This commit is contained in:
@@ -1,12 +1,29 @@
|
||||
export function initShare() {
|
||||
document.querySelectorAll('[data-share-copy]').forEach(btn => {
|
||||
btn.addEventListener('click', () => {
|
||||
const url = btn.dataset.shareCopy
|
||||
globalThis.navigator.clipboard.writeText(url).then(() => {
|
||||
const original = btn.innerHTML
|
||||
btn.innerHTML = '<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/></svg>'
|
||||
setTimeout(() => { btn.innerHTML = original }, 1500)
|
||||
})
|
||||
})
|
||||
})
|
||||
/**
|
||||
* Handles the click event to copy text and toggle the button icon.
|
||||
* @param {PointerEvent} event
|
||||
*/
|
||||
async function handleCopyClick(event) {
|
||||
const btn = event.currentTarget;
|
||||
const url = btn.dataset.shareCopy;
|
||||
|
||||
try {
|
||||
await globalThis.navigator.clipboard.writeText(url);
|
||||
|
||||
// Swap UI state
|
||||
const original = btn.innerHTML;
|
||||
btn.innerHTML = '<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/></svg>';
|
||||
|
||||
setTimeout(() => {
|
||||
btn.innerHTML = original;
|
||||
}, 1500);
|
||||
} catch (err) {
|
||||
console.error('Failed to copy text: ', err);
|
||||
}
|
||||
}
|
||||
|
||||
export function initShare() {
|
||||
const shareButtons = document.querySelectorAll('[data-share-copy]');
|
||||
shareButtons.forEach(btn => {
|
||||
btn.addEventListener('click', handleCopyClick);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user