jsor / lity

Lightweight, accessible and responsive lightbox.
https://sorgalla.com/lity/
MIT License
1.16k stars 196 forks source link

Fix RegEx pattern for YouTube #256

Open nekoshippo opened 4 years ago

nekoshippo commented 4 years ago

When <a href="//youtu.be/WJ88GhJJI3Q?start=4394" data-lity>Link</a> is fired, var matches in lity.js is filled as

matches[0]: youtu.be/WJ88GhJJI3Q?start=4394
matches[1]: youtu.be
matches[2]: undefined
matches[3]: undefined
matches[4]: WJ88GhJJI3Q
matches[5]: ?start=4394

and then, lity builds a url below which includes %3F as an urlencoded result of ? in matches[5] so that YouTube does not start the movie at 4394. https://www.youtube.com/embed/WJ88GhJJI3Q?autoplay=1&%3Fstart=4394

So, var _youtubeRegex = /(youtube(-nocookie)?\.com|youtu\.be)\/(watch\?v=|v\/|u\/|embed\/?)?([\w-]{11})(.*)?/i; should be var _youtubeRegex = /(youtube(-nocookie)?\.com|youtu\.be)\/(watch\?v=|v\/|u\/|embed\/?)?([\w-]{11})\?(.*)?/i; for the expected behavior.

naton commented 2 years ago

Hi @nekoshippo, I'm interested in merging this into my "vanilla js" fork at https://github.com/naton/lity but unsure how to proceed. Any suggestions? Rebase this to my master there maybe?