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', '