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.
Problem/Motivation
If colorbox is not enabled/defined, we get this error Uncaught TypeError: Cannot read property 'mobiledetect' of undefined in blazy.colorbox.js.
Proposed resolution
Similar to this colorbox issue fix, we need to add a "is not undefined" check.
Comment | File | Size | Author |
---|---|---|---|
#15 | 3123435-mobiledetect-undefined-15-interdiff.txt | 417 bytes | sasanikolic |
#15 | 3123435-mobiledetect-undefined-15.patch | 558 bytes | sasanikolic |
| |||
#2 | 3123435-mobiledetect-undefined.patch | 587 bytes | sasanikolic |
|
Comments
Comment #2
sasanikolic CreditAttribution: sasanikolic at MD Systems GmbH commentedHere is the patch with the proposed fix.
Comment #3
gausarts CreditAttribution: gausarts commentedThank you.
Care to detail reproduction?
Comment #4
BerdirI think this happens if you add the colorbox/blazy library to the page but you don't have anything using colorbox. Might be enough to just do drupalSettings.colorbox && drupalSettings.colorbox.mobiledetect in the existing condition, not sure what else is below it?
Comment #5
gausarts CreditAttribution: gausarts commentedThank you.
Makes sense for a feature with custom works.
Comment #6
sasanikolic CreditAttribution: sasanikolic at MD Systems GmbH commented@Berdir, that check wouldn't work because that only checks for mobiles in order to disable it in that case, and after that check we call blazyColorbox which initializes the colorbox. IMHO we need a separate check to return even before that.
Comment #7
BerdirI think the questions have been answerd, back to needs review?
Comment #8
gausarts CreditAttribution: gausarts commentedThe two conditions seem required. One cannot pass through I think. Although in reality they are of course made present by colorbox module, but expects one simply put and called the library manually while the colorbox module is not even enabled like the OP scenario.
Some themes sometimes create their own libraries like Zircon for Slick.
Does it pass the original scenario?
I don't have it handy so I love to hear from you.
Comment #9
BerdirI'm not sure what you mean with "original scenario"?
Comment #10
gausarts CreditAttribution: gausarts commentedSorry, I meant the OP one. Colorbox being uninstalled.
I should have said both scenarios but didn't correct it due to being away for a routine thinking enough after I mentioned another scenario with a theme like Zircon as a good example.
I hope that clarifies.
Comment #11
Berdir@sasanikolic didn't mean that the module isn't installed, there is only one use case here, we're working on the same project :)
blazy/colorbox depends on blazy/colorbox.skin which depends on colorbox/colorbox, so it's not possible to include this library without having colorbox enabled and I suspect the .colorbox function check might not be necessary, just that the settings are empty? But being extra careful should also not hurt?
Comment #12
gausarts CreditAttribution: gausarts commentedYou are right. I missed the skin part.
When I first read this issue, I was thinking to propose solving it at PHP level. This reminds me of drupal_get_path. Many including me used to call it without a check with module_exists, then suddenly core changed it, and we have warnings. What I meant, why not check it before loading it? But I thought, your idea is less hustle.
It won't hurt :)
I already agreed for a feature. I just needed your opinions about scenarios, and missed the skin part. Thanks for showing me the light.
Comment #13
gausarts CreditAttribution: gausarts commentedWe can remove the first check which is useless as @Berdir said. It is blazy skin dependency.
The error is also not complaining about the first, just the second.
Again, as I don't have it handy, I would leave it to your best decision.
Comment #14
gausarts CreditAttribution: gausarts commentedWould like to include this in the new release. Unfortunately no bandwidth to verify.
Are you still working on this?
Comment #15
sasanikolic CreditAttribution: sasanikolic at MD Systems GmbH commented@gfausarts Sorry for the late reply. I did remove the function change now.
Comment #17
gausarts CreditAttribution: gausarts commentedGot it. Thank you for contribution.