summaryrefslogtreecommitdiff
path: root/src/js/sidenotes.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/js/sidenotes.js')
-rw-r--r--src/js/sidenotes.js26
1 files changed, 10 insertions, 16 deletions
diff --git a/src/js/sidenotes.js b/src/js/sidenotes.js
index f31bef7..db2781f 100644
--- a/src/js/sidenotes.js
+++ b/src/js/sidenotes.js
@@ -1,5 +1,3 @@
-'use strict';
-
function getPos(element) {
/* Element.getBoundingClientRect()
* Return box of the element relatively to viewport.
@@ -15,10 +13,10 @@ function getPos(element) {
};
}
-const getTop = element => element.offsetTop + (element.offsetParent && getTop(element.offsetParent));
-let sidenotes = undefined;
+// Use this if needed :
+// const getTop = element => element.offsetTop + (element.offsetParent && getTop(element.offsetParent));
+let sidenotes;
const resize = () => {
-
for (const sidenote of sidenotes) {
if (sidenote.offsetWidth < 200 || window.screen.width < 1400) {
sidenote.innerHTML = '';
@@ -26,8 +24,7 @@ const resize = () => {
}
const articleRef = sidenote.attributes.for.value;
- const article = document.querySelector(`#${articleRef}`);
- console.log(article, articleRef);
+ const article = document.querySelector(`#${CSS.escape(articleRef)}`);
const notes = Array.from(article.querySelectorAll('li'))
.filter(element => element.id.startsWith('user-content-fn'));
const newSidenotes = notes.map(sidenoteLi => {
@@ -59,16 +56,13 @@ const resize = () => {
}
};
-if (sidenotes.length > 0) {
- new ResizeObserver(resize).observe(sidenotes[0])
-}
-
-// window.addEventListener('resize', resize);
-window.addEventListener('DOMContentLoaded') () => {
-
-};
window.addEventListener('DOMContentLoaded', () => {
- if(document.querySelectorAll('.math-display').length > 0) {
+ sidenotes = document.querySelectorAll('.sidenotes');
+ if (sidenotes.length > 0) {
+ new ResizeObserver(resize).observe(sidenotes[0]);
+ }
+
+ if (document.querySelectorAll('.math-display').length > 0) {
document.head.innerHTML += '<link href="/s/css/katex.css" rel="stylesheet"/>';
}
});