Hi, I ran into a problem with the jCarousel plugin. I have a carousel with 10 images in it. When my screen resolution or browser zoom are set such that there is room for more than 10 elements, rather than repeating the elements, jCarousel puts a bunch of placeholder in that never get replaced. Scrolling the carousel works fine. I have mine set to autoscroll, and after 3 seconds everything moves left and the next one on the end shows an image.

This appears to me to be a bug in the jCarousel plugin. At one point when initializing the carousel, the code loops through all the available slide positions based on the dimensions of the screen. For each slide position, It tries to load the slide from the HTML. If it doesn't find one, it creates a placeholder.

Then the following code runs:

if (this.first !== null && this.options.wrap == 'circular' && this.options.size !== null && (j <= 0 || j > this.options.size)) {
  g = this.get(this.index(j));
  if (g.length) {
    e = this.add(j, g.clone(true));
  }
}

This is supposed to go grab the appropriate slide to put in place of that placeholder based on that this.first property, which holds the index/ID of the first element in the carousel.

The problem is that this.first hasn't been initialized yet. After everything gets loaded and setup, this.first gets set to 1 further down the line, but at the time of this initial run through, it is null. So this entire if statement evaluates to false, and nothing happens.

I have a patch (attached) that fixes the problem in my environment by setting this.first to the value of this.options.start if this.first hasn't been initialized yet.. This is relevant to version 6.x-2.6 of the module and 0.2.8 of the jCarousel plugin. I realize that the jCarousel plugin is a bit old, but a) the 0.2.9 release doesn't seem to fix the problem and b) 0.3.0 is a complete re-write and I didn't want to get into dealing with all that.

Please review this patch and let me know if maybe there is a better approach.

PS Sorry if this is a duplicate. I found some others that sounded similar to mine, but none that hit the nail on the head, and they were for 7.x. I find it very odd that this problem hasn't been more widely encountered on the web. I don't know if I'm doing something wrong, but I've changed just about every view setting I can think of, and none of them fixed the problem.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mlewis_duoconsulting created an issue. See original summary.

Mike Lewis’s picture