fancybox
fancybox copied to clipboard
Hash not working on selector
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 aselector
because the images are generated (I think; this is whatselector
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 startingfancybox
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:
- 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
Here's the relevant line:
https://github.com/fancyapps/fancybox/blob/c4fd90370f8c93336d6e36a5c6120bcabcf8675c/src/js/hash.js#L53
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.
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()
Good to know when I try to implement this for WP (if I knew how!).
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?
Ah, I wrote that question before I got your other answer. I'll try that.