diff --git a/pages/Beamline_elements/Beamline_elements_config.js b/pages/Beamline_elements/Beamline_elements_config.js index 6a8a7c7..b48a12d 100644 --- a/pages/Beamline_elements/Beamline_elements_config.js +++ b/pages/Beamline_elements/Beamline_elements_config.js @@ -1,3 +1,25 @@ +/** + * Monitor the MIDAS side navigation for changes and reapply the URL fix. + * + * mhttpd may rebuild the side navigation after initial page loading. + * A MutationObserver ensures that newly created menu links are corrected + * automatically without modifying the standard mhttpd.js library using + * fixMenuLinks() + */ +export function watchMenuLinks() { + const menu = document.getElementById("msidenav"); + + const observer = new MutationObserver(() => { + fixMenuLinks(); + }); + + observer.observe(menu, { + childList: true, + subtree: true + }); + + fixMenuLinks(); +} /** * Fix MIDAS side navigation links for standalone custom pages. @@ -22,27 +44,4 @@ function fixMenuLinks() { document.querySelectorAll("#msidenav a[href^='?cmd=']").forEach(link => { link.href = "/" + link.getAttribute("href"); }); -} - -/** - * Monitor the MIDAS side navigation for changes and reapply the URL fix. - * - * mhttpd may rebuild the side navigation after initial page loading. - * A MutationObserver ensures that newly created menu links are corrected - * automatically without modifying the standard mhttpd.js library using - * fixMenuLinks() - */ -function watchMenuLinks() { - const menu = document.getElementById("msidenav"); - - const observer = new MutationObserver(() => { - fixMenuLinks(); - }); - - observer.observe(menu, { - childList: true, - subtree: true - }); - - fixMenuLinks(); } \ No newline at end of file diff --git a/pages/common.js b/pages/common.js index ea095e4..8bc717e 100644 --- a/pages/common.js +++ b/pages/common.js @@ -15,6 +15,8 @@ // stefan.mathis@psi.ch //**************************************************************************// +import watchMenuLinks from "./Beamline_elements/Beamline_overview_images.js"; + /** * Stop the current run, after user confirmation. * @@ -153,6 +155,9 @@ export async function init(instrTabs, instrODB, instrName, instrColor, elogLink) used by experts only.\nBy continuing, you agree to take responsibility for any damage to the experiment or loss of beam time.`); }; + + // Initialize site link transformer for Beamline_elements + watchMenuLinks(); } // Global variables