added scroll and highlight to links

This commit is contained in:
plebbitor
2023-04-17 18:52:21 +02:00
parent a8e09896e9
commit 0ccf6327e1
4 changed files with 58 additions and 15 deletions
+16 -4
View File
@@ -1,9 +1,21 @@
function handleQuoteClick(reply) {
const cid = reply.shortCid;
function handleQuoteClick(reply, parentCid) {
const cid = parentCid ? parentCid : reply.shortCid;
const targetElement = [...document.querySelectorAll('.post-reply')]
.find(el => el.innerHTML.includes(cid));
.find(el => {
const postNumberElement = el.querySelector('.post-number');
return postNumberElement && postNumberElement.innerHTML.includes(cid);
});
if (targetElement) {
targetElement.scrollIntoView({ behavior: "instant" });
const highlightedElements = document.querySelectorAll('.highlighted');
highlightedElements.forEach(el => {
el.classList.remove('highlighted');
});
targetElement.scrollIntoView({ behavior: "auto", block: "center" });
targetElement.classList.add('highlighted');
} else {
console.log('Could not find target element');
}