diff --git a/l4d2web/l4d2web/static/js/editor.js b/l4d2web/l4d2web/static/js/editor.js index df1742f..258042d 100644 --- a/l4d2web/l4d2web/static/js/editor.js +++ b/l4d2web/l4d2web/static/js/editor.js @@ -86,18 +86,31 @@ } } - function init() { - for (const ta of document.querySelectorAll("textarea[data-editor-language]")) { + function initEditors(root) { + const scope = root || document; + for (const ta of scope.querySelectorAll("textarea[data-editor-language]")) { mountOne(ta).catch(err => { console.error("[editor] mount failed", err); - unhideTextarea(ta); // restore the form-usable raw textarea + unhideTextarea(ta); }); } } if (document.readyState === "loading") { - document.addEventListener("DOMContentLoaded", init); + document.addEventListener("DOMContentLoaded", () => initEditors(document)); } else { - init(); + initEditors(document); + } + + // Re-init editors that arrive via HTMX swap (modal content, etc.). + document.body.addEventListener("htmx:afterSwap", (event) => { + if (event.target && event.target.id === "modal-content") { + initEditors(event.target); + } + }); + + // Expose for callers that need to re-mount imperatively. + if (window.__editor) { + window.__editor.initEditors = initEditors; } })();