mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2025-05-25 11:14:12 +00:00
deploy: 39e67e57ef
This commit is contained in:
parent
be7d802084
commit
2ac7c33dc9
1198 changed files with 22731 additions and 20315 deletions
js
68
js/theme.js
68
js/theme.js
|
@ -657,6 +657,7 @@ function initCodeClipboard() {
|
|||
var inTable = inPre && code.parentNode.parentNode.tagName.toLowerCase() == 'td' && code.parentNode.parentNode.classList.contains('lntd');
|
||||
// avoid copy-to-clipboard for highlight shortcode in table lineno mode
|
||||
var isFirstLineCell = inTable && code.parentNode.parentNode.parentNode.querySelector('td:first-child > pre > code') == code;
|
||||
var isBlock = inTable || inPre;
|
||||
|
||||
if (!isFirstLineCell && (inPre || text.length > 5)) {
|
||||
code.classList.add('copy-to-clipboard-code');
|
||||
|
@ -671,14 +672,34 @@ function initCodeClipboard() {
|
|||
code.parentNode.replaceChild(span, code);
|
||||
code = clone;
|
||||
}
|
||||
var button = document.createElement('button');
|
||||
button.classList.add('copy-to-clipboard-button');
|
||||
button.setAttribute('title', window.T_Copy_to_clipboard);
|
||||
button.innerHTML = '<i class="far fa-copy"></i>';
|
||||
button.addEventListener('mouseleave', function () {
|
||||
this.removeAttribute('aria-label');
|
||||
this.classList.remove('tooltipped', 'tooltipped-w', 'tooltipped-se', 'tooltipped-sw');
|
||||
});
|
||||
var button = null;
|
||||
if (isBlock || !window.relearn.disableInlineCopyToClipboard) {
|
||||
button = document.createElement('button');
|
||||
var buttonPrefix = isBlock ? 'block' : 'inline';
|
||||
button.classList.add(buttonPrefix + '-copy-to-clipboard-button');
|
||||
button.setAttribute('title', window.T_Copy_to_clipboard);
|
||||
button.innerHTML = '<i class="far fa-copy"></i>';
|
||||
button.addEventListener('mouseleave', function () {
|
||||
this.removeAttribute('aria-label');
|
||||
this.classList.remove('tooltipped', 'tooltipped-w', 'tooltipped-se', 'tooltipped-sw');
|
||||
});
|
||||
if (isBlock) {
|
||||
// we have to make sure, the button is visible while
|
||||
// Clipboard.js is doing its magic
|
||||
button.addEventListener('focus', function (ev) {
|
||||
setTimeout(function () {
|
||||
ev.target.classList.add('force-display');
|
||||
}, 0);
|
||||
});
|
||||
button.addEventListener('blur', function (ev) {
|
||||
this.removeAttribute('aria-label');
|
||||
this.classList.remove('tooltipped', 'tooltipped-w', 'tooltipped-se', 'tooltipped-sw');
|
||||
setTimeout(function () {
|
||||
ev.target.classList.remove('force-display');
|
||||
}, 0);
|
||||
});
|
||||
}
|
||||
}
|
||||
if (inTable) {
|
||||
var table = code.parentNode.parentNode.parentNode.parentNode.parentNode;
|
||||
table.dataset.code = text;
|
||||
|
@ -687,7 +708,7 @@ function initCodeClipboard() {
|
|||
var pre = code.parentNode;
|
||||
pre.dataset.code = text;
|
||||
var p = pre.parentNode;
|
||||
// indented code blocks are missing the div
|
||||
// html <pre><code> constructs and indented code blocks are missing the div
|
||||
while (p != document && (p.tagName.toLowerCase() != 'div' || !p.classList.contains('highlight'))) {
|
||||
p = p.parentNode;
|
||||
}
|
||||
|
@ -695,33 +716,30 @@ function initCodeClipboard() {
|
|||
var clone = pre.cloneNode(true);
|
||||
var div = document.createElement('div');
|
||||
div.classList.add('highlight');
|
||||
if (window.relearn.enableBlockCodeWrap) {
|
||||
div.classList.add('wrap-code');
|
||||
}
|
||||
div.appendChild(clone);
|
||||
pre.parentNode.replaceChild(div, pre);
|
||||
pre = clone;
|
||||
}
|
||||
// we have to make sure, the button is visible while
|
||||
// Clipboard.js is doing its magic
|
||||
button.addEventListener('focus', function (ev) {
|
||||
setTimeout(function () {
|
||||
ev.target.classList.add('force-display');
|
||||
}, 0);
|
||||
});
|
||||
button.addEventListener('blur', function (ev) {
|
||||
this.removeAttribute('aria-label');
|
||||
this.classList.remove('tooltipped', 'tooltipped-w', 'tooltipped-se', 'tooltipped-sw');
|
||||
setTimeout(function () {
|
||||
ev.target.classList.remove('force-display');
|
||||
}, 0);
|
||||
});
|
||||
pre.parentNode.insertBefore(button, pre.nextSibling);
|
||||
} else {
|
||||
code.classList.add('highlight');
|
||||
code.dataset.code = text;
|
||||
code.parentNode.insertBefore(button, code.nextSibling);
|
||||
if (button) {
|
||||
// #1022 fix for FF; see CSS for explanation
|
||||
if (isRtl) {
|
||||
code.parentNode.insertBefore(button, code.parentNode.firstChild);
|
||||
} else {
|
||||
code.parentNode.insertBefore(button, code.nextSibling);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var clip = new ClipboardJS('.copy-to-clipboard-button', {
|
||||
var clip = new ClipboardJS('.block-copy-to-clipboard-button, .inline-copy-to-clipboard-button', {
|
||||
text: function (trigger) {
|
||||
if (!trigger.previousElementSibling) {
|
||||
return '';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue