fancybox icon indicating copy to clipboard operation
fancybox copied to clipboard

Init Fancybox in AJAX loaded content

Open clevertools opened this issue 10 years ago • 1 comments

I have a complex application and do heavy load of ajax content and subcontent. Fancybox is working fine when I initialize with: $(".fancybox").fancybox(fancy_options);

but newly loaded ajax content with fancybox elements is sometimes initialized and sometimes not. Clicking the element with the correct class works not always. So the obvious solution is to init the new content after ajax loading: $("#NewLoadedDiv .fancybox").fancybox(fancy_options);

It works but if it was already initialized by magic it duplicates all event handlers like onclose. Every handler is called multiple times and causes problems so this is no solution.

Is there a way to init all ajax loaded content easily and only once?

Maybe as workaround: Can I clear existing fancybox instances and handlers and reinit everything?

Thank you

clevertools avatar Jun 29 '16 07:06 clevertools

If you call .fancybox(), it just adds click events that executes $.fancybox.open().

You coud unbind click events, if needed, but I suggest using something like $( "body" ).on( "click", "a", function() {}; where you would check for source and call $.fancybox.open();

fancyapps avatar Feb 27 '17 13:02 fancyapps