|
|
|
@ -1,28 +1,35 @@ |
|
|
|
(function () { |
|
|
|
(function () { |
|
|
|
// Guard against running multiple observers if the script is loaded more than once
|
|
|
|
|
|
|
|
if (window.__miradorSpaceFixInitialized) return; |
|
|
|
if (window.__miradorSpaceFixInitialized) return; |
|
|
|
window.__miradorSpaceFixInitialized = true; |
|
|
|
window.__miradorSpaceFixInitialized = true; |
|
|
|
|
|
|
|
|
|
|
|
const observer = new MutationObserver((mutations) => { |
|
|
|
const observer = new MutationObserver((mutations) => { |
|
|
|
// Target any third-party HTML content blocks in Mirador that haven't been cleaned yet
|
|
|
|
|
|
|
|
const elements = document.querySelectorAll( |
|
|
|
const elements = document.querySelectorAll( |
|
|
|
".mirador-third-party-html:not([data-fixed])" |
|
|
|
".mirador-third-party-html:not([data-fixed])" |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
if (elements.length > 0) { |
|
|
|
|
|
|
|
elements.forEach((el) => { |
|
|
|
elements.forEach((el) => { |
|
|
|
// Swap non-breaking spaces for normal breakable spaces
|
|
|
|
// Create a TreeWalker to find all text nodes inside this container
|
|
|
|
el.innerHTML = el.innerHTML |
|
|
|
const walker = document.createTreeWalker( |
|
|
|
.replace(/ /g, " ") |
|
|
|
el, |
|
|
|
.replace(/\u00A0/g, " "); |
|
|
|
NodeFilter.SHOW_TEXT, |
|
|
|
|
|
|
|
null, |
|
|
|
|
|
|
|
false |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
let node; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while ((node = walker.nextNode())) { |
|
|
|
|
|
|
|
// Replace both non-breaking space characters and entity text if present
|
|
|
|
|
|
|
|
if (node.nodeValue) { |
|
|
|
|
|
|
|
node.nodeValue = node.nodeValue |
|
|
|
|
|
|
|
.replace(/\u00A0/g, " ") |
|
|
|
|
|
|
|
.replace(/ /g, " "); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Mark element so we don't re-process it on subsequent mutations
|
|
|
|
|
|
|
|
el.setAttribute("data-fixed", "true"); |
|
|
|
el.setAttribute("data-fixed", "true"); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// Start observing the document body for dynamically added Mirador elements
|
|
|
|
|
|
|
|
observer.observe(document.body, { |
|
|
|
observer.observe(document.body, { |
|
|
|
childList: true, |
|
|
|
childList: true, |
|
|
|
subtree: true, |
|
|
|
subtree: true, |
|
|
|
|