This commit is contained in:
robbieandrew
2025-07-04 11:06:03 +02:00
parent 777f64a7e4
commit dfa410436a
2 changed files with 38 additions and 6 deletions

View File

@@ -11,9 +11,14 @@ function updateHighlight() {
async function loadSiteDataFiles(siteCode, partialPath) {
try {
const dataFiles = await fetchGitHubDataFiles(siteCode, partialPath);
availableDataFiles = dataFiles;
console.log(`Full list of data files found for ${siteCode}: ${availableDataFiles}`);
return true;
if (dataFiles) {
availableDataFiles = dataFiles;
console.log(`Full list of data files found for ${siteCode}: ${availableDataFiles}`);
return true;
} else {
console.log("No data files found");
return false;
}
} catch (error) {
console.error("Failed to initialize SVGs:", error);
return false;

View File

@@ -3,8 +3,9 @@
document.addEventListener("DOMContentLoaded", async () => {
const url_path = window.location.pathname;
const parts = url_path.startsWith('/') ? url_path.substring(1).split('/') : url_path.split('/');
// obtaining the list of data files could sometimes take a while, allowing some SVGs to already be loaded before it's finished. In that case we can't add an event listener to process the SVG after it's loaded, because it's already loaded. So below we handle these two cases: SVG already loaded, then process it; SVG not yet loaded, add an event listener.
const loaded = await loadSiteDataFiles("data",parts[0]);
document.querySelectorAll('object[type="image/svg+xml"]').forEach(svgObject => {
/* document.querySelectorAll('object[type="image/svg+xml"]').forEach(svgObject => {
svgObject.addEventListener("load", function () {
// Add a PNG download link for every SVG on the page
addSVGbuttons(svgObject);
@@ -25,8 +26,34 @@
if (container) {
container.classList.add("figure-group");
}
});
});*/
document.querySelectorAll('object[type="image/svg+xml"]').forEach(svgObject => {
function handleSVGLoad() {
addSVGbuttons(svgObject);
addSVGmetadata(svgObject);
const svgDoc = svgObject.contentDocument;
if (svgDoc) {
const titleElement = svgDoc.querySelector("title");
if (titleElement) {
const titleText = titleElement.textContent.trim();
svgObject.setAttribute("data-title", titleText);
}
}
const container = svgObject.closest("div");
if (container) {
container.classList.add("figure-group");
}
}
if (svgObject.contentDocument && svgObject.contentDocument.rootElement) {
// Already loaded, probably due to fast load before listener was attached
handleSVGLoad();
} else {
svgObject.addEventListener("load", handleSVGLoad);
}
});
});