1 changed files with 25 additions and 14 deletions
@ -1,19 +1,30 @@ |
|||||||
(function (Drupal, once) { |
(function () { |
||||||
Drupal.behaviors.fixMiradorAnnotationSpaces = { |
// Guard against running multiple observers if the script is loaded more than once
|
||||||
attach: function (context, settings) { |
if (window.__miradorSpaceFixInitialized) return; |
||||||
// Find all Mirador annotation HTML content wrappers
|
window.__miradorSpaceFixInitialized = true; |
||||||
const annotationElements = once( |
|
||||||
"fix-annotation-spaces", |
|
||||||
".mirador-third-party-html", |
|
||||||
context |
|
||||||
); |
|
||||||
|
|
||||||
annotationElements.forEach((el) => { |
const observer = new MutationObserver((mutations) => { |
||||||
// Replace both the literal ' ' string and the non-breaking space character (\u00A0)
|
// Target any third-party HTML content blocks in Mirador that haven't been cleaned yet
|
||||||
|
const elements = document.querySelectorAll( |
||||||
|
".mirador-third-party-html:not([data-fixed])" |
||||||
|
); |
||||||
|
|
||||||
|
if (elements.length > 0) { |
||||||
|
elements.forEach((el) => { |
||||||
|
// Swap non-breaking spaces for normal breakable spaces
|
||||||
el.innerHTML = el.innerHTML |
el.innerHTML = el.innerHTML |
||||||
.replace(/ /g, " ") |
.replace(/ /g, " ") |
||||||
.replace(/\u00A0/g, " "); |
.replace(/\u00A0/g, " "); |
||||||
|
|
||||||
|
// Mark element so we don't re-process it on subsequent mutations
|
||||||
|
el.setAttribute("data-fixed", "true"); |
||||||
}); |
}); |
||||||
}, |
} |
||||||
}; |
}); |
||||||
})(Drupal, once); |
|
||||||
|
// Start observing the document body for dynamically added Mirador elements
|
||||||
|
observer.observe(document.body, { |
||||||
|
childList: true, |
||||||
|
subtree: true, |
||||||
|
}); |
||||||
|
})(); |
||||||
|
|||||||
Loading…
Reference in new issue