I have a slideshow view that is sometimes throwing the error: opts is undefined

It is coming from jquery.cycle.all.js, from the function:

function triggerPause(cont, byHover, onPager) {
  var opts = $(cont).data('cycle.opts');
  var paused = !!cont.cyclePause;
  if (paused && opts.paused) // This is the line where opts is undefined.
    opts.paused(cont, opts, byHover, onPager);
  else if (!paused && opts.resumed)
    opts.resumed(cont, opts, byHover, onPager);
}

It seems to happen if the slideshow only has 1 item, but as soon as there are more items the error goes away.

I have attached a file with Drupal.settings objects for both working and non-working examples.

Comments

I have the same problem.

Priority:Normal» Major

I'm not sure if this is the same issue but it seems related. I get the same issue when there is only one slide in my slider but my error is

[cycle] terminating; too few slides: 1 - jquery.cycle.all.js:28
Uncaught TypeError: Cannot read property 'paused' of undefined - jquery.cycle.all.js:105

And for me any other javascript I have seems to be breaking. But on pages with a similar slider and more slides then everything works fine.

Also just noticed that it's only when the "Start slideshow paused" option is checked.

@jnettik:
That sounds like a different issue, so probably best to make a new issue for it as it will have a different fix.

Status:Needs review» Active
StatusFileSize
new1.06 KB

I put in a pull request to cycle to fix this issue, as I think it's the triggerPause's job to check if opts isn't set. You can find that over here: https://github.com/malsup/cycle/pull/128

But in the mean time, I just wrapped views_slideshow_cycle's pause function in a try/catch for TypeErrors. I don't do a ton of JS, so if my code is weird, please feel free to improve it. Attached is the patch.

@jnettik: That is the same issue, either of these will fix it.

Status:Active» Needs review

Status:Active» Fixed

Thanks a lot to rooby, wbobeirne and everyone else for the great work on the patches, testing, reviews and reporting.

It's more time this got committed and I went ahead and had this rolled at:
7.x-3.x: be2bdec
Marking this as fixed.

Please let me know if you would have any other questions, comments, issues or concerns on any of these changes, I would be glad to provide more information.
Thanks again to everyone for the help and great work on this issue.
Cheers!

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.