File tree Expand file tree Collapse file tree 3 files changed +34
-18
lines changed
Expand file tree Collapse file tree 3 files changed +34
-18
lines changed Original file line number Diff line number Diff line change 2424 </ head >
2525 < body >
2626 < div data-lab-components-embed ="datawrapper-switcher "> </ div >
27+ < script >
28+ const target = document . currentScript . previousElementSibling ;
29+ if ( window . __mountDatawrapperSwitcher ) {
30+ window . __mountDatawrapperSwitcher ( target ) ;
31+ } else {
32+ document . addEventListener ( 'DOMContentLoaded' , ( ) => {
33+ window . __mountDatawrapperSwitcher ( target ) ;
34+ } ) ;
35+ }
36+ </ script >
2737 < script type ="module ">
28- import { mountEmbed } from '/src/lib/utils/mountEmbed' ;
38+ import mountEmbed from '/src/lib/utils/mountEmbed' ;
2939 import Embed from '/src/components/datawrapper-switcher/embed.svelte' ;
30- window . __mountDatawrapperSwitcher = ( ) => mountEmbed ( 'datawrapper-switcher' , Embed ) ;
31- window . __mountDatawrapperSwitcher ( ) ;
32- </ script >
33- < script >
34- window . __mountDatawrapperSwitcher && window . __mountDatawrapperSwitcher ( ) ;
40+
41+ window . __mountDatawrapperSwitcher = ( target ) => {
42+ console . log ( 'Mounting Datawrapper Switcher component on' , target ) ;
43+ mountEmbed ( target , Embed ) ;
44+ } ;
3545 </ script >
3646 </ body >
3747</ html >
Original file line number Diff line number Diff line change 2424 </ head >
2525 < body >
2626 < div data-lab-components-embed ="highlight-cards "> </ div >
27+ < script >
28+ const target = document . currentScript . previousElementSibling ;
29+ if ( window . __mountHighlightCards ) {
30+ window . __mountHighlightCards ( target ) ;
31+ } else {
32+ document . addEventListener ( 'DOMContentLoaded' , ( ) => {
33+ window . __mountHighlightCards ( target ) ;
34+ } ) ;
35+ }
36+ </ script >
2737 < script type ="module ">
28- import { mountEmbed } from '/src/lib/utils/mountEmbed' ;
38+ import mountEmbed from '/src/lib/utils/mountEmbed' ;
2939 import Embed from '/src/components/highlight-cards/embed.svelte' ;
3040
31- window . __mountHighlightCards = ( ) => mountEmbed ( 'highlight-cards' , Embed ) ;
32- window . __mountHighlightCards ( ) ;
33- </ script >
34- < script >
35- window . __mountHighlightCards && window . __mountHighlightCards ( ) ;
41+ window . __mountHighlightCards = ( target ) => {
42+ console . log ( 'Mounting Highlight Cards component on' , target ) ;
43+ mountEmbed ( target , Embed ) ;
44+ } ;
3645 </ script >
3746 </ body >
3847</ html >
Original file line number Diff line number Diff line change @@ -2,12 +2,9 @@ import { mount } from 'svelte';
22
33type ComponentConstructor = new ( ...args : any [ ] ) => any ;
44
5- export async function mountEmbed (
6- componentName : string ,
5+ export default async function mountEmbed (
6+ target : Element ,
77 Component : ComponentConstructor
88) : Promise < void > {
9- const selector = `[data-lab-components-embed="${ componentName } "]` ;
10- document . querySelectorAll ( selector ) . forEach ( ( target ) => {
11- mount ( Component , { target } ) ;
12- } ) ;
9+ mount ( Component , { target } ) ;
1310}
You can’t perform that action at this time.
0 commit comments