views:

548

answers:

1

I'm using the Galleria plugin with jQuery to create my image gallery. I'm trying to get load images dynamically from the user's selection into the DOM and have the gallery auto-update to display those new images but it's not working.

Firebug shows the images are successfully loading into the DOM but Galleria displays no thumbnails. I need a way to reload Galleria to display the new images.

/* ---- Gallery Code ---- */
if ($(this).find('div').attr('title') == 'photogallery' && $('.galleria_container').length == 0)
{
   $('.gallery').galleria(
   {
      history   : false,
      clickNext : true,
      onImage   : function(image,caption,thumb) 
      { 
         if(! ($.browser.mozilla && navigator.appVersion.indexOf("Win")!=-1) ) 
         {
            image.css('display','none').fadeIn(1000);
         }

         var _li = thumb.parents('li');

         caption.css('display','none').fadeIn(1000);
         _li.siblings().children('img.selected').fadeTo(500,0.3);
         thumb.fadeTo('fast',1).addClass('selected');
         image.attr('title','Next image >>');
      },
      onThumb : function(thumb) 
      { 
        var _li = thumb.parents('li');
        var _fadeTo = _li.is('.active') ? '1' : '0.3';

        thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
        thumb.hover
        (
           function() { thumb.fadeTo('fast',1); },
           function() { _li.not('.active').children('img').fadeTo('fast',0.3); } // don't fade out if the parent is active
        )
     }
  });
}

/* ---- Gallery Selector ---- */
$(document).ready(function()
{
   var galleryImages = new Object();

   <?php
   echo $myGal;
   ?>

   function setImages(type)
   {
      var image = '';

      for (var i = 0; i < galleryImages[type].length; i++)
      {
         image += '<li><img src="' + galleryImages[type][i] + '"></li>';
      }

      $('ul.gallery').html(image);
   }

   $('ul.menu-horiz li ul li').click(function()
   {
      setImages($(this).attr('rel'));
   });
});

The PHP code you see just creates an array of images.

So to summarise my question: How can I reload Galleria once the new images have been loaded into the DOM?

A: 

You may want to look at using the LiveQuery plugin which binds the function to the element in such a way that it fires even when the DOM is changed.

Vincent Ramdhanie
I asked a similar question to this regarding pulling a different gallery with AJAX and having it fire then. Someone recommended the LiveQuery plugin. But the site I'm coding is set up to use an accordion so it's all dynamic content. Once Galleria has been initialized, that's it. No more page loads. So LiveQuery would have no effect in this matter, no? How could I use LiveQuery to (on a static page - index.php) reload the, already initialized, Galleria to include the new images? :/
panas