summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorache <ache@ache.one>2022-05-04 22:05:53 +0200
committerache <ache@ache.one>2022-05-04 22:05:53 +0200
commit7b2dd1a311ca5f6beeaf966060a301bece6cff3b (patch)
tree3e54dc302501aeaa9c1387edf6574501286ba76b
parentw3c check (diff)
Fix sidenotes
-rw-r--r--src/js/sidenotes.js14
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) {