Skip to content

Commit 390d4d1

Browse files
committed
change text of copy button when text is copied
1 parent 568d2cf commit 390d4d1

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

layouts/partials/footer.html

+9
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,17 @@
106106
copybutton.classList.add('copy-code');
107107
copybutton.innerHTML = 'copy';
108108

109+
function copyingDone() {
110+
copybutton.innerText = 'copied!';
111+
setTimeout(() => {
112+
copybutton.innerText = 'copy';
113+
}, 2000);
114+
}
115+
109116
copybutton.addEventListener('click', (cb) => {
110117
if ('clipboard' in navigator) {
111118
navigator.clipboard.writeText(codeblock.textContent);
119+
copyingDone();
112120
return;
113121
}
114122

@@ -119,6 +127,7 @@
119127
selection.addRange(range);
120128
try {
121129
document.execCommand('copy');
130+
copyingDone();
122131
} catch (e) {};
123132
selection.removeRange(range);
124133
});

0 commit comments

Comments
 (0)