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).
Comment | File | Size | Author |
---|---|---|---|
#2 | juicebox-use_drupal_behaviors_and_settings-2448159-2.patch | 16.37 KB | rjacobs |
Comments
Comment #1
rjacobs CreditAttribution: rjacobs commentedHummm, 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.
Comment #2
rjacobs CreditAttribution: rjacobs commentedHere'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.
Comment #4
rjacobs CreditAttribution: rjacobs commentedCommitted for 7.x-2.x. Now this needs a port to 8.x-2.x.
Comment #5
rjacobs CreditAttribution: rjacobs commentedHere's a first crack at a port.
Comment #6
rjacobs CreditAttribution: rjacobs commentedAnother one.
Comment #10
rjacobs CreditAttribution: rjacobs commentedThe 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.
Comment #12
rjacobs CreditAttribution: rjacobs commentedAdding 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.