Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #523 - "Slider cannot be initialized in iframe" #675

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jayelkaake
Copy link

How to recreate the issue

Load glide in an iframe

What I Did

I changed the exist() method to use duck-typing instead of a null check.

The work that @ericmorand did in pull request #669 did not fully solve the problem, and also sort of makes it possible to pass invalid objects, so was not a preferred solution. Thanks for leading me in the right direction though @ericmorand!

How was it tested

Loaded in iframe and out of iframe.

Comment on lines +31 to +32
// We are usine duck-typing here because we can't use `instanceof` since if we're in an iframe the class instance will be different.
if (node && node.appendChild && node.isConnected) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that this seems like a better fix. However, I think it would be possible to avoid duck-typing by using ownerDocument.defaultView. Mostly I'm adding the comment because it seems like ownerDocument and defaultView are oft overlooked features of the DOM.

Suggested change
// We are usine duck-typing here because we can't use `instanceof` since if we're in an iframe the class instance will be different.
if (node && node.appendChild && node.isConnected) {
if (!node) return false
const nodeWindow = node.ownerDocument?.defaultView
if (nodeWindow && node instanceof nodeWindow.HTMLElement) {

I’d also probably just return the test nodeWindow && node instanceof nodeWindow.HTMLElement directly and eliminate the following returns but couldn’t do that in the scope of the suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants