mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-06 03:13:42 -05:00
* First commit * Removed govuk for webpack. Modernized javascript importing. Removed dead js * Fixed tests, a few styling bugs * Fixed some table errors and regenerated backstop ref images * Updated tests for coverage * Changes from carlo suggestions
41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
const modules = new Map();
|
|
|
|
export function registerModule(name, ModuleClass) {
|
|
modules.set(name, ModuleClass);
|
|
window.NotifyModules = window.NotifyModules || {};
|
|
window.NotifyModules[name] = ModuleClass;
|
|
}
|
|
|
|
export function initModules() {
|
|
const moduleElements = document.querySelectorAll('[data-module]');
|
|
|
|
moduleElements.forEach(element => {
|
|
const moduleName = element.getAttribute('data-module');
|
|
const moduleStarted = element.getAttribute('data-module-started');
|
|
|
|
if (moduleStarted) return;
|
|
|
|
const ModuleClass = modules.get(moduleName);
|
|
|
|
if (!ModuleClass) {
|
|
console.warn(`Module "${moduleName}" not found in registry`);
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const moduleInstance = new ModuleClass();
|
|
|
|
if (moduleInstance.start && typeof moduleInstance.start === 'function') {
|
|
moduleInstance.start(element);
|
|
}
|
|
|
|
element.setAttribute('data-module-started', 'true');
|
|
} catch (error) {
|
|
console.error(`Error initializing module "${moduleName}":`, error);
|
|
}
|
|
});
|
|
}
|
|
|
|
window.NotifyModules = window.NotifyModules || {};
|
|
window.NotifyModules.start = initModules;
|