mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 08:09:18 +02:00
#gzip #extract-inline-js enable gzip in nginx + move ~730 lines of inline JS to 15 external files
This commit is contained in:
@@ -12,46 +12,4 @@
|
||||
</nav>
|
||||
</aside>
|
||||
|
||||
<script>
|
||||
(function() {
|
||||
function build() {
|
||||
var main = document.getElementById('main-content');
|
||||
var nav = document.getElementById('admin-toc-list');
|
||||
var aside = document.getElementById('admin-toc');
|
||||
if (!main || !nav || !aside) return;
|
||||
|
||||
var sections = main.querySelectorAll('section[aria-labelledby]');
|
||||
if (sections.length < 2) { aside.hidden = true; return; }
|
||||
|
||||
var items = [];
|
||||
sections.forEach(function(sec) {
|
||||
var headingId = sec.getAttribute('aria-labelledby');
|
||||
var heading = document.getElementById(headingId);
|
||||
if (!heading) return;
|
||||
if (!sec.id) sec.id = headingId;
|
||||
|
||||
var a = document.createElement('a');
|
||||
a.href = '#' + sec.id;
|
||||
a.textContent = heading.textContent.trim();
|
||||
a.style.display = 'block';
|
||||
nav.appendChild(a);
|
||||
items.push({ section: sec, link: a });
|
||||
});
|
||||
|
||||
var observer = new IntersectionObserver(function(entries) {
|
||||
var best = null, bestRatio = 0;
|
||||
entries.forEach(function(e) {
|
||||
if (e.intersectionRatio > bestRatio) { bestRatio = e.intersectionRatio; best = e.target; }
|
||||
});
|
||||
items.forEach(function(item) {
|
||||
item.link.classList.toggle('admin-toc-active', item.section === best);
|
||||
});
|
||||
}, { rootMargin: '-10% 0px -70% 0px', threshold: [0, 0.25, 0.5, 0.75, 1] });
|
||||
|
||||
items.forEach(function(item) { observer.observe(item.section); });
|
||||
}
|
||||
|
||||
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', build);
|
||||
else build();
|
||||
})();
|
||||
</script>
|
||||
<script src="<?= App::assetV('/assets/js/app/admin-toc.js') ?>"></script>
|
||||
|
||||
Reference in New Issue
Block a user