noelboss / featherlight

Featherlight is a very lightweight jQuery lightbox plugin. It's simple yet flexible and easy to use. Featherlight has minimal css and uses no inline styles, everything is name-spaced, it's completely customizable via config object and offers image, ajax and iframe support out of the box. Featherlights small footprint weights about 4kB – in total.
https://www.noevu.ch/featherlight-js-the-ultra-slim-lightbox/
MIT License
2.08k stars 293 forks source link

Error while witching between elements of different "type" in a gallery #366

Open sayontan opened 6 years ago

sayontan commented 6 years ago

What kind of issue is this? (put 'x' between the square brackets)

I have been using Featherlight for a WordPress plugin Photonic that is available to the public for free. So far I haven't had an issue adapting the script to any of my scenarios, but I believe I have come across something that is causing Featherlight to break.

Fiddle: http://jsfiddle.net/JNsu6/722/

Scenario:

  1. If I have a mixed gallery with images and videos, and I mark every element of the gallery with an explicit data-featherlight-type, when I try to click on an element, it opens up fine. However, if I click on an image and then click left / right to go to a video, I get a JavaScript error saying "Uncaught TypeError: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'." as soon as I encounter the video.
  2. If, however, I drop the definition of data-featherlight-type="image" and just leave alone the ones that have video, this works fine.

I have verified that the behavior documented above is consistent if I switch to a different type instead of video (like wrapping the video in an HTML element and presenting it).

The reason I need to be able to do this is because my plugin is adding support for the new Google Photos API. Google Photos URLs don't have extensions, and if I try to pass a Google Photos URL as is, Featherlight reports "No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://xyz.org' is therefore not allowed access." If I explicitly define data-featherlight-type="image" or data-featherlight-type="video" then the "No 'Access-Control-Allow-Origin'" error goes away, but I am hit with the error in the JSFiddle when I try to transition to a video.

Hope this makes sense. I will be happy to provide more details if required.