Using different versions of Fancybox on the same page

I ran into the issue where some users had an older version of Fancybox on their sites and needed to provide my own version to work with Crayon. So I put together a modification of the original script which allows you to initialise Fancybox when you need it and with different objects to what it’s usually provided.

By default, Fancybox will apply these once the script is loaded: (window, document, jQuery)

And it will initialise jQuery.fancybox. If I want to have my own version running independently, I’d need to provide it with a jQuery instance and a custom attribute name, say “crayonFancybox” so I can use my version without accidentally using the old Fancybox on some users’ WordPress installs.

Now if you include jQuery and two different Fancybox scripts in the same page, they won’t clash:

The only downside is that you must use $(elem).crayonFancybox instead of $(elem).fancybox in your scripts.

See a demo, and download the script.