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.

Files: 
CommentFileSizeAuthor
#15 drupal_dehavior_settings_docs.patch642 bytesquicksketch
Passed: 10551 passes, 0 fails, 0 exceptions
[ View ]
#14 drupal_behavior_settings.patch22.99 KBquicksketch
Passed: 10551 passes, 0 fails, 0 exceptions
[ View ]
#10 drupal_dehavior_settings_10.patch23.47 KBmfer
Passed: 10551 passes, 0 fails, 0 exceptions
[ View ]
#6 drupal_behavior_settings.patch23.55 KBquicksketch
Failed: Failed to apply patch.
[ View ]
#3 drupal_behavior_settings.patch23.61 KBquicksketch
Failed: Failed to apply patch.
[ View ]
drupal_behavior_settings.patch24.53 KBquicksketch
Failed: Invalid PHP syntax.
[ View ]

Comments

Your local .project file got in there somehow

Status:Needs review» Needs work

The last submitted patch failed testing.

Status:Needs work» Needs review
StatusFileSize
new23.61 KB
Failed: Failed to apply patch.
[ View ]

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

subscribing

Status:Needs review» Needs work

The last submitted patch failed testing.

Status:Needs work» Needs review
StatusFileSize
new23.55 KB
Failed: Failed to apply patch.
[ View ]

Reroll for fuzz.

Status:Needs review» Needs work

The last submitted patch failed testing.

Subscribing!

Issue tags:+JavaScript

StatusFileSize
new23.47 KB
Passed: 10551 passes, 0 fails, 0 exceptions
[ View ]

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.

This is a smart change to make.

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.

StatusFileSize
new22.99 KB
Passed: 10551 passes, 0 fails, 0 exceptions
[ View ]

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

StatusFileSize
new642 bytes
Passed: 10551 passes, 0 fails, 0 exceptions
[ View ]

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.

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. ;)

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. :)

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

Added documentation

Status:Fixed» Closed (fixed)

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