0

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

leemon
  • 917
  • 4
  • 19
  • 47
  • Have you looked at the documentation for "lightGallery"? – gforce301 Jan 19 '20 at 08:51
  • Yes, I see you can destroy the instance with the destroy() method and reinitialize it with new parameters, but I wanted to know if there's a way to do this without having to destroy the instance first. – leemon Jan 19 '20 at 09:05

1 Answers1

1

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.

gforce301
  • 2,944
  • 1
  • 19
  • 24