If the Juicebox gallery-specific javascript is added to a page that somehow does not contain the accompanying gallery embed code, the Juicebox javascript library displays a very intrusive error. Significant work has been done to prevent these cases (#2217791: Prevent javascript from being added in contexts were embed code may not be displayed (e.g. "Cannot find div with id" error on search results) and others) and now the module is very good at ensuring that the embed code and javascript are added simultaneously (via a single Drupal render array with #attached attribute).

The error cases that remain are ones where a gallery is fully rendered (Drupal is committed to placing it on the page) but something conditionally removes the rendered markup very late in the page building process. This is quite rare and probably only occurs in some edge-case situations, but I have a feeling that it could become a re-occurring issue case.

As of 7.x-2.1 we now trigger the gallery-specific JS via Drupal behaviors, which means that we have an additional layer of Drupal-specific JS control that happens after the page is built. I propose adding a conditional check to the behavior that verifies if the gallery embed div is actually on the page before triggering the JS. This could likely avoid the intrusive "cannot find div with id" error for all situations once and for all.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rjacobs created an issue. See original summary.

rjacobs’s picture

rjacobs’s picture

Status: Active » Needs review
FileSize
658 bytes

Here's a patch that adds the described check to the behavior.

arebacollins’s picture

FileSize
1 MB

Thanks!

Patch applied, doesn't seem to address the issue of missing divs. Both the main gallery (http://www.infonet-biovision.org/content/african-nightshade) and the pestmodule galleries (which I have now enabled juicebox to show the issue) still have a blank juicebox div where no image is passed from the view.

Incidentally, since Im calling the juicebox view from inside a view by passing the [nid] in the referencing view, if I disable the contextual filter it doesnt show anything Juicebox related, but the moment I pass [nid] I get this issue. I have attached some mish mash of the views as I have them rendering the output seen.

Regards.

rjacobs’s picture

Just to clarify, this patch/issue only addresses the specific "Cannot find div with ID" error message that may appear when a gallery's embed code is removed from the page in a non-standard way. It's not totally clear to me how your setup is triggering that error, but I figured it would be best to explore a generic solution to that kind of problem. If you configure things the same way that previously triggered those "Cannot find div with ID" errors, does this patch make them go away?

When it comes to the issue of the "blank juicebox divs" I still think you may need to add a filter to one of your views, which is something I posted a note about in #2577565-13: Unused , hidden Juicebox view generates an error . We can probably continue that discussion over in that other issue. Can you also post that image (from comment #4) in that other issue (#2577565)?

  • rjacobs committed 4029937 on 8.x-2.x
    Issue #2581285 by rjacobs: Use JS in Drupal behavior to confirm that...
rjacobs’s picture

I went ahead and committed this change in 8.x-2.x as it does provide some advantages and shouldn't hurt anything.

  • rjacobs committed 216fa62 on 7.x-2.x
    Issue #2581285 by rjacobs: Use JS in Drupal behavior to confirm that...
rjacobs’s picture

Status: Needs review » Fixed

Now also committed on 7.x-2.x.

Status: Fixed » Closed (fixed)

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