• Resolved James Revillini

    (@jrevillini)


    I love this plugin and hope to assist with its development!

    my site doesn’t use jQuery. your plugin assumes it is available and generates inline script even if “v2.7.0” is the lightGallery version chosen, so i get the error that jQuery is not defined. so I am going to give you the code it generated inline as vanilla JS. let me know if you want help rewriting anything else to vanilla JS, which should work better regardless of the version used:

    document.addEventListener("DOMContentLoaded", function() {
        // Select all divs with an ID starting with "gallery-"
        document.querySelectorAll('div[id^="gallery-"]').forEach(function(gallery) {
            // For each gallery item within this gallery div
            gallery.querySelectorAll('.gallery-item').forEach(function(item) {
                // Retrieve the text inside the figcaption element
                const caption = item.querySelector('figcaption').textContent;
                // Add the data-sub-html attribute to the corresponding <a> element
                const link = item.querySelector('a');
                if (link) {
                    link.setAttribute('data-sub-html', caption);
                }
            });
    
            // Get the ID of the current div
            const id = gallery.id;
            // Use a regular expression to extract the number from the ID
            const number = id.match(/\d+/)[0];
            // Do something with each selected div
            lightGallery(gallery, {
                plugins: [lgFullscreen, lgMediumZoom, lgVideo, lgZoom],
                selector: 'a',
                galleryId: number,
            });
        });
    });
Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.