From af5d510c803ea98a1ce2c45de48da1a1816f31a1 Mon Sep 17 00:00:00 2001 From: Andrew Brehaut Date: Mon, 23 Sep 2019 19:56:58 +1200 Subject: [PATCH] #544 Better handling of the footnote reverse links * Uses a stylesheet to hide the reverse link in the popover rather than monkeying around with the dom in JS * Javascript event handler catches clicks on the reverse buttons in the footnote list at the bottom of the page and scrolls the document back to the source, rather than opening the document in a browser window. --- Mac/MainWindow/Detail/styleSheet.css | 3 +++ Shared/Article Rendering/newsfoot.js | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Mac/MainWindow/Detail/styleSheet.css b/Mac/MainWindow/Detail/styleSheet.css index c39d376ce..e47f1255b 100644 --- a/Mac/MainWindow/Detail/styleSheet.css +++ b/Mac/MainWindow/Detail/styleSheet.css @@ -199,6 +199,9 @@ img[src*="share-buttons"] { border-radius: 0.3em; box-sizing: border-box; } +.newsfoot-footnote-popover .reversefootnote { + display: none; +} a.footnote { display: inline-block; text-decoration: none; diff --git a/Shared/Article Rendering/newsfoot.js b/Shared/Article Rendering/newsfoot.js index 7374610e7..a599bb1c7 100644 --- a/Shared/Article Rendering/newsfoot.js +++ b/Shared/Article Rendering/newsfoot.js @@ -107,16 +107,27 @@ } } + // Handle clicks on the footnote reference document.addEventListener("click", (ev) => { if (!(ev.target && ev.target instanceof HTMLAnchorElement)) return; if (!ev.target.matches(".footnote")) return; ev.preventDefault(); const content = document.querySelector(`[id='${ev.target.hash.substring(1)}']`).cloneNode(true); - if (content instanceof HTMLElement) { - remove(content.querySelector(".reversefootnote")); - } installContainer(ev.target); void new Footnote(fragFromContents(content), ev.target); }); + + // Handle clicks on the footnote reverse link + document.addEventListener("click", (ev) => + { + if (!(ev.target && ev.target instanceof HTMLAnchorElement)) return; + if (!ev.target.matches(".footnotes .reversefootnote")) return; + const hash = ev.target.hash; + if (!hash) return; + const fnref = document.getElementById(hash.substring(1)); + + window.scrollTo({ top: fnref.getBoundingClientRect().top + window.scrollY }); + ev.preventDefault(); + }); }());