Implement initAnatomyFragment function for HTMX fragment swaps to initialize DICOM viewers

This commit is contained in:
Ross
2025-11-10 12:15:15 +00:00
parent 0acc2da374
commit ed88f794f8
2 changed files with 21 additions and 1 deletions
+20
View File
@@ -341,6 +341,26 @@ function loadJsonToolStateOnCurrentImage(element, json) {
}
// Called by HTMX after a fragment swap; initializes any dicom-image-legacy viewers
window.initAnatomyFragment = function(fragmentRoot) {
try {
// If a fragment root is an element (hx-on passes `this`), search within it.
const root = fragmentRoot || document;
const imgs = (root.querySelectorAll) ? root.querySelectorAll('.dicom-image-legacy') : [];
imgs.forEach((el) => {
try {
if (typeof window.setUpDicomLegacy === 'function') {
window.setUpDicomLegacy(el);
}
} catch (err) {
console.warn('initAnatomyFragment: setUpDicomLegacy failed for element', el, err);
}
});
} catch (err) {
console.warn('initAnatomyFragment error', err);
}
}
async function setUpDicomLegacy(element) {
console.log("setUpDicom (original)", element);