diff options
Diffstat (limited to 'src/js/sidenotes.js')
-rw-r--r-- | src/js/sidenotes.js | 14 |
1 files 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) { |