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,
exturl : theme.exturl,
sidebar : theme.sidebar,
copycode : theme.codeblock.copy_button.enable,
copycode : theme.codeblock.copy_button,
bookmark : theme.bookmark,
mediumzoom: theme.mediumzoom,
lazyload : theme.lazyload,

View File

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

View File

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

View File

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