fancybox icon indicating copy to clipboard operation
fancybox copied to clipboard

Hash not working on selector

Open StyXman opened this issue 4 years ago • 6 comments

Describe the bug Assuming:

  • images don't have data-fancybox attribute (my gallery generator is removing those; I know, it's kinda also a bug in it too).
  • fancybox is launched with a selector because the images are generated (I think; this is what selector is for, and it's not working without it; I already tried $('[...]').fancybox(...));
  • with hash="image" (BTW, I think the doc is a little bit short here, it took me a while to figure out that for this method of starting fancybox I should set it to a string).
  • we arrive to the gallery with an image hash.

Then triggerFromUrl() fails because it's using $("[data-fancybox='" + $.escapeSelector(url.gallery) + "']") instead of selector.

To Reproduce Steps to reproduce the behavior:

  1. Go to http://dionecanali.hd.free.fr/~mdione/tmp/#image-2

Expected behavior The lightbox opens in the image.

Desktop:

  • OS: Linux Debian Sid
  • Browser: Firefox
  • Version: 74.0

StyXman avatar Apr 05 '20 20:04 StyXman

Here's the relevant line:

https://github.com/fancyapps/fancybox/blob/c4fd90370f8c93336d6e36a5c6120bcabcf8675c/src/js/hash.js#L53

StyXman avatar Apr 06 '20 06:04 StyXman

Hi,

Hash plugin grabs URL.hash and looks if any element has data-fancybox attribute with the same value. So, in order for this feature to work, your elements have to have data-fancybox attribute.

FYI, I am right now working on hash plugin for v4 (you can preview it here https://fancyapps.com/next/) so it might work in the future like you expect, but for v3 you have to use data-fancybox attributes, sorry about that.

fancyapps avatar Apr 06 '20 07:04 fancyapps

btw, nothing prevents you from starting fancybox manually, e.g., you could either trigger click event on corresponding link or use $.fancybox.open() inside $(document).ready()

fancyapps avatar Apr 06 '20 08:04 fancyapps

Good to know when I try to implement this for WP (if I knew how!).

chasdevlin avatar Apr 06 '20 17:04 chasdevlin

I understand. Now, If I would like to hack this (please confirm my finding is correct), how could I get a reference to opts.selector so I can use it in that line?

StyXman avatar Apr 06 '20 19:04 StyXman

Ah, I wrote that question before I got your other answer. I'll try that.

StyXman avatar Apr 06 '20 19:04 StyXman