In working with JavaScript in Drupal, we've run into several problems with dynamically loaded data. This patch is meant to solve exactly one of those problems. Currently when we load content via AJAX or AHAH, we only get the needed HTML. We don't get any JS or CSS that is required by the new content, we have to assume that it's already there on the original page.

This patch addresses a subset of that problem. When we attempt to attach behaviors to the that new content, often times it depends on values in the Drupal.variables array (such as when using teaser.js, ahah.js, or tabledrag.js). The problem is that all these scripts call the Drupal.settings array directly. So other than editing this global JavaScript variable, there isn't a way to make these scripts work. So instead we should switch these variables to local ones, so we can pass in any values we like.

Of course this patch doesn't do much on it's own, but future enhancements (after #251578: More flexible js/css ordering and an alter operation and subpatches are finished) should allow us to send back not just HTML on AHAH requests, but also JS, CSS, and Drupal.settings back to the calling page to be loaded dynamically.

This patch would be a pre-requisite to clean Popups functionality, we have a workaround in the Popups API project (see #336641: Auto-load needed JS and CSS files (and settings)), but this would make it so that we could effectively apply behaviors that depend on the Drupal.settings variables.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dmitrig01’s picture

Your local .project file got in there somehow

Status: Needs review » Needs work

The last submitted patch failed testing.

quicksketch’s picture

Status: Needs work » Needs review
FileSize
23.61 KB

Hrm. Same patch, no ".project" file this time.

starbow’s picture

subscribing

Status: Needs review » Needs work

The last submitted patch failed testing.

quicksketch’s picture

Status: Needs work » Needs review
FileSize
23.55 KB

Reroll for fuzz.

Status: Needs review » Needs work

The last submitted patch failed testing.

Wim Leers’s picture

Subscribing!

sun’s picture

Issue tags: +JavaScript
mfer’s picture

mfer’s picture

Status: Needs work » Reviewed & tested by the community

The patch looks good. Manually tested across the JS and it works.

The patch in #10 just accounts for a moving head.

starbow’s picture

This is a smart change to make.

katbailey’s picture

This is awesome. I just tested it out properly with Quick Tabs and was able to make an ajax-loaded QT react to settings that didn't exist on the original page - it would be great to see this get in.

quicksketch’s picture

Somehow my PHPdoc got dropped from #11. Same patch with docs.

quicksketch’s picture

I'm positive #14 and #10 are identical, though I'm sure why the filesize got smaller rather than bigger. If preferred, you can use this patch in conjunction with #10 to add the docs.

sun’s picture

Sorry, but wrong indentation here:

+ * @param settings
+ *  An object containing settings for the current context. If none given, the
+ *  global Drupal.settings object is used.

I do not want to change the status because of this. Injecting 2 spaces shouldn't be too much for any core maintainer. ;)

webchick’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs documentation

I looked this over at the ice cream sprint and the only issue I found was the PHPDoc. That's now fixed, so I committed this to HEAD. Thanks!

Please document. :)

mfer’s picture

Status: Needs work » Fixed
Issue tags: -Needs documentation

Added documentation

Status: Fixed » Closed (fixed)

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