Search code examples
javascriptjquerymultiple-instancesgallerianyromodal

Galleria jquery plugin - removing instances


I have a page where i have several links that when clicked, load a gallery of images into Galleria within a Nyromodal lightbox. When the lightbox is closed, i use $("#container").html('') to clear the contents of the lightbox including Galleria.

// open modal
$.nmManual("#container",{
    callbacks: {
        // loads Galleria after lightbox has finished opening
        afterReposition: function(nm) {
            $("#container #gallery").galleria({
                width:800,height:600
            });
        },
        // clear container with Galleria before closing the Modal
        beforeClose: function(nm) {
            $("#container").html('');
        }
    }
})

The next link i open properly opens a Nyromodal lightbox, properly populates Galleria with a new set of images, but using another instance of Galleria. I would like to delete any old instances of Galleria. How do i do this? I don't see anything in the docs that allow me to remove instances manually.

I know that i have created multiple instances of Galleria by using Galleria.get(). This really doesn't have much to do with Nyromodal, but some context is always good :)

same issue here: http://getsatisfaction.com/galleria/topics/allow_ability_to_remove_galleria_instances (code does not work for current version)

Thanks!


Solution

  • You can simply reuse existing instance of galleria, something like this

    var gal;
    
    if (!gal) {                 // not created yet
        $('#galleria2').galleria({
            dataSource: [],
            lightbox: true,
            some other options....
        });
        gal = $('#galleria2').data('galleria');
    }
    gal.load(images);