Skip to content

Commit aa21db6

Browse files
committed
don't add copy to clipboard button if clipboard API isn't available
1 parent a84356e commit aa21db6

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

src/css/doc.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,8 +701,8 @@
701701
padding: 0;
702702
font-size: inherit;
703703
line-height: inherit;
704-
width: 1.025em;
705-
height: 1.025em;
704+
width: 1.05em;
705+
height: 1.05em;
706706
}
707707

708708
.code-toolbox .copy-button * {

src/js/06-copy-to-clipboard.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,26 @@
2121
} else {
2222
return
2323
}
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)
3724
;(toolbox = document.createElement('div')).className = 'code-toolbox'
3825
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+
}
4042
pre.appendChild(toolbox)
41-
copy.addEventListener('click', writeToClipboard.bind(copy, code))
43+
if (copy) copy.addEventListener('click', writeToClipboard.bind(copy, code))
4244
})
4345

4446
function extractCommands (text) {

0 commit comments

Comments
 (0)