2021-02-27 21:21:26 +00:00
|
|
|
const Clipboard = (): void => {
|
2021-04-02 17:20:02 +00:00
|
|
|
const buttons: NodeListOf<HTMLButtonElement> | null = document.querySelectorAll(
|
|
|
|
"button[data-type='clipboard-copy']"
|
|
|
|
);
|
2021-02-27 21:21:26 +00:00
|
|
|
|
|
|
|
if (buttons) {
|
|
|
|
for (let i = 0; i < buttons.length; i++) {
|
|
|
|
const button: HTMLButtonElement = buttons[i];
|
|
|
|
const textArea: HTMLTextAreaElement | null = document.querySelector(
|
|
|
|
`textarea[id="${button.dataset.clipboardTarget}"]`
|
|
|
|
);
|
|
|
|
if (textArea) {
|
|
|
|
button.addEventListener("click", () => {
|
|
|
|
textArea.select();
|
|
|
|
textArea.setSelectionRange(0, textArea.value.length);
|
|
|
|
document.execCommand("copy");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Clipboard;
|