105 lines
2.8 KiB
JavaScript
105 lines
2.8 KiB
JavaScript
// Load header and footer, then initialize navbar script after header injected
|
|
['header', 'footer'].forEach(id => {
|
|
const file = id === 'header' ? 'components/header.html' : 'components/footer.html';
|
|
fetch(file)
|
|
.then(res => res.text())
|
|
.then(html => {
|
|
const mount = document.getElementById(id);
|
|
if (!mount) return;
|
|
mount.innerHTML = html;
|
|
if (id === 'header') {
|
|
const script = document.createElement('script');
|
|
script.src = 'js/navbar.js';
|
|
script.defer = true;
|
|
document.body.appendChild(script);
|
|
}
|
|
});
|
|
});
|
|
|
|
// Pages mapping
|
|
const routes = {
|
|
"#/": "pages/home.html",
|
|
"#/our-fund": "pages/our-fund.html",
|
|
"#/our-team": "pages/our-team.html",
|
|
"#/about": "pages/about.html",
|
|
"#/contact": "pages/contact.html",
|
|
"#/blog": "pages/blog.html",
|
|
};
|
|
|
|
// ✅ Function to initialize Swiper (only if needed)
|
|
function initSwiper() {
|
|
if (document.querySelector(".mySwiper")) {
|
|
new Swiper(".mySwiper", {
|
|
slidesPerView: 1.2,
|
|
spaceBetween: 20,
|
|
loop: true,
|
|
autoplay: {
|
|
delay: 2500, // ⏱️ 2.5 seconds between slides
|
|
disableOnInteraction: false, // keep auto even after manual swipe
|
|
},
|
|
|
|
});
|
|
console.log("✅ Swiper initialized with autoplay");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Load page content
|
|
// Load page content
|
|
function loadPage() {
|
|
const hash = location.hash || "#/";
|
|
const page = routes[hash] || routes["#/"];
|
|
|
|
fetch(page)
|
|
.then(res => res.text())
|
|
.then(html => {
|
|
document.getElementById("page-content").innerHTML = html;
|
|
|
|
// ✅ Scroll to top of page after content is loaded
|
|
window.scrollTo({ top: 0, behavior: "smooth" });
|
|
|
|
// ✅ Initialize Swiper after HTML is inserted
|
|
initSwiper();
|
|
})
|
|
.catch(() => {
|
|
document.getElementById("page-content").innerHTML = "<h2>Page not found</h2>";
|
|
});
|
|
}
|
|
|
|
|
|
// Load page on hash change
|
|
window.addEventListener("hashchange", loadPage);
|
|
|
|
// Load default page
|
|
loadPage();
|
|
|
|
// Define globally so inline onclick works
|
|
window.openDrawer = function (name, role, img, desc) {
|
|
document.getElementById("drawerName").textContent = name;
|
|
document.getElementById("drawerRole").textContent = role;
|
|
document.getElementById("drawerImg").src = img;
|
|
|
|
// Use innerHTML to preserve paragraph breaks
|
|
document.getElementById("drawerDesc").innerHTML = desc;
|
|
|
|
const drawer = bootstrap.Offcanvas.getOrCreateInstance(document.getElementById('teamDrawer'));
|
|
drawer.show();
|
|
};
|
|
|
|
|
|
gsap.registerPlugin(ScrollTrigger);
|
|
|
|
const slides = gsap.utils.toArray('.home_service_item');
|
|
|
|
gsap.to(slides, {
|
|
yPercent: -100 * (slides.length - 1),
|
|
ease: "none",
|
|
scrollTrigger: {
|
|
trigger: ".home_services_wrapper",
|
|
pin: true,
|
|
scrub: 1,
|
|
snap: 1 / (slides.length - 1),
|
|
end: () => "+=" + document.querySelector(".home_services_wrapper").offsetHeight,
|
|
}
|
|
}); |