|
214 | 214 | font-size: 1.1rem; |
215 | 215 | } |
216 | 216 |
|
| 217 | +/* Copy button styles for code blocks */ |
| 218 | +.tip-content pre { |
| 219 | + position: relative !important; |
| 220 | +} |
| 221 | +
|
| 222 | +.tip-content .copy-button { |
| 223 | + position: absolute !important; |
| 224 | + right: 0.5rem !important; |
| 225 | + top: 0.5rem !important; |
| 226 | + padding: 0.25rem 0.5rem !important; |
| 227 | + font-size: 0.875rem !important; |
| 228 | + line-height: 1.5 !important; |
| 229 | + color: #6c757d !important; |
| 230 | + background-color: transparent !important; |
| 231 | + border: 1px solid #6c757d !important; |
| 232 | + border-radius: 0.25rem !important; |
| 233 | + opacity: 0; |
| 234 | + transition: opacity 0.2s ease-in-out !important; |
| 235 | + cursor: pointer !important; |
| 236 | +} |
| 237 | +
|
| 238 | +.tip-content pre:hover .copy-button { |
| 239 | + opacity: 1; |
| 240 | +} |
| 241 | +
|
| 242 | +.tip-content .copy-button:hover { |
| 243 | + color: #fff !important; |
| 244 | + background-color: #6c757d !important; |
| 245 | +} |
| 246 | +
|
| 247 | +.tip-content .copy-button.success { |
| 248 | + color: #fff !important; |
| 249 | + background-color: #198754 !important; |
| 250 | + border-color: #198754 !important; |
| 251 | +} |
| 252 | +
|
217 | 253 | .tip-content h1, .tip-content h2, .tip-content h3, |
218 | 254 | .tip-content h4, .tip-content h5, .tip-content h6 { |
219 | 255 | margin-top: 2rem; |
@@ -334,10 +370,30 @@ document.addEventListener('DOMContentLoaded', function() { |
334 | 370 | |
335 | 371 | // Re-highlight everything |
336 | 372 | Prism.highlightAll(); |
| 373 | +
|
| 374 | + // Handle copy button success states |
| 375 | + document.querySelectorAll('.copy-button').forEach(function(button) { |
| 376 | + button.addEventListener('click', async function() { |
| 377 | + const pre = this.closest('pre'); |
| 378 | + const code = pre.querySelector('code')?.textContent || pre.textContent; |
| 379 | + |
| 380 | + try { |
| 381 | + await navigator.clipboard.writeText(code.trim()); |
| 382 | + const originalText = button.innerHTML; |
| 383 | + button.innerHTML = '<i class="bi bi-check"></i>'; |
| 384 | + button.classList.add('success'); |
| 385 | + |
| 386 | + setTimeout(() => { |
| 387 | + button.innerHTML = originalText; |
| 388 | + button.classList.remove('success'); |
| 389 | + }, 2000); |
| 390 | + } catch (err) { |
| 391 | + console.error('Failed to copy text: ', err); |
| 392 | + } |
| 393 | + }); |
| 394 | + }); |
337 | 395 | } |
338 | 396 | }, 100); |
339 | | - |
340 | | - // Note: Copy-to-clipboard functionality is handled by code-clipboard.js |
341 | 397 | }); |
342 | 398 |
|
343 | 399 | document.addEventListener('DOMContentLoaded', function() { |
|
0 commit comments