fixed quote scroll to start of match

This commit is contained in:
plebbitor
2023-04-19 10:45:42 +02:00
parent 9783a9b86f
commit 3c5b725937
3 changed files with 25 additions and 11 deletions
+21 -4
View File
@@ -1,6 +1,7 @@
function handleQuoteClick(reply, parentCid, threadCid) {
const cid = parentCid ? parentCid : reply.shortCid;
const isMobile = window.innerWidth <= 480;
const postNumberSelector = isMobile ? '.post-number-mobile' : '.post-number-desktop';
if (threadCid && cid === threadCid) {
const highlightedElements = document.querySelectorAll('.highlighted');
@@ -9,11 +10,24 @@ function handleQuoteClick(reply, parentCid, threadCid) {
el.classList.remove('highlighted');
});
const opElementSelector = isMobile ? '.op-mobile' : '.op-desktop';
const opElement = [...document.querySelectorAll(opElementSelector)]
.find(el => {
const postNumberElement = el.querySelector(postNumberSelector);
return postNumberElement && postNumberElement.innerHTML.includes(threadCid);
});
if (opElement) {
opElement.scrollIntoView({ behavior: "auto", block: "start" });
} else {
console.log('Could not find OP element');
}
return;
}
const targetElementSelector = isMobile ? '.post-reply-mobile' : '.post-reply-desktop';
const postNumberSelector = isMobile ? '.post-number-mobile' : '.post-number-desktop';
const targetElementSelector = isMobile ? '.post-reply-mobile, .op-mobile' : '.post-reply-desktop, .op-desktop';
const targetElement = [...document.querySelectorAll(targetElementSelector)]
.find(el => {
@@ -28,8 +42,11 @@ function handleQuoteClick(reply, parentCid, threadCid) {
el.classList.remove('highlighted');
});
targetElement.scrollIntoView({ behavior: "auto", block: "center" });
targetElement.classList.add('highlighted');
targetElement.scrollIntoView({ behavior: "auto", block: "start" });
if (!targetElement.classList.contains('op-mobile') && !targetElement.classList.contains('op-desktop')) {
targetElement.classList.add('highlighted');
}
} else {
console.log('Could not find target element');