|
1 | 1 | // API page clipboard functions |
2 | 2 |
|
3 | | -function copyToClipboard(text, targetElement) { |
4 | | - if (navigator.clipboard && navigator.clipboard.writeText) { |
5 | | - // Modern Clipboard API |
6 | | - navigator.clipboard.writeText(text).then(function() { |
7 | | - targetElement.addClass('flash-copy') |
8 | | - .delay('1000').queue(function() { |
9 | | - targetElement.removeClass('flash-copy').dequeue(); |
10 | | - }); |
11 | | - }).catch(function(err) { |
12 | | - console.error('Failed to copy: ', err); |
13 | | - alert('Failed to copy to clipboard'); |
14 | | - }); |
15 | | - } else { |
16 | | - // Fallback for browsers that don't support clipboard API |
17 | | - var tempInput = document.createElement('input'); |
18 | | - tempInput.value = text; |
19 | | - document.body.appendChild(tempInput); |
20 | | - tempInput.select(); |
21 | | - document.execCommand('copy'); |
22 | | - document.body.removeChild(tempInput); |
23 | | - |
24 | | - targetElement.addClass('flash-copy') |
25 | | - .delay('1000').queue(function() { |
26 | | - targetElement.removeClass('flash-copy').dequeue(); |
27 | | - }); |
28 | | - } |
29 | | -} |
30 | | - |
31 | 3 | function copyApiKey(apiKey) { |
32 | | - var apiKeyField = $('#'+apiKey); |
33 | | - copyToClipboard(apiKey, apiKeyField); |
| 4 | + copyToClipboard(apiKey); |
| 5 | + $('#'+apiKey).addClass('flash-copy').delay('1000').queue(function() { |
| 6 | + $(this).removeClass('flash-copy').dequeue(); |
| 7 | + }); |
34 | 8 | } |
35 | 9 |
|
36 | 10 | function copyApiUrl(urlText) { |
37 | | - var apiUrlField = $('#apiUrl'); |
38 | | - copyToClipboard(urlText, apiUrlField); |
| 11 | + copyToClipboard(urlText); |
| 12 | + $('#apiUrl').addClass('flash-copy').delay('1000').queue(function() { |
| 13 | + $(this).removeClass('flash-copy').dequeue(); |
| 14 | + }); |
39 | 15 | } |
40 | 16 |
|
41 | 17 | $(function () { |
|
0 commit comments