|
|
@ -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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|