fix: closes #11806, fix code blocks

isekai-main
Barış Soner Uşaklı 2 years ago
parent a5cc5372cb
commit 165b0f8565

@ -96,12 +96,12 @@
"nodebb-plugin-dbsearch": "6.1.0", "nodebb-plugin-dbsearch": "6.1.0",
"nodebb-plugin-emoji": "5.1.3", "nodebb-plugin-emoji": "5.1.3",
"nodebb-plugin-emoji-android": "4.0.0", "nodebb-plugin-emoji-android": "4.0.0",
"nodebb-plugin-markdown": "12.1.5", "nodebb-plugin-markdown": "12.1.6",
"nodebb-plugin-mentions": "4.3.0", "nodebb-plugin-mentions": "4.3.0",
"nodebb-plugin-ntfy": "1.0.16", "nodebb-plugin-ntfy": "1.0.16",
"nodebb-plugin-spam-be-gone": "2.1.1", "nodebb-plugin-spam-be-gone": "2.1.1",
"nodebb-rewards-essentials": "0.2.3", "nodebb-rewards-essentials": "0.2.3",
"nodebb-theme-harmony": "1.1.4", "nodebb-theme-harmony": "1.1.5",
"nodebb-theme-lavender": "7.1.1", "nodebb-theme-lavender": "7.1.1",
"nodebb-theme-peace": "2.1.2", "nodebb-theme-peace": "2.1.2",
"nodebb-theme-persona": "13.2.4", "nodebb-theme-persona": "13.2.4",

@ -242,6 +242,15 @@ define('forum/topic', [
function scrollbarVisible(element) { function scrollbarVisible(element) {
return element.scrollHeight > element.clientHeight; return element.scrollHeight > element.clientHeight;
} }
function offsetCodeBtn(codeEl) {
if (!codeEl.length) { return; }
if (!codeEl[0].scrollHeight) {
return setTimeout(offsetCodeBtn, 100, codeEl);
}
if (scrollbarVisible(codeEl.get(0))) {
codeEl.parent().parent().find('[component="copy/code/btn"]').css({ margin: '0.5rem 1.5rem 0 0' });
}
}
let codeBlocks = $('[component="topic"] [component="post/content"] code:not([data-button-added])'); let codeBlocks = $('[component="topic"] [component="post/content"] code:not([data-button-added])');
codeBlocks = codeBlocks.filter((i, el) => $(el).text().includes('\n')); codeBlocks = codeBlocks.filter((i, el) => $(el).text().includes('\n'));
const container = $('<div class="hover-parent position-relative"></div>'); const container = $('<div class="hover-parent position-relative"></div>');
@ -250,9 +259,7 @@ define('forum/topic', [
preEls.wrap(container).parent().append(buttonDiv); preEls.wrap(container).parent().append(buttonDiv);
preEls.parent().find('[component="copy/code/btn"]').translateAttr('title', '[[topic:copy-code]]'); preEls.parent().find('[component="copy/code/btn"]').translateAttr('title', '[[topic:copy-code]]');
preEls.each((index, el) => { preEls.each((index, el) => {
if (scrollbarVisible(el)) { offsetCodeBtn($(el).find('code'));
$(el).parent().find('[component="copy/code/btn"]').css({ margin: '0.5rem 1.5rem 0 0' });
}
}); });
codeBlocks.attr('data-button-added', 1); codeBlocks.attr('data-button-added', 1);
} }

Loading…
Cancel
Save