Because of the way the Juicebox library renders most of the gallery markup on the client-side (as opposed to just decorating existing markup) I've been assuming that it's safest to add its gallery-specific js inline. The way things have been implemented has still proven pretty robust, and even AJAX friendly (after fixing #2367809: Juicebox dissapears if loaded/updated via AJAX), but it still feels a little clunky. Furthermore, the more I work with D8 the more I see that the current way of doing things may not port in a very performant way, so it may be good to re-visit options with Drupal.behaviors and Drupal.settings.

After a bit of testing I'm seeing that the requirements of the library should be compatible with Drupal.behaviors and Drupal.settings. Even though using them may add some layers of complication relative to simple inline inclusions, it may prove more compatible with more complex AJAX needs and will allow for all Juicebox js to be better deferred for performance (especially in D8).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rjacobs’s picture

Hummm, so some initial testing reveals that pushing the gallery-specific settings to the browser with Drupal.settings and then triggering the actual gallery (new juicebox()) with Drupal.behaviors actually fixes #2401327: Galleries built via AJAX may not render correctly with older jQuery. I guess that older jQuery versions don't execute inline JS added via AJAX correctly so bypassing the inline js altogether makes that problem go away.

So a switch to Drupal.behaviors and Drupal.settings would defiantly be the way to go.

rjacobs’s picture

Status: Active » Needs review
FileSize
16.37 KB

Here's a patch. After figuring out the general concept the implementation was actually pretty easy. The real pain was just getting all the tests adjusted.

  • rjacobs committed 60512dd on 7.x-2.x
    Issue #2448159 by rjacobs: Use Drupal JS behaviors and settings instead...
rjacobs’s picture

Version: 7.x-2.x-dev » 8.x-2.x-dev
Status: Needs review » Active

Committed for 7.x-2.x. Now this needs a port to 8.x-2.x.

rjacobs’s picture

Status: Active » Needs review
FileSize
17.76 KB

Here's a first crack at a port.

rjacobs’s picture

FileSize
17.76 KB

Another one.

  • rjacobs committed e4d8d0e on 8.x-2.x
    Issue #2448159 by rjacobs: Use Drupal JS behaviors and settings instead...

The last submitted patch, 5: juicebox-use_drupal_behaviors-2448159-5.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 6: juicebox-use_drupal_behaviors-2448159-6.patch, failed testing.

rjacobs’s picture

Status: Needs work » Fixed

The D8 patches submitted above passed tests fine against core 8.0.0-beta7, but some incompatibilities were introduced between that release and the most recent HEAD. Anyway, those incompatibilities were addressed in the commit (#7), so this can be closed.

Status: Fixed » Closed (fixed)

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

rjacobs’s picture

Adding a relationship for tracking purposes. This connects to #2355253: JS handeling in D8 core is constantly changing as that is sort-of a high-level overview of what's changing with the JS lib handling for the 8.x version.