mirror of
https://github.com/next-theme/hexo-theme-next.git
synced 2026-01-20 19:02:33 +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';
|
newElement.className = 'mermaid';
|
||||||
box.appendChild(newElement);
|
box.appendChild(newElement);
|
||||||
if (CONFIG.copycode.enable) {
|
if (CONFIG.copycode.enable) {
|
||||||
NexT.utils.registerCopyButton(box, box, element.innerText);
|
NexT.utils.registerCopyButton(box, box, element.textContent);
|
||||||
}
|
}
|
||||||
const parent = element.parentNode;
|
const parent = element.parentNode;
|
||||||
parent.parentNode.replaceChild(box, parent);
|
parent.parentNode.replaceChild(box, parent);
|
||||||
|
|||||||
@ -39,11 +39,15 @@ NexT.utils = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
registerCopyButton(target, element, code) {
|
registerCopyButton(target, element, code = '') {
|
||||||
// One-click copy code support.
|
// One-click copy code support.
|
||||||
target.insertAdjacentHTML('beforeend', '<div class="copy-btn"><i class="fa fa-copy fa-fw"></i></div>');
|
target.insertAdjacentHTML('beforeend', '<div class="copy-btn"><i class="fa fa-copy fa-fw"></i></div>');
|
||||||
const button = target.querySelector('.copy-btn');
|
const button = target.querySelector('.copy-btn');
|
||||||
button.addEventListener('click', () => {
|
button.addEventListener('click', () => {
|
||||||
|
if (!code) {
|
||||||
|
const lines = element.querySelector('.code') || element.querySelector('code');
|
||||||
|
code = lines.innerText;
|
||||||
|
}
|
||||||
if (navigator.clipboard) {
|
if (navigator.clipboard) {
|
||||||
// https://caniuse.com/mdn-api_clipboard_writetext
|
// https://caniuse.com/mdn-api_clipboard_writetext
|
||||||
navigator.clipboard.writeText(code).then(() => {
|
navigator.clipboard.writeText(code).then(() => {
|
||||||
@ -131,8 +135,7 @@ NexT.utils = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (!inited && CONFIG.copycode.enable) {
|
if (!inited && CONFIG.copycode.enable) {
|
||||||
const lines = element.querySelector('.code') || element.querySelector('code');
|
this.registerCopyButton(target, element);
|
||||||
this.registerCopyButton(target, element, lines.innerText);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user