Skip to content

Commit 9efae05

Browse files
authored
Copy to clupboard (parse-community#790)
1 parent 055a1fe commit 9efae05

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

_layouts/default.html

+33
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,38 @@
1919
gtag('js', new Date());
2020

2121
gtag('config', 'UA-102564547-3');
22+
23+
window.onload = function () {
24+
function copyToClipboard() {
25+
const textId = this.id.replace('btn','code')
26+
const copyText = document.getElementById(textId);
27+
const text = copyText.textContent || copyText.innerText;
28+
29+
const input = document.createElement('textarea');
30+
input.innerHTML = text;
31+
document.body.appendChild(input);
32+
input.select();
33+
input.setSelectionRange(0, 99999);
34+
document.execCommand('copy');
35+
document.body.removeChild(input);
36+
37+
this.innerHTML = '✔️';
38+
setTimeout(() => {
39+
this.innerHTML = '📋';
40+
},2000)
41+
}
42+
let codes = document.querySelectorAll('.highlight > pre > code');
43+
let count = 0;
44+
codes.forEach((code) => {
45+
code.setAttribute("id", `code-${count}`);
46+
const btn = document.createElement('button');
47+
btn.innerHTML = "📋";
48+
btn.className = "btn-copy";
49+
btn.setAttribute("id", `btn-${count}`);
50+
btn.addEventListener("click",copyToClipboard);
51+
code.before(btn);
52+
count++;
53+
});
54+
}
2255
</script>
2356
</html>

css/lib/docs/views/_detail.scss

+10
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,16 @@
152152
}
153153
}
154154

155+
.highlight {
156+
position: relative;
157+
}
158+
.btn-copy {
159+
position: absolute;
160+
right: 10px;
161+
background: none;
162+
border: none;
163+
}
164+
155165
.toggles{
156166
text-align: right;
157167
padding-top: 15px;

0 commit comments

Comments
 (0)