From 165b0f856581b0404ad1680e9f1a9e01c9677cb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Sat, 15 Jul 2023 21:19:07 -0400 Subject: [PATCH] fix: closes #11806, fix code blocks --- install/package.json | 4 ++-- public/src/client/topic.js | 13 ++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/install/package.json b/install/package.json index 534e854001..bd53f322ca 100644 --- a/install/package.json +++ b/install/package.json @@ -96,12 +96,12 @@ "nodebb-plugin-dbsearch": "6.1.0", "nodebb-plugin-emoji": "5.1.3", "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-ntfy": "1.0.16", "nodebb-plugin-spam-be-gone": "2.1.1", "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-peace": "2.1.2", "nodebb-theme-persona": "13.2.4", diff --git a/public/src/client/topic.js b/public/src/client/topic.js index 7a0b228efd..79235656dd 100644 --- a/public/src/client/topic.js +++ b/public/src/client/topic.js @@ -242,6 +242,15 @@ define('forum/topic', [ function scrollbarVisible(element) { 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])'); codeBlocks = codeBlocks.filter((i, el) => $(el).text().includes('\n')); const container = $('
'); @@ -250,9 +259,7 @@ define('forum/topic', [ preEls.wrap(container).parent().append(buttonDiv); preEls.parent().find('[component="copy/code/btn"]').translateAttr('title', '[[topic:copy-code]]'); preEls.each((index, el) => { - if (scrollbarVisible(el)) { - $(el).parent().find('[component="copy/code/btn"]').css({ margin: '0.5rem 1.5rem 0 0' }); - } + offsetCodeBtn($(el).find('code')); }); codeBlocks.attr('data-button-added', 1); }