From c56487aac34813ff3bb065486a820b935e16961c Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Thu, 14 Nov 2019 14:39:45 +0800 Subject: [PATCH 1/5] Adjust copy-button style --- languages/en.yml | 3 --- layout/_partials/head/head.swig | 5 ----- source/js/utils.js | 9 +++------ 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/languages/en.yml b/languages/en.yml index 12b126af00..0fd1a55373 100644 --- a/languages/en.yml +++ b/languages/en.yml @@ -32,9 +32,6 @@ post: sticky: Sticky views: Views related_posts: Related Posts - copy_button: Copy - copy_success: Copied - copy_failure: Copy failed copyright: author: Post author link: Post link diff --git a/layout/_partials/head/head.swig b/layout/_partials/head/head.swig index 4e31879f75..6f10289253 100644 --- a/layout/_partials/head/head.swig +++ b/layout/_partials/head/head.swig @@ -88,11 +88,6 @@ localsearch: {{ theme.local_search | json }}, path: '{{ config.search.path }}', motion: {{ theme.motion | json }}, - translation: { - copy_button: '{{ __("post.copy_button") }}', - copy_success: '{{ __("post.copy_success") }}', - copy_failure: '{{ __("post.copy_failure") }}' - }, sidebarPadding: 40 }; diff --git a/source/js/utils.js b/source/js/utils.js index a249585386..f82f403ee0 100644 --- a/source/js/utils.js +++ b/source/js/utils.js @@ -61,17 +61,14 @@ NexT.utils = { registerCopyCode: function() { document.querySelectorAll('figure.highlight').forEach(element => { const initButton = button => { - if (CONFIG.copycode.style === 'mac') { - button.innerHTML = ''; - } else { - button.innerText = CONFIG.translation.copy_button; - } + button.querySelector('i').className = 'fa fa-clipboard'; }; const box = document.createElement('div'); box.classList.add('highlight-wrap'); element.wrap(box); element.parentNode.insertAdjacentHTML('beforeend', '
'); var button = element.parentNode.querySelector('.copy-btn'); + button.innerHTML = ''; button.addEventListener('click', event => { var target = event.currentTarget; var code = [...target.parentNode.querySelectorAll('.code .line')].map(line => { @@ -92,7 +89,7 @@ NexT.utils = { ta.readOnly = false; var result = document.execCommand('copy'); if (CONFIG.copycode.show_result) { - target.innerText = result ? CONFIG.translation.copy_success : CONFIG.translation.copy_failure; + target.querySelector('i').className = result ? 'fa fa-check' : 'fa fa-times'; } ta.blur(); // For iOS target.blur(); From bc343f34f33ad6fdf39fa8ee0b4de820718ff500 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Thu, 14 Nov 2019 15:42:13 +0800 Subject: [PATCH 2/5] Update --- source/js/utils.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/source/js/utils.js b/source/js/utils.js index f82f403ee0..ae89f7843a 100644 --- a/source/js/utils.js +++ b/source/js/utils.js @@ -60,15 +60,12 @@ NexT.utils = { */ registerCopyCode: function() { document.querySelectorAll('figure.highlight').forEach(element => { - const initButton = button => { - button.querySelector('i').className = 'fa fa-clipboard'; - }; const box = document.createElement('div'); box.classList.add('highlight-wrap'); element.wrap(box); element.parentNode.insertAdjacentHTML('beforeend', '
'); var button = element.parentNode.querySelector('.copy-btn'); - button.innerHTML = ''; + button.innerHTML = ''; button.addEventListener('click', event => { var target = event.currentTarget; var code = [...target.parentNode.querySelectorAll('.code .line')].map(line => { @@ -101,10 +98,9 @@ NexT.utils = { }); button.addEventListener('mouseleave', event => { setTimeout(() => { - initButton(event.target); + event.target.querySelector('i').className = 'fa fa-clipboard'; }, 300); }); - initButton(button); }); }, From 64d7a088e8a0f36a9158cb0e5a9249e16b33695b Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Thu, 14 Nov 2019 15:56:27 +0800 Subject: [PATCH 3/5] Update --- source/js/utils.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/source/js/utils.js b/source/js/utils.js index ae89f7843a..b4b90e7a77 100644 --- a/source/js/utils.js +++ b/source/js/utils.js @@ -61,19 +61,17 @@ NexT.utils = { registerCopyCode: function() { document.querySelectorAll('figure.highlight').forEach(element => { const box = document.createElement('div'); - box.classList.add('highlight-wrap'); element.wrap(box); - element.parentNode.insertAdjacentHTML('beforeend', '
'); + box.classList.add('highlight-wrap'); + box.insertAdjacentHTML('beforeend', '
'); var button = element.parentNode.querySelector('.copy-btn'); - button.innerHTML = ''; button.addEventListener('click', event => { var target = event.currentTarget; var code = [...target.parentNode.querySelectorAll('.code .line')].map(line => { return line.innerText; }).join('\n'); var ta = document.createElement('textarea'); - var yPosition = window.scrollY; - ta.style.top = yPosition + 'px'; // Prevent page scrolling + ta.style.top = window.scrollY + 'px'; // Prevent page scrolling ta.style.position = 'absolute'; ta.style.opacity = '0'; ta.readOnly = true; From 8d1d7576177bfd6caba6513e2658ab69bbf08e76 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Fri, 15 Nov 2019 18:03:45 +0800 Subject: [PATCH 4/5] Rename --- source/css/_common/scaffolding/highlight/copy-code.styl | 6 +++--- source/js/utils.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/css/_common/scaffolding/highlight/copy-code.styl b/source/css/_common/scaffolding/highlight/copy-code.styl index a2c9c32a90..1fd248aba9 100644 --- a/source/css/_common/scaffolding/highlight/copy-code.styl +++ b/source/css/_common/scaffolding/highlight/copy-code.styl @@ -1,8 +1,8 @@ -.highlight-wrap { +.highlight-container { position: relative; } -.highlight-wrap:hover .copy-btn, .highlight-wrap .copy-btn:focus { +.highlight-container:hover .copy-btn, .highlight-container .copy-btn:focus { opacity: 1; } @@ -44,7 +44,7 @@ } if (hexo-config('codeblock.copy_button.style') == 'mac') { - .highlight-wrap { + .highlight-container { background: #21252b; border-radius: 5px; box-shadow: 0 10px 30px 0 rgba(0, 0, 0, .4); diff --git a/source/js/utils.js b/source/js/utils.js index b4b90e7a77..538e9a96ba 100644 --- a/source/js/utils.js +++ b/source/js/utils.js @@ -62,7 +62,7 @@ NexT.utils = { document.querySelectorAll('figure.highlight').forEach(element => { const box = document.createElement('div'); element.wrap(box); - box.classList.add('highlight-wrap'); + box.classList.add('highlight-container'); box.insertAdjacentHTML('beforeend', '
'); var button = element.parentNode.querySelector('.copy-btn'); button.addEventListener('click', event => { From b7b20d24834bd802e47e934b750ffe5d21278763 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Fri, 15 Nov 2019 18:32:35 +0800 Subject: [PATCH 5/5] Update --- .../css/_common/scaffolding/highlight/highlight.styl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/source/css/_common/scaffolding/highlight/highlight.styl b/source/css/_common/scaffolding/highlight/highlight.styl index fcc9e18165..ef1cb4713a 100644 --- a/source/css/_common/scaffolding/highlight/highlight.styl +++ b/source/css/_common/scaffolding/highlight/highlight.styl @@ -50,7 +50,7 @@ pre { pre { border: 0; margin: 0; - padding: 10px 0; + padding: 0; } table { @@ -59,6 +59,15 @@ pre { width: auto; } + tr { + &:first-child pre { + padding-top: 10px; + } + &:last-child pre { + padding-bottom: 10px; + } + } + td { border: 0; padding: 0;