Skip to content

Commit

Permalink
feat: add autohide param for copy button
Browse files Browse the repository at this point in the history
  • Loading branch information
reuixiy committed Mar 20, 2020
1 parent f873fcc commit bdb6077
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 18 deletions.
10 changes: 10 additions & 0 deletions assets/js/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ function addCopyButtons(clipboard) {
});

containerEl.appendChild(button);

{{ if .Site.Params.enableCopyAutoHide }}
containerEl.parentNode.addEventListener('mouseover', () => {
button.style = 'visibility: visible; opacity: 1';
});

containerEl.parentNode.addEventListener('mouseout', () => {
button.style = 'visibility: hidden; opacity: 0';
});
{{ end }}
});
}

Expand Down
16 changes: 0 additions & 16 deletions assets/scss/components/_highlight.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,3 @@ span.lnt {
overflow: auto;
}
}

@if (enableCopy) {
.copy-button {
position: absolute;
top: 0;
right: 0;
border: 0;
color: var(--color-bg);
background-color: alpha(var(--color-contrast-medium), 0.5);
transition: background-color $duration;
cursor: pointer;
&:hover {
background-color: alpha(var(--color-primary), 0.5);
}
}
}
23 changes: 23 additions & 0 deletions assets/scss/layout/_single.scss
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,29 @@ pre {
}
}

@if ($enableCopy) {
.copy-button {
position: absolute;
top: 0;
right: 0;
border: 0;
color: var(--color-bg);
background-color: alpha(var(--color-contrast-medium), 0.5);
transition: all $duration;
cursor: pointer;
&:hover {
background-color: alpha(var(--color-primary), 0.5);
}
}

@if ($enableCopyAutoHide) {
.copy-button {
visibility: hidden;
opacity: 0;
}
}
}

.katex-display, mjx-container[jax="CHTML"][display="true"] {
overflow: auto hidden;
text-indent: 0;
Expand Down
6 changes: 6 additions & 0 deletions assets/scss/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@
$enableCopy: false;
{{ end }}

{{ if .Site.Params.enableCopyAutoHide }}
$enableCopyAutoHide: true;
{{ else }}
$enableCopyAutoHide: false;
{{ end }}


// Utilities

Expand Down
1 change: 1 addition & 0 deletions config-examples/en/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,7 @@ uglyURLs = false
# Unit: em

enableCopy = true
enableCopyAutoHide = true


######################################
Expand Down
2 changes: 2 additions & 0 deletions config-examples/zh-cn/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,8 @@ uglyURLs = false

# 是否开启复制
enableCopy = true
# 是否开启自动隐藏
enableCopyAutoHide = true


######################################
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"Target":"css/meme.min.8ebc75cc2e0d5e4beb6ce2cd77cc927ddff5609c3822cb96860098df7115a001.css","MediaType":"text/css","Data":{"Integrity":"sha256-jrx1zC4NXkvrbOLNd8ySfd/1YJw4IsuWhgCY33EVoAE="}}
{"Target":"css/meme.min.eede794627e4ed8002b5b86cd4c81f6b30e8f0d21321eb3eaf7e65a251666c6c.css","MediaType":"text/css","Data":{"Integrity":"sha256-7t55Rifk7YACtbhs1MgfazDo8NITIes+r35lolFmbGw="}}

0 comments on commit bdb6077

Please sign in to comment.