Skip to content

Commit b404424

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

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

sophora-components/datawrapper-switcher.html

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,11 @@
2727
<script type="module">
2828
import { mountEmbed } from '/src/lib/utils/mountEmbed';
2929
import Embed from '/src/components/datawrapper-switcher/embed.svelte';
30-
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-
}
30+
window.__mountDatawrapperSwitcher = () => mountEmbed('datawrapper-switcher', Embed);
31+
window.__mountDatawrapperSwitcher();
32+
</script>
33+
<script>
34+
window.__mountDatawrapperSwitcher && window.__mountDatawrapperSwitcher();
4635
</script>
4736
</body>
4837
</html>

sophora-components/highlight-cards.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@
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+
window.__mountHighlightCards();
33+
</script>
34+
<script>
35+
window.__mountHighlightCards && window.__mountHighlightCards();
3236
</script>
3337
</body>
3438
</html>

0 commit comments

Comments
 (0)