From 7b2dd1a311ca5f6beeaf966060a301bece6cff3b Mon Sep 17 00:00:00 2001 From: ache Date: Wed, 4 May 2022 22:05:53 +0200 Subject: Fix sidenotes --- src/js/sidenotes.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/js/sidenotes.js b/src/js/sidenotes.js index eb09d56..8ab99f9 100644 --- a/src/js/sidenotes.js +++ b/src/js/sidenotes.js @@ -15,16 +15,14 @@ function getPos(element) { // Use this if needed : // const getTop = element => element.offsetTop + (element.offsetParent && getTop(element.offsetParent)); -let sidenotes; +let articles; const resize = () => { - for (const sidenote of sidenotes) { + for (const [article, sidenote] of articles) { if (sidenote.offsetWidth < 200 || window.screen.width < 1400) { sidenote.innerHTML = ''; return; } - const articleRef = sidenote.attributes.for.value; - const article = document.querySelector(`#${CSS.escape(articleRef)}_article`); const notes = Array.from(article.querySelectorAll('li')) .filter(element => element.id.startsWith('user-content-fn')); const newSidenotes = notes.map(sidenoteLi => { @@ -57,9 +55,11 @@ const resize = () => { }; window.addEventListener('DOMContentLoaded', () => { - sidenotes = document.querySelectorAll('.sidenotes'); - if (sidenotes.length > 0) { - new ResizeObserver(resize).observe(sidenotes[0]); + articles = Array.from(document.querySelectorAll('article')); + + if (articles.length > 0) { + articles = articles.map(x => [x, x.parentElement.querySelector('.sidenotes')]); + new ResizeObserver(resize).observe(articles[0][1]); } if (document.querySelectorAll('.math-display').length > 0) { -- cgit v1.2.3