32 lines
1.1 KiB
JavaScript
32 lines
1.1 KiB
JavaScript
// JIT file loading
|
|
function include_file(filename, id) {
|
|
fetch(`includes/${filename}.html`)
|
|
.then(response => response.text())
|
|
.then(html => { document.getElementById(id).innerHTML = html; })
|
|
.catch(err => console.error('Error loading include:', err));
|
|
}
|
|
|
|
function setupIntersectionObserver() {
|
|
const observer = new IntersectionObserver((entries) => {
|
|
entries.forEach(entry => {
|
|
if (entry.isIntersecting) {
|
|
const element = entry.target;
|
|
const name = element.getAttribute('data-section-name');
|
|
include_file(name, element.id);
|
|
observer.unobserve(element);
|
|
}
|
|
});
|
|
}, {
|
|
threshold: 0.05,
|
|
rootMargin: "0px 0px -50px 0px"
|
|
});
|
|
|
|
const observedSections = document.querySelectorAll('.observed');
|
|
if (observedSections.length === 0) {
|
|
console.error('No elements with class "observed" found!');
|
|
} else {
|
|
observedSections.forEach(section => { observer.observe(section); });
|
|
}
|
|
}
|
|
|
|
setupIntersectionObserver(); |