update 4page
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* Loads Leading V2 header/footer modules (separate from layout.js nav/footer).
|
||||
*/
|
||||
(function () {
|
||||
var HEADER_URL = "/components/leading-v2-header.html";
|
||||
var FOOTER_URL = "/components/leading-v2-footer.html";
|
||||
|
||||
function fetchText(url) {
|
||||
return fetch(url, { credentials: "same-origin" }).then(function (res) {
|
||||
if (!res.ok) throw new Error("Failed to load " + url + " (" + res.status + ")");
|
||||
return res.text();
|
||||
});
|
||||
}
|
||||
|
||||
function injectHtml(containerId, html) {
|
||||
var el = document.getElementById(containerId);
|
||||
if (!el) return null;
|
||||
el.innerHTML = html;
|
||||
return el;
|
||||
}
|
||||
|
||||
function updateCopyrightYear(root) {
|
||||
var year = String(new Date().getFullYear());
|
||||
root.querySelectorAll("[data-lv2-year]").forEach(function (el) {
|
||||
el.textContent = year;
|
||||
});
|
||||
}
|
||||
|
||||
function initLayoutV2() {
|
||||
var headerContainer = document.getElementById("header-v2-container");
|
||||
var footerContainer = document.getElementById("footer-v2-container");
|
||||
if (!headerContainer && !footerContainer) return;
|
||||
|
||||
var tasks = [];
|
||||
tasks.push(headerContainer ? fetchText(HEADER_URL) : Promise.resolve(null));
|
||||
tasks.push(footerContainer ? fetchText(FOOTER_URL) : Promise.resolve(null));
|
||||
|
||||
Promise.all(tasks)
|
||||
.then(function (parts) {
|
||||
var headerHtml = parts[0];
|
||||
var footerHtml = parts[1];
|
||||
|
||||
if (headerHtml) {
|
||||
injectHtml("header-v2-container", headerHtml);
|
||||
}
|
||||
|
||||
if (footerHtml) {
|
||||
var footerRoot = injectHtml("footer-v2-container", footerHtml);
|
||||
if (footerRoot) updateCopyrightYear(footerRoot);
|
||||
}
|
||||
|
||||
document.dispatchEvent(new CustomEvent("aifo:layout-v2-ready"));
|
||||
})
|
||||
.catch(function (err) {
|
||||
console.error("[layout-v2.js]", err);
|
||||
});
|
||||
}
|
||||
|
||||
if (document.readyState === "loading") {
|
||||
document.addEventListener("DOMContentLoaded", initLayoutV2);
|
||||
} else {
|
||||
initLayoutV2();
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user