mirror of
https://github.com/next-theme/hexo-theme-next.git
synced 2026-01-18 18:33:42 +00:00
Fix empty innerText
This commit is contained in:
parent
783b6ffe8c
commit
ddecbe3628
2
source/js/third-party/tags/mermaid.js
vendored
2
source/js/third-party/tags/mermaid.js
vendored
@ -14,7 +14,7 @@ document.addEventListener('page:loaded', () => {
|
||||
newElement.className = 'mermaid';
|
||||
box.appendChild(newElement);
|
||||
if (CONFIG.copycode.enable) {
|
||||
NexT.utils.registerCopyButton(box, box, element.innerText);
|
||||
NexT.utils.registerCopyButton(box, box, element.textContent);
|
||||
}
|
||||
const parent = element.parentNode;
|
||||
parent.parentNode.replaceChild(box, parent);
|
||||
|
||||
@ -39,11 +39,15 @@ NexT.utils = {
|
||||
});
|
||||
},
|
||||
|
||||
registerCopyButton(target, element, code) {
|
||||
registerCopyButton(target, element, code = '') {
|
||||
// One-click copy code support.
|
||||
target.insertAdjacentHTML('beforeend', '<div class="copy-btn"><i class="fa fa-copy fa-fw"></i></div>');
|
||||
const button = target.querySelector('.copy-btn');
|
||||
button.addEventListener('click', () => {
|
||||
if (!code) {
|
||||
const lines = element.querySelector('.code') || element.querySelector('code');
|
||||
code = lines.innerText;
|
||||
}
|
||||
if (navigator.clipboard) {
|
||||
// https://caniuse.com/mdn-api_clipboard_writetext
|
||||
navigator.clipboard.writeText(code).then(() => {
|
||||
@ -131,8 +135,7 @@ NexT.utils = {
|
||||
});
|
||||
}
|
||||
if (!inited && CONFIG.copycode.enable) {
|
||||
const lines = element.querySelector('.code') || element.querySelector('code');
|
||||
this.registerCopyButton(target, element, lines.innerText);
|
||||
this.registerCopyButton(target, element);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user