Skip to content

Commit e7a1515

Browse files
committed
don't add copy button to source toolbox if uiRootPath data attribute is not defined
1 parent abab977 commit e7a1515

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
var CMD_RX = /^\$ (\S[^\\\n]*(\\\n(?!\$ )[^\\\n]*)*)(?=\n|$)/gm
55
var LINE_CONTINUATION_RX = /( ) *\\\n *|\\\n( ?) */g
66
var TRAILING_SPACE_RX = / +$/gm
7+
78
var config = (document.getElementById('site-script') || { dataset: {} }).dataset
9+
var uiRootPath = config.uiRootPath
10+
var svgAs = config.svgAs
11+
var supportsCopy = window.navigator.clipboard && uiRootPath != null
812

913
;[].slice.call(document.querySelectorAll('.doc pre.highlight, .doc .literalblock pre')).forEach(function (pre) {
1014
var code, language, lang, copy, toast, toolbox
@@ -28,19 +32,19 @@
2832
}
2933
;(toolbox = document.createElement('div')).className = 'source-toolbox'
3034
if (lang) toolbox.appendChild(lang)
31-
if (window.navigator.clipboard) {
35+
if (supportsCopy) {
3236
;(copy = document.createElement('button')).className = 'copy-button'
3337
copy.setAttribute('title', 'Copy to clipboard')
34-
if (config.svgAs === 'svg') {
38+
if (svgAs === 'svg') {
3539
var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg')
3640
svg.setAttribute('class', 'copy-icon')
3741
var use = document.createElementNS('http://www.w3.org/2000/svg', 'use')
38-
use.setAttribute('href', config.uiRootPath + '/img/octicons-16.svg#icon-clippy')
42+
use.setAttribute('href', uiRootPath + '/img/octicons-16.svg#icon-clippy')
3943
svg.appendChild(use)
4044
copy.appendChild(svg)
4145
} else {
4246
var img = document.createElement('img')
43-
img.src = config.uiRootPath + '/img/octicons-16.svg#view-clippy'
47+
img.src = uiRootPath + '/img/octicons-16.svg#view-clippy'
4448
img.alt = 'copy icon'
4549
img.className = 'copy-icon'
4650
copy.appendChild(img)

0 commit comments

Comments
 (0)