Comments (7)
I just created a basic example here.
from iframemanager.
Unfortunately, that doesn't work either. I have invited you to the private repo and will send you the necessary .env contents via email.
Maybe it is a bug in this very specific context? I hope you can reproduce it.
from iframemanager.
The script seems to work after I change something and hot reload kicks in. After a full reload, the div is black again.
The services Map of im.getState()
is empty after a full reload, but not with hot reload. Maybe the script runs too early?
from iframemanager.
Finally! The simple thing is to use actions in Svelte: https://svelte.dev/docs/svelte-action
They run code after an element ist rendered to the DOM. Maybe update your Svelte example?
This is my final code:
// iframemanager.ts
import '@orestbida/iframemanager';
import '@orestbida/iframemanager/dist/iframemanager.css';
const im = (node) => {
// @ts-ignore
const im = iframemanager();
im.run({
...
});
};
export default im;
<!-- component.svelte -->
<script lang="ts">
import im from '$lib/Iframemanager';
</script>
<div {...dataAtts} use:im />
from iframemanager.
It worth noting that when you call run
multiple times you get multiple consent notice elements added to the DOM and they start to stack up. It seems running run
is not idempotent - it will in fact duplicate elements.
So I think Iframemanager as it stands does not support dynamic elements that are added after initial run
is called. Perhaps needs a refresh
method that just captures unknown ones and cleans up state for missing ones. run
can then just reject if already been given a config.
from iframemanager.
@orestbida I have another issue with SvelteKit. I try to load Google Maps API as a custom widget according to your demo.
Svelte:
<script>
// ...
const dataAtts = {
'data-service': 'maps',
'data-autoscale': '',
'data-lat': loc[0],
'data-lang': loc[1],
'data-title': embed.maps.title,
'data-phone': embed.maps.contact.phone.target,
'data-email': embed.maps.contact.email.target
};
// ...
</script>
<!-- ... -->
<div {...dataAtts} use:im>
<div data-placeholder>
<div id="map"></div>
</div>
</div>
onAccept:
onAccept: async (div, setIframe) => {
await CookieConsent.loadScript(
'https://maps.googleapis.com/maps/api/js?key=[API]'
);
await im.childExists({ childProperty: 'maps' });
const { lat, lng, title, phone, email } = div.dataset;
const map = new google.maps.Map(div.querySelector('#map') as HTMLElement, {
center: { lat: Number(lat), lng: Number(lng) },
zoom: 9
});
const infowindow = new google.maps.InfoWindow({
content: `<div style="max-width: 288px; padding: 8px 20px 20px 8px;"><p style="line-height: 1.2; margin-bottom: 12px;"><strong>${title}</strong></p><p style="line-height: 1.2;">Telefon: <a href="tel:${phone}">${phone}</a><br>E-Mail: <a href="mailto:${email}">${email}</a></p></div>`,
ariaLabel: title
});
const marker = new google.maps.Marker({
position: { lat: Number(lat), lng: Number(lng) },
map,
title: title
});
infowindow.open({
anchor: marker,
map
});
marker.addListener('click', () => {
infowindow.open({
anchor: marker,
map
});
});
(await im.childExists({ parent: div })) && setIframe(div.querySelector('iframe'));
},
The issue: My div#maps inside the placeholder is not there (before and after accept) and the black box is spinning forever. This error follows in the browser console:
Uncaught (in promise) InvalidValueError: Map: Expected mapDiv of type HTMLElement but was passed null.
Could you provide a working example for custom widgets with SvelteKit?
from iframemanager.
Related Issues (20)
- Merge cookies + automatically generate <div> around
- Google maps embed marker not showing HOT 2
- Add build tools
- Integration with cookieconsent
- Build `esm` and `umd` variants [v2]
- Add typescript types [v2]
- Support for Slideshare.net HOT 3
- iframemanager doesn't work HOT 5
- Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'name') HOT 4
- [Bug]: invalid iframe src when `iframe.params` is an empty string
- Use `rem/em` units rather than `px`
- [Bug]: loaded iframes outside viewport are not reset
- Parameters defined in the configuration are also added to the iframe as an attribute HOT 3
- Button properties not accessible via custom properties
- Add an option to hide the overlay if consent has already been given
- Use {data-id} on notice HOT 2
- Twitter/X "Read More" not clickable HOT 2
- Ist there a way to re-run? HOT 2
- When integrating with CookieConsent it still sets cookies
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from iframemanager.