Skip to content

Commit a2d8cc6

Browse files
committed
reference copy icon in source toolbox using img tag instead of svg+use (unless configured otherwise)
1 parent 0301fd3 commit a2d8cc6

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

src/css/doc.css

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,13 +739,20 @@ h1.page + aside.toc.embedded {
739739
height: 1em;
740740
}
741741

742-
.doc .source-toolbox .copy-button svg {
742+
.doc .source-toolbox .copy-icon {
743743
flex: none;
744-
fill: currentColor;
745744
width: inherit;
746745
height: inherit;
747746
}
748747

748+
.doc .source-toolbox img.copy-icon {
749+
filter: invert(50.2%);
750+
}
751+
752+
.doc .source-toolbox svg.copy-icon {
753+
fill: currentColor;
754+
}
755+
749756
.doc .source-toolbox .copy-toast {
750757
flex: none;
751758
position: relative;

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
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+
var config = (document.getElementById('site-script') || { dataset: {} }).dataset
78

89
;[].slice.call(document.querySelectorAll('.doc pre.highlight, .doc .literalblock pre')).forEach(function (pre) {
910
var code, language, lang, copy, toast, toolbox
@@ -30,13 +31,20 @@
3031
if (window.navigator.clipboard) {
3132
;(copy = document.createElement('button')).className = 'copy-button'
3233
copy.setAttribute('title', 'Copy to clipboard')
33-
var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg')
34-
svg.setAttribute('aria-hidden', 'true')
35-
svg.setAttribute('class', 'copy-icon')
36-
var use = document.createElementNS('http://www.w3.org/2000/svg', 'use')
37-
use.setAttribute('href', window.uiRootPath + '/img/octicons-16.svg#icon-clippy')
38-
svg.appendChild(use)
39-
copy.appendChild(svg)
34+
if (config.svgAs === 'svg') {
35+
var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg')
36+
svg.setAttribute('class', 'copy-icon')
37+
var use = document.createElementNS('http://www.w3.org/2000/svg', 'use')
38+
use.setAttribute('href', window.uiRootPath + '/img/octicons-16.svg#icon-clippy')
39+
svg.appendChild(use)
40+
copy.appendChild(svg)
41+
} else { // img
42+
var img = new Image()
43+
img.alt = 'copy icon'
44+
img.className = 'copy-icon'
45+
img.src = window.uiRootPath + '/img/octicons-16.svg#view-clippy'
46+
copy.appendChild(img)
47+
}
4048
;(toast = document.createElement('span')).className = 'copy-toast'
4149
toast.appendChild(document.createTextNode('Copied!'))
4250
copy.appendChild(toast)

0 commit comments

Comments
 (0)