I'm trying to initialize the FitVids plugin on Fancybox modal content once that content is loaded. It works perfectly if I use the onUpdate callback for when the user resizes the viewport, but if I try to get it working with afterShow to apply it once the content is shown, I get nothing. I've tested to ensure that afterShow works by throwing in console.log('whatever') and that was successful.
This is the code I'm using:
$('.tile-link.fancybox').click(function() {
var url = $(this).data('url');
var getContent = $('.tile-lightbox-content').load(url + ' #lightboxBucketContent');
$('.tile-lightbox-content').empty();
$.fancybox({
content: getContent,
width: '90%',
height: '90%',
type: 'html',
scrolling: 'no',
modal: false,
padding: 20,
enableEscapeButton: true,
titleShow: true,
autoSize: false,
autoResize: true,
autoDimensions: false,
aspectRatio: true,
helpers: {
media: true
},
// afterShow doesn't work
afterShow: function() {
$('.fancybox-inner').fitVids({
customSelector: 'iframe[src^="http://somewebsite.com"]'
});
},
// onUpdate works correctly
onUpdate: function() {
$('.fancybox-inner').fitVids({
customSelector: 'iframe[src^="http://somewebsite.com"]'
});
}
});
});
I'm using this on a WordPress website where content is loaded into some masonry tiles that trigger a fancybox modal window when clicked and load a portion of a page via the jQuery load function. Everything works dandy with the exception of the FitVids. The tile modal content often contains iframe video embeds and I need them to cooperate on touch/mobile devices.
Thanks in advance.
hrefof the fancybox URL is directly to the media item itself. With my situation, the modal boxes contain text content that the user writes in the WYSIWYG of a WordPress post and an embedded (iframe) video that is pulled from a third party source that is not one of the mainstream providers listed under the media helper. My client uses a CDN for presenting media and other things to potential clients and publicly. - htmlbotinline, try initializing FitVids as a callback of the.load()` method and I guess that would work for what you are trying to do withafterShow- JFK