(function($) {
function logAndApplyFancyStuff() {
console.log('Running fancy stuff…');
const links = $('.fancybox-link');
console.log('Found', links.length, 'fancybox-link(s)');
links.each(function(index) {
const uniqueValue = 'fancybox-' + index;
console.log('Setting data-src:', uniqueValue, 'on:', this);
$(this).attr('data-src', uniqueValue);
const container = $(this).find('.fancybox-container');
if (container.length) {
console.log('Adding class', uniqueValue, 'to child container:', container.get(0));
container.addClass(uniqueValue);
} else {
console.warn('No child .fancybox-container found in:', this);
}
});
}
// Run on initial load
$(document).ready(function () {
logAndApplyFancyStuff();
});
// Run every time JetEngine renders the listing grid
$(document).on('jet-engine/listing-grid/rendered', function(event, $scope) {
console.log('jet-engine/listing-grid/rendered triggered');
logAndApplyFancyStuff();
});
})(jQuery);