Hi,
I created a view to display a list of search results. (exposed form.) This is working fine.
We have a custom template for the node. It includes thumbnails (imagecache). Lightbox automatically turns them into links for the lightbox modal window. This is working fine.
Next, we set the header of the view (basic settings) to include some javascript. This overrides the links with jquery ajax loads. This works fine.
THE AJAX JUST REPLACES THE INNER DIV OF THE PAGE WITH THE INNER DIV OF THE FETCHED PAGE.
Now, when content is loaded via AJAX, the lightbox functionality doesn't work. A view of the source shows that the links all have the rel="lightbox[field_picture][]" set, but still the lightbox doesn't work.
I've tried a few things from older posts such as using jquery to load lightbox.js or Drupal.behaviors.initLightbox. Neither seems to help.
Here is the javascript we're using in the view:
$(document).ready(function(){ $(".field-content a").click(function(e) { e.preventDefault(); var my_url = $(this).attr('href') + ' #content > .inner'; $("#content > .inner").load(my_url); }); });
Comments
Comment #1
noah977 commentedAnybody?
Comment #2
noah977 commentedReally? Nobody?
Comment #3
onelittleant commentedMaybe too late for you...
The problem is that lightbox functionality is attached to links on the page on page load via the Drupal.attachBehaviors() javascript function. When you load content via ajax, this is not called again, so the links in your ajax content don't get lightbox attached to them. After you load content via ajax you simply need to call Drupal.attachBehaviors() in javascript. See more about attachBehaviors() here:
http://api.drupal.org/api/drupal/developer--topics--javascript_startup_g...
Comment #4
tyler.frankenstein commentedjQuery live() may also be worth checking out in this instance.