Last active
June 6, 2020 21:07
-
-
Save DrYurets/d7ea4d70e66077e553a849c778828140 to your computer and use it in GitHub Desktop.
Advanced Gutenberg gallery with thumbnails & lightbox fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// file from wp-content/plugins/advanced-gutenberg/assets/js/ | |
jQuery(document).ready(function ($) { | |
$('.wp-block-gallery').each(function () { | |
// Add lightbox for images | |
$(this).find('.blocks-gallery-item').colorbox({ | |
title: function () { | |
if (parseInt(advgb.imageCaption)) { | |
var imgCap = $(this).find('figcaption').text() || $(this).find('img').attr('alt'); | |
return imgCap; | |
} | |
return null; | |
}, | |
maxWidth: '90%', | |
maxHeight: '85%', | |
fixed: true, | |
className: 'advgb_lightbox', | |
rel: 'gallery', | |
href: function () { | |
return $(this).find('a').attr('href'); // changeg lightbox target to anchor from image src | |
}, | |
onComplete: function () { | |
$('.cboxPhoto') | |
.attr('alt', $(this).find('img').attr('alt')) | |
.attr('title', $(this).find('img').attr('title')); | |
}, | |
onOpen: function() { | |
var ycoord = $(window).scrollTop(); | |
$('#colorbox').data('ycoord',ycoord); | |
ycoord = ycoord * -1; | |
//$('body').css('position','fixed').css('left','0px').css('right','0px').css('top',ycoord + 'px'); | |
}, | |
onClosed: function () { | |
$('body').css('position','').css('left','auto').css('right','auto').css('top','auto'); | |
$(window).scrollTop($('#colorbox').data('ycoord')); | |
} | |
}) | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment