From dca653bba4c70bad7f205c186dfd351ae9d5beb6 Mon Sep 17 00:00:00 2001 From: Cedric Abonnel Date: Wed, 13 May 2026 01:11:48 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20d=C3=A9placer=20le=20JS=20de=20la=20TOC?= =?UTF-8?q?=20dans=20un=20fichier=20externe=20(CSP)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/assets/js/toc.js | 23 +++++++++++++++++++++++ templates/post_view.php | 26 +------------------------- 2 files changed, 24 insertions(+), 25 deletions(-) create mode 100644 public/assets/js/toc.js diff --git a/public/assets/js/toc.js b/public/assets/js/toc.js new file mode 100644 index 0000000..24ddbb2 --- /dev/null +++ b/public/assets/js/toc.js @@ -0,0 +1,23 @@ +(function () { + var headings = document.querySelectorAll('.post-content h2, .post-content h3'); + var links = document.querySelectorAll('.toc-list a'); + if (!headings.length || !links.length) return; + + var map = {}; + links.forEach(function (a) { + map[decodeURIComponent(a.getAttribute('href').slice(1))] = a; + }); + + var active = null; + var observer = new IntersectionObserver(function (entries) { + entries.forEach(function (entry) { + if (entry.isIntersecting) { + if (active) active.classList.remove('toc-active'); + active = map[entry.target.id] || null; + if (active) active.classList.add('toc-active'); + } + }); + }, { rootMargin: '-8% 0px -82% 0px', threshold: 0 }); + + headings.forEach(function (h) { observer.observe(h); }); +})(); diff --git a/templates/post_view.php b/templates/post_view.php index 8bdcc7f..0aefb68 100644 --- a/templates/post_view.php +++ b/templates/post_view.php @@ -308,31 +308,7 @@ $hasSources = (!empty($externalLinks) || !empty($files)) = 3): ?> - +