Skip to content

Commit b84d7b4

Browse files
committed
Expose mounting function via window object
1 parent 136df97 commit b84d7b4

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

sophora-components/datawrapper-switcher.html

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,10 @@
2828
import { mountEmbed } from '/src/lib/utils/mountEmbed';
2929
import Embed from '/src/components/datawrapper-switcher/embed.svelte';
3030

31-
function mount() {
32-
console.log('mounting datawrapper switcher embed');
33-
mountEmbed('datawrapper-switcher', Embed);
34-
}
35-
36-
window.addEventListener('popstate', () => {
37-
console.log('popstate, remounting datawrapper switcher embed');
38-
mount();
39-
});
40-
41-
if (document.readyState === 'loading') {
42-
document.addEventListener('DOMContentLoaded', mount);
43-
} else {
44-
mount();
45-
}
31+
window.__mountDatawrapperSwitcher = () => mountEmbed('datawrapper-switcher', Embed);
32+
</script>
33+
<script>
34+
window.__mountDatawrapperSwitcher && window.__mountDatawrapperSwitcher();
4635
</script>
4736
</body>
4837
</html>

sophora-components/highlight-cards.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828
import { mountEmbed } from '/src/lib/utils/mountEmbed';
2929
import Embed from '/src/components/highlight-cards/embed.svelte';
3030

31-
mountEmbed('highlight-cards', Embed);
31+
window.__mountHighlightCards = () => mountEmbed('highlight-cards', Embed);
32+
</script>
33+
<script>
34+
window.__mountHighlightCards && window.__mountHighlightCards();
3235
</script>
3336
</body>
3437
</html>

0 commit comments

Comments
 (0)