Files
wanderer/assets/js/hooks/copyToClipboard.ts
Dmitry Popov 4136aaad76 Initial commit
2024-09-18 01:55:30 +04:00

24 lines
528 B
TypeScript

export default {
mounted() {
const hook = this;
const url = hook.el.dataset.url;
const button = hook.el;
button.addEventListener('click', function () {
// Get the URL from the data attribute
button.classList.remove('copied');
// Copy the URL to the clipboard
navigator.clipboard
.writeText(url)
.then(() => {
button.classList.add('copied');
})
.catch(err => {
console.error('Failed to copy URL:', err);
});
});
},
};