Skip to content

Commit 73ee65b

Browse files
committed
fix: fix copy button issue.
1 parent 29b890b commit 73ee65b

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

template/details.ejs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
<%- include('partial/header'); %>
22
<%- include('widget/search',{type: "list"}); %>
3+
<script src="https://unpkg.com/@uiw/copy-to-clipboard/dist/copy-to-clipboard.umd.js"></script>
4+
<script>
5+
function copied(target, str) {
6+
target.classList.add('active');
7+
copyTextToClipboard(target.dataset.code, function() {
8+
setTimeout(() => {
9+
target.classList.remove('active');
10+
}, 2000);
11+
});
12+
}
13+
</script>
14+
315
<div class="markdown-body">
416
<% if(md_path){ %>
517
<span class="edit_btn">

template/styl/mixins/markdown.styl

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,50 @@ mq-mobile = "screen and (max-width: 479px)"
5555
}
5656
}
5757

58+
59+
.markdown-body pre[class*="language-"] {
60+
position: relative;
61+
}
62+
.markdown-body pre[class*="language-"] .copied {
63+
visibility: hidden;
64+
display: flex;
65+
position: absolute;
66+
cursor: pointer;
67+
color: #a5afbb;
68+
top: 6px;
69+
right: 6px;
70+
border-radius: 5px;
71+
background: #e3e3e3;
72+
padding: 6px;
73+
font-size: 12px;
74+
transition: all .3s;
75+
}
76+
.markdown-body pre[class*="language-"]:hover .copied {
77+
visibility: visible;
78+
}
79+
.markdown-body pre[class*="language-"]:hover .copied:hover {
80+
background: #4caf50;
81+
color: #fff;
82+
}
83+
.markdown-body pre[class*="language-"]:hover .copied:active,
84+
.markdown-body pre[class*="language-"] .active {
85+
background: #2e9b33;
86+
color: #fff;
87+
}
88+
89+
.markdown-body pre[class*="language-"] .copied .octicon-copy {
90+
display: block;
91+
}
92+
.markdown-body pre[class*="language-"] .copied .octicon-check {
93+
display: none;
94+
}
95+
.markdown-body pre[class*="language-"] .active .octicon-copy {
96+
display: none;
97+
}
98+
.markdown-body pre[class*="language-"] .active .octicon-check {
99+
display: block;
100+
}
101+
58102
.markdown-body .octicon {
59103
display: inline-block;
60104
fill: currentColor;

0 commit comments

Comments
 (0)