|
21 | 21 | } else {
|
22 | 22 | return
|
23 | 23 | }
|
24 |
| - ;(copy = document.createElement('button')).className = 'copy-button' |
25 |
| - copy.setAttribute('title', 'Copy to clipboard') |
26 |
| - var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg') |
27 |
| - svg.setAttribute('aria-hidden', 'true') |
28 |
| - svg.setAttribute('class', 'copy-icon') |
29 |
| - svg.setAttribute('viewBox', '0 0 16 16') |
30 |
| - var use = document.createElementNS('http://www.w3.org/2000/svg', 'use') |
31 |
| - use.setAttribute('href', window.uiRootPath + '/img/octicons.svg#icon-clippy-16') |
32 |
| - svg.appendChild(use) |
33 |
| - copy.appendChild(svg) |
34 |
| - ;(toast = document.createElement('span')).className = 'copy-toast' |
35 |
| - toast.appendChild(document.createTextNode('Copied!')) |
36 |
| - copy.appendChild(toast) |
37 | 24 | ;(toolbox = document.createElement('div')).className = 'code-toolbox'
|
38 | 25 | if (lang) toolbox.appendChild(lang)
|
39 |
| - toolbox.appendChild(copy) |
| 26 | + if (window.navigator.clipboard) { |
| 27 | + ;(copy = document.createElement('button')).className = 'copy-button' |
| 28 | + copy.setAttribute('title', 'Copy to clipboard') |
| 29 | + var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg') |
| 30 | + svg.setAttribute('aria-hidden', 'true') |
| 31 | + svg.setAttribute('class', 'copy-icon') |
| 32 | + svg.setAttribute('viewBox', '0 0 16 16') |
| 33 | + var use = document.createElementNS('http://www.w3.org/2000/svg', 'use') |
| 34 | + use.setAttribute('href', window.uiRootPath + '/img/octicons.svg#icon-clippy-16') |
| 35 | + svg.appendChild(use) |
| 36 | + copy.appendChild(svg) |
| 37 | + ;(toast = document.createElement('span')).className = 'copy-toast' |
| 38 | + toast.appendChild(document.createTextNode('Copied!')) |
| 39 | + copy.appendChild(toast) |
| 40 | + toolbox.appendChild(copy) |
| 41 | + } |
40 | 42 | pre.appendChild(toolbox)
|
41 |
| - copy.addEventListener('click', writeToClipboard.bind(copy, code)) |
| 43 | + if (copy) copy.addEventListener('click', writeToClipboard.bind(copy, code)) |
42 | 44 | })
|
43 | 45 |
|
44 | 46 | function extractCommands (text) {
|
|
0 commit comments