Update ajax to use intersection observer

This commit is contained in:
A McIlwraith 2024-07-14 21:52:51 -04:00
parent 2f4c21397b
commit 1c0186d4fe

View File

@ -185,6 +185,13 @@ module.exports = {
document.querySelectorAll("article").forEach((a) => { document.querySelectorAll("article").forEach((a) => {
if ( a.getAttribute("data-template") != "none" ) { if ( a.getAttribute("data-template") != "none" ) {
const observer = new IntersectionObserver((articles, { threshold: 0, rootMargin: 50vh}) => {
articles.forEach(article => {
let a = article.target;
if (article.isIntersecting) {
let path = a.getAttribute("data-path"); let path = a.getAttribute("data-path");
path = "patterns/" + path = "patterns/" +
(a.getAttribute("data-core") == "true" ? (a.getAttribute("data-core") == "true" ?
@ -267,6 +274,13 @@ module.exports = {
}; };
ajx.open("GET", path, ASYNC); ajx.open("GET", path, ASYNC);
ajx.send(); ajx.send();
}
})
})
observer.observe(a);
} }
}) })