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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sasanikolic created an issue. See original summary.

sasanikolic’s picture

Status: Active » Needs review
FileSize
587 bytes

Here is the patch with the proposed fix.

gausarts’s picture

Category: Bug report » Support request
Status: Needs review » Postponed (maintainer needs more info)

Thank you.

Care to detail reproduction?

Berdir’s picture

I 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?

gausarts’s picture

Category: Support request » Feature request

Thank you.

Makes sense for a feature with custom works.

sasanikolic’s picture

@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.

Berdir’s picture

Status: Postponed (maintainer needs more info) » Needs review

I think the questions have been answerd, back to needs review?

gausarts’s picture

Status: Needs review » Postponed (maintainer needs more info)

The 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.

Berdir’s picture

I'm not sure what you mean with "original scenario"?

gausarts’s picture

Sorry, 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.

Berdir’s picture

Status: Postponed (maintainer needs more info) » Needs review

@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?

gausarts’s picture

You 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.

gausarts’s picture

Status: Needs review » Needs work

We 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.

gausarts’s picture

Would like to include this in the new release. Unfortunately no bandwidth to verify.

Are you still working on this?

sasanikolic’s picture

@gfausarts Sorry for the late reply. I did remove the function change now.

  • gausarts committed b0613db on 8.x-2.x authored by sasanikolic
    Issue #3123435 by sasanikolic, Berdir: Uncaught TypeError: Cannot read...
gausarts’s picture

Assigned: sasanikolic » Unassigned
Status: Needs review » Fixed

Got it. Thank you for contribution.

Status: Fixed » Closed (fixed)

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