fix: déplacer le JS de la TOC dans un fichier externe (CSP)
This commit is contained in:
@@ -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); });
|
||||||
|
})();
|
||||||
+1
-25
@@ -308,31 +308,7 @@ $hasSources = (!empty($externalLinks) || !empty($files))
|
|||||||
</div><!-- /row -->
|
</div><!-- /row -->
|
||||||
|
|
||||||
<?php if (count($_tocItems) >= 3): ?>
|
<?php if (count($_tocItems) >= 3): ?>
|
||||||
<script>
|
<script src="/assets/js/toc.js" defer></script>
|
||||||
(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); });
|
|
||||||
})();
|
|
||||||
</script>
|
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
|||||||
Reference in New Issue
Block a user