Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#5 | views_slideshow-opts-undefined-1707240-5.patch | 1.06 KB | wbobeirne |
views_slideshow-undefined_opts_drupal_settings.txt | 15.79 KB | rooby |
Comments
Comment #1
2phaI have the same problem.
Comment #2
jnettikI'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
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.
Comment #3
jnettikAlso just noticed that it's only when the "Start slideshow paused" option is checked.
Comment #4
rooby CreditAttribution: rooby commented@jnettik:
That sounds like a different issue, so probably best to make a new issue for it as it will have a different fix.
Comment #5
wbobeirne CreditAttribution: wbobeirne commentedI 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.
Comment #6
wbobeirne CreditAttribution: wbobeirne commentedComment #7
wangqizhong CreditAttribution: wangqizhong commentedThanks 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!