Skip to content

Commit

Permalink
#257 map doesn't be blank
Browse files Browse the repository at this point in the history
  • Loading branch information
smellman committed Oct 9, 2023
1 parent 0ca8a98 commit 4135cb4
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions app/helpers/gtt_map_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,37 @@ def map_tag(map: nil, layers: map&.layers,
content_tag(:div, "", data: data, id: uid, class: 'ol-map',
style: (collapsed ? "display: none" : "display: block")),
javascript_tag("
var contentObserver = () => {
const target = document.getElementById('#{uid}');
const observerCallback = function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.removedNodes.length) {
mutation.removedNodes.forEach(function(node) {
if (node === target) {
observer.disconnect();
let event = new Event('contentUpdated');
document.dispatchEvent(event);
}
});
}
});
};
const observer = new MutationObserver(observerCallback);
const config = {
childList: true,
subtree: true
};
observer.observe(document.body, config);
}
document.addEventListener('contentUpdated', function(){
var target = document.getElementById('#{uid}');
window.createGttClient(target);
contentObserver();
}, { once: true });
document.addEventListener('DOMContentLoaded', function(){
var target = document.getElementById('#{uid}');
window.createGttClient(target);
contentObserver();
});
")
]
Expand Down

0 comments on commit 4135cb4

Please sign in to comment.