orep-js/sunpy/node/node.js
2020-04-21 00:03:26 +02:00

26 lines
588 B
JavaScript

const handlers = {};
var onloadOld = onload || (() => {});
onload = () => {
onloadOld();
init();
}
function init() {
for(const k in handlers) {
for (const n of getNodes(k)) {
handlers[k](n);
}
}
}
function getNodes(scriptType) {
return Array.from( document.querySelectorAll(`script[type="orep/${scriptType}"]`) ).filter(n => !n.dataset.handled);
}
export function register(scriptType, handler) {
if (scriptType in handlers)
throw new Error(`'${scriptType}' is already registered`);
handlers[scriptType] = handler;
}