I have a series of images displayed in a carousel. I am using the ajax setting and have 'Items to display' set to 3. It's important that I have the Views 'Use AJAX' setting on - in some cases there are over 20 images to display which can cause page load times to slow with AJAX turned off.
I am using the Colorbox library and module alongside jCarousel to display a larger version of each image when clicked. Here's where I run into problems. The first three images (which are present in the DOM on the first page load) correctly trigger the Colorbox plugin when they're clicked. However, after using jCarousel's navigation buttons (previous / next), Colorbox is not triggered - this is because Colorbox has not been initialised for the new images in the DOM. I can tell this is the case because the usual colorbox classes are not added to the AJAX images.
I am not sure how to go about adding this initialisation code, in effect 'refreshing' the active Colorbox elements on the page. Is there perhaps a callback I can use to add the necessary javascript on each AJAX call?
Any help greatly appreciated, thanks for making this module available.
Comment | File | Size | Author |
---|---|---|---|
#3 | jcarousel_behaviors.patch | 583 bytes | quicksketch |
Comments
Comment #1
wuh CreditAttribution: wuh commentedI have found a simple solution to the problem, adding
Drupal.attachBehaviors();
inside theDrupal.jcarousel.ajaxResponseCallback
in jcarousel.js. This could benefit other modules too - might it be considered for commit?Comment #2
quicksketchThanks for the suggestion. You're correct that we should be calling Drupal.attachBehaviors() to the newly added items loaded via AJAX. We should only call Drupal.attachBehaviors() on the new part of the page though, calling it without any arguments makes it so that the entire page is checked for behaviors, which is unnecessary.
Comment #3
quicksketchI've fixed this with the attached patch, the same as yours but selectively affecting only the new part of the page.