Search code examples
javascriptimagelightboxlightgallery

Add/edit an option in an already running instance of lightGallery


Is it possible to add/edit an option in an already running instance of the lightGallery script? I have this WordPress theme which loads an instance of lightGallery on galleries and I need to add/edit some of its options (for example: change the transition effect between images) without modifying the main theme files (on a child theme, for example).

This is the code found in the theme:

var container = $( '.gallery' );
var parseImage = container.data( 'images' );

if ( typeof $.fn.lightGallery != 'undefined' ) {
    container.lightGallery({
        dynamic : true,
        dynamicEl : parseImage
    });
}

Can this be done?

Thanks in advance


Solution

  • From their Pluging API page

        // You can access all lightgallery variables and functions like this.
        this.core = $(element).data('lightGallery');
    
        this.$el = $(element);
        this.core.s = $.extend({}, defaults, this.core.s)
    

    It appears that the s property of $(element).data('lightGallery') contains all the options. So you can set the mode there. Like this:

    $(element).data('lightGallery').s.mode = "lg-slide";
    

    I tested this in the console on their transitions demo page and it does indeed work.