IFrame Lightboxes

This is a theme component that adds the ability to open iFrames in lightboxes.

Samples

This component adds an “expand” button on top of the iframes you enable it on.

Clicking the button will open the iframe in fullscreen in a lightbox.

Clicking either the dark area around the iframe or the x at the top right corner closes the lightbox. The same way it works for default image lightboxes.

Settings

There’s only one setting. You add the domains that you want to have this functionality on there.

:warning: Whatever domains you specify here also need to be whitelisted in the allowed_iframes site setting to show up in posts in the first place.

Usage examples:

Here’s a couple of examples besides the CodePen iframe above

Google forms iframe:

Embedding the entire weather.gov website:

Credit:

This component uses Noël Bossart’s fantastic Featherlight library (MIT license - 3kb gzip)

31 Likes

I suppose these iframes still also need to be activated in the allowed iframes site setting?

5 Likes

Correct, this component will not mess with any whitelisting settings at all.

In order for any iframe to show up in the cooked content of a post - expandable or not - it has to be on the list of allowed_iframes setting like you pointed out.

I’ll add a note about this to the topic.

5 Likes

@Johani is this component still functional? If so, any thoughts on why I am not getting the pop-out diagonal-arrows in the upper-right, but rather a blank/dead box?

Here is what I’ve tried:

  • Updated themes/components.
  • Made sure src links were white-listed in the component and the Discourse settings.
  • Tried a few different links, including Google Maps.
  • Tried several scenarios with the Media Overlay on/off + Lightbox alone on/off.

Below are some screenshots.

Thx!
-Patrick





image
image
image
image

Dear @Johani,

thank you very much for conceiving and maintaining this theme component.

After installing it on https://community.hiveeyes.org/ the other day, some users recently started to complain that the overall appearance of the head of the page looked different for them. They finally found out the reason was that they blocked cloudflare altogether, so all requests to https://cdnjs.cloudflare.com/ajax/libs/featherlight/1.7.13/featherlight.min.js would fail.

So, we are humbly asking if there would be a way for you to provide this component in a self-contained variant?

With kind regards,
Andreas.

3 Likes

Why is it desktop-only?

I had a bug this theme component, post contents weren’t showing.

Could I trigger open iframe in a any link simply?
User just see iframe only when click at link

1 Like

Welp… this one fell through the cracks. It’s been a while since it got any attention, and a lot has changed in Discourse.

Better late than never… :upside_down_face:

I just pushed an update that should fix all the problems.

It will be after you update.

The component is now self-contained with no external requests.

After you update, it will work on mobile too.

Should be fixed after you update

This is out of the scope of this component. You need a different component to handle that.

Apologies for the delay, and thanks for the feedback :+1:

7 Likes

Thanks a stack!

No need to apologize, nice to see you have been able to give it some love, in between all the other things going on. We really appreciate it.

1 Like

Is there already a component that can open an iframe lightbox in a link that way?

I’m not aware of any existing components that do that, so you’d have to create one or commission that work in the marketplace category.

This theme component checks iFrame tags in a post and compares their src attribute to a list of eligible sources provided by the admin in the component settings. If the source domain matches, it adds the lightbox button. Showing the lightbox is handled by featherlight.js. Featherlight listens to clicks on elements with the data-featherlight attribute. If one of those is clicked, it opens the lightbox with the contents of that iFrame.

You can do the same with <a> tags in a different component with a little bit of wrangling. If the link href matches a domain listed in the component settings, lightbox it in an iframe. Otherwise, leave it as a regular link. You don’t want all links to open in a lightboxed iframe.

Most of the required work is already handled by this component so you can just hard-fork it and start from there. There’s no plans to add that feature to this component because it’s only meant to handle iFrame tags in posts.

3 Likes

Here is one method for including an iFrame Lightbox inside a clickable inline text element …

The Discourse Footnotes Plugin accepts HTML as well as Markdown inside popup footnotes.

So for example this code …

… generates this clickable popup footnote containing a mini iFrame with the Expand content button on the top right corner …

To make this work I have (in site settings) enabled both enable markdown footnotes and display footnotes inline

Then I added that site’s domain name (microchic.com) to the allowed iframes list in site settings …

… and also in the list of iframe origin domains in the iFrame Lightbox Plugin settings …

You can try it out live here …

Hi was wondering how you format posts. I get a blank box using

iframe src=" url" surrounded by < > That is even when using codepen.io that is on the main site whitelist iframes.

Is this component still working? It used to work for me in the past but stopped working for some reason.
Seems like last update was 3 years ago: hnb-ku/discourse-iframe-lightboxes (github.com) So reasonable to assume something broke?

1 Like

It was working in May as used it here.

1 Like

It works on my side with the latest Discourse version.

Is there any error in the browser console?

2 Likes

Can’t make this work, I followed the guide precisely and added the domain to both the theme component and the site setting. Here’s what I get:

No errors recorded in js developer console.

allowed iframes site setting has the top-level domain:

https://example.biz/

The theme component settings has it without https as by the existing examples:

example.biz

Any ideas how to debug?

1 Like

no errors in the console.
I’m using it with PDF previews: Inline PDF Previews - #116 by Alon1
I expect to get the expand arrows above the PDF

image

But they simply won’t show up

Can you try this fork instead?

URL: https://github.com/Arkshine/discourse-iframe-lightboxes
Branch: improve-compatibility

You were lucky before if it was working!

Both TCs use the same API to decorate a post, so the order in which you install them would be necessary. Also, the iframe source is set dynamically once the PDF has been downloaded and may not be available immediately in this IFrame Lighboxes TC.

The changes I made are basically:

  • Search for iframe elements in the next run loop, so iframe is guaranteed to be available
  • Wait for the iframe to load so you can retrieve the source URL

Let me know if it works better. :+1:

3 Likes