Optimize the position of copy-button (#508)

This commit is contained in:
Mimi 2022-05-22 01:57:50 +08:00 committed by GitHub
parent d932e308d4
commit c7c13fdd6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 4 deletions

View File

@ -18,7 +18,7 @@ hexo.extend.helper.register('next_config', function() {
version : this.next_version, version : this.next_version,
exturl : theme.exturl, exturl : theme.exturl,
sidebar : theme.sidebar, sidebar : theme.sidebar,
copycode : theme.codeblock.copy_button.enable, copycode : theme.codeblock.copy_button,
bookmark : theme.bookmark, bookmark : theme.bookmark,
mediumzoom: theme.mediumzoom, mediumzoom: theme.mediumzoom,
lazyload : theme.lazyload, lazyload : theme.lazyload,

View File

@ -2,6 +2,12 @@
opacity: 1; opacity: 1;
} }
figure.highlight {
.table-container {
position: relative;
}
}
.copy-btn { .copy-btn {
color: $black-dim; color: $black-dim;
cursor: pointer; cursor: pointer;

View File

@ -45,13 +45,13 @@ NexT.boot.refresh = function() {
CONFIG.pangu && window.pangu.spacingPage(); CONFIG.pangu && window.pangu.spacingPage();
CONFIG.exturl && NexT.utils.registerExtURL(); CONFIG.exturl && NexT.utils.registerExtURL();
NexT.utils.wrapTableWithBox();
NexT.utils.registerCopyCode(); NexT.utils.registerCopyCode();
NexT.utils.registerTabsTag(); NexT.utils.registerTabsTag();
NexT.utils.registerActiveMenuItem(); NexT.utils.registerActiveMenuItem();
NexT.utils.registerLangSelect(); NexT.utils.registerLangSelect();
NexT.utils.registerSidebarTOC(); NexT.utils.registerSidebarTOC();
NexT.utils.registerPostReward(); NexT.utils.registerPostReward();
NexT.utils.wrapTableWithBox();
NexT.utils.registerVideoIframe(); NexT.utils.registerVideoIframe();
}; };

View File

@ -51,8 +51,10 @@ NexT.utils = {
span.classList.replace(name, `hljs-${name}`); span.classList.replace(name, `hljs-${name}`);
}); });
}); });
if (!CONFIG.copycode) return; if (!CONFIG.copycode.enable) return;
element.insertAdjacentHTML('beforeend', '<div class="copy-btn"><i class="fa fa-copy fa-fw"></i></div>'); let target = element;
if (CONFIG.copycode.style !== 'mac') target = element.querySelector('.table-container') || element;
target.insertAdjacentHTML('beforeend', '<div class="copy-btn"><i class="fa fa-copy fa-fw"></i></div>');
const button = element.querySelector('.copy-btn'); const button = element.querySelector('.copy-btn');
button.addEventListener('click', () => { button.addEventListener('click', () => {
const lines = element.querySelector('.code') || element.querySelector('code'); const lines = element.querySelector('.code') || element.querySelector('code');