| 1 | // JavaScript for copy functionality |
| 2 | document.addEventListener('click', function(e) { |
| 3 | if (e.target.matches('.copy-button')) { |
| 4 | const button = e.target; |
| 5 | const targetId = button.getAttribute('data-target'); |
| 6 | const codeText = document.getElementById(targetId).textContent; |
| 7 | |
| 8 | navigator.clipboard.writeText(codeText).then(() => { |
| 9 | button.textContent = "Copied!"; |
| 10 | button.disabled = true; |
| 11 | |
| 12 | setTimeout(() => { |
| 13 | button.textContent = "Copy"; |
| 14 | button.disabled = false; |
| 15 | }, 3000); // Revert after 3 seconds |
| 16 | }); |
| 17 | } |
| 18 | }); |