Files
crank/apps/ui/js/overlay-loader.js
T
github-ops ba29ac7b94
Deploy / deploy (push) Successful in 2m44s
CI / Rust Checks (push) Successful in 5m31s
CI / UI Checks (push) Successful in 5s
CI / Deployment Manifests (push) Successful in 2s
CI / Frontend E2E (push) Successful in 4m24s
chore: publish clean community baseline
2026-06-19 16:45:51 +00:00

76 lines
2.0 KiB
JavaScript

(function() {
var manifestPromise = null;
var loadedScripts = Object.create(null);
function overlayBasePath() {
return (window.APP_BASE || '/') + 'overlay/';
}
function fetchManifest() {
return fetch(overlayBasePath() + 'manifest.json', { cache: 'no-store' })
.then(function(response) {
if (response.status === 404) {
return null;
}
if (!response.ok) {
throw new Error('overlay manifest request failed');
}
return response.json();
})
.catch(function() {
return null;
});
}
function loadScript(path) {
if (loadedScripts[path]) {
return loadedScripts[path];
}
loadedScripts[path] = new Promise(function(resolve, reject) {
var script = document.createElement('script');
script.src = overlayBasePath() + path.replace(/^\/+/, '');
script.async = false;
script.onload = function() { resolve(); };
script.onerror = function() { reject(new Error('overlay script load failed')); };
document.head.appendChild(script);
}).catch(function() {
return null;
});
return loadedScripts[path];
}
function load() {
if (manifestPromise) {
return manifestPromise;
}
manifestPromise = fetchManifest().then(function(manifest) {
if (!(manifest && manifest.slots && window.CrankUiSlots)) {
return null;
}
var tasks = Object.entries(manifest.slots)
.filter(function(entry) {
return window.CrankUiSlots.isAllowed(entry[0]) && typeof entry[1] === 'string';
})
.map(function(entry) {
return loadScript(entry[1]);
});
return Promise.all(tasks).then(function() {
return manifest;
});
});
return manifestPromise;
}
async function render(root, context) {
await load();
if (window.CrankUiSlots) {
window.CrankUiSlots.renderAll(root, context);
}
}
window.CrankOverlay = {
load: load,
render: render,
};
}());