From 63e297da167713e17fd271958b4109ea44e7075a Mon Sep 17 00:00:00 2001 From: ache Date: Fri, 9 Aug 2024 04:12:37 +0200 Subject: Lint JavaScript --- src/js/sidenotes.js | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) (limited to 'src/js/sidenotes.js') diff --git a/src/js/sidenotes.js b/src/js/sidenotes.js index 851e11b..591f856 100644 --- a/src/js/sidenotes.js +++ b/src/js/sidenotes.js @@ -19,19 +19,23 @@ let articles; const resize = () => { for (const [article, sidenote] of articles) { if (sidenote.offsetWidth < 200 || window.screen.width < 1400) { - sidenote.innerHTML = ''; + sidenote.innerHTML = ""; return; } - const notes = Array.from(article.querySelectorAll('li')) - .filter(element => element.id.startsWith('user-content-fn')); - const newSidenotes = notes.map(sidenoteLi => { - const div = document.createElement('div'); - const refName = sidenoteLi.querySelector('.data-footnote-backref').attributes.href.value; - const refSideNode = article.querySelector(`#${CSS.escape(refName.slice(1))}`); + const notes = Array.from(article.querySelectorAll("li")).filter((element) => + element.id.startsWith("user-content-fn"), + ); + const newSidenotes = notes.map((sidenoteLi) => { + const div = document.createElement("div"); + const refName = sidenoteLi.querySelector(".data-footnote-backref") + .attributes.href.value; + const refSideNode = article.querySelector( + `#${CSS.escape(refName.slice(1))}`, + ); - const sup = document.createElement('sup'); - sup.textContent = refSideNode.textContent + ' '; + const sup = document.createElement("sup"); + sup.textContent = refSideNode.textContent + " "; for (const element of sidenoteLi.children) { const child = element.cloneNode(true); @@ -40,7 +44,7 @@ const resize = () => { div.children[0].prepend(sup); div.style.top = `${getPos(refSideNode).y}px`; - div.classList.add('sidenote'); + div.classList.add("sidenote"); return div; }); @@ -48,21 +52,25 @@ const resize = () => { sidenote.replaceChildren(...newSidenotes); if (sidenote.offsetWidth < 100 || window.screen.width < 1400) { - sidenote.innerHTML = ''; + sidenote.innerHTML = ""; return; } } }; -window.addEventListener('DOMContentLoaded', () => { - articles = Array.from(document.querySelectorAll('article')); +window.addEventListener("DOMContentLoaded", () => { + articles = Array.from(document.querySelectorAll("article")); if (articles.length > 0) { - articles = articles.map(x => [x, x.parentElement.querySelector('.sidenotes')]); + articles = articles.map((x) => [ + x, + x.parentElement.querySelector(".sidenotes"), + ]); new ResizeObserver(resize).observe(articles[0][1]); } - if (document.querySelectorAll('.math-display').length > 0) { - document.head.innerHTML += ''; + if (document.querySelectorAll(".math-display").length > 0) { + document.head.innerHTML += + ''; } }); -- cgit v1.2.3-70-g09d2