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.
Comment | File | Size | Author |
---|---|---|---|
#15 | drupal_dehavior_settings_docs.patch | 642 bytes | quicksketch |
#14 | drupal_behavior_settings.patch | 22.99 KB | quicksketch |
#10 | drupal_dehavior_settings_10.patch | 23.47 KB | mfer |
#6 | drupal_behavior_settings.patch | 23.55 KB | quicksketch |
#3 | drupal_behavior_settings.patch | 23.61 KB | quicksketch |
Comments
Comment #1
dmitrig01 CreditAttribution: dmitrig01 commentedYour local .project file got in there somehow
Comment #3
quicksketchHrm. Same patch, no ".project" file this time.
Comment #4
starbow CreditAttribution: starbow commentedsubscribing
Comment #6
quicksketchReroll for fuzz.
Comment #8
Wim LeersSubscribing!
Comment #9
sunComment #10
mfer CreditAttribution: mfer commentedComment #11
mfer CreditAttribution: mfer commentedThe patch looks good. Manually tested across the JS and it works.
The patch in #10 just accounts for a moving head.
Comment #12
starbow CreditAttribution: starbow commentedThis is a smart change to make.
Comment #13
katbailey CreditAttribution: katbailey commentedThis 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.
Comment #14
quicksketchSomehow my PHPdoc got dropped from #11. Same patch with docs.
Comment #15
quicksketchI'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.
Comment #16
sunSorry, but wrong indentation here:
I do not want to change the status because of this. Injecting 2 spaces shouldn't be too much for any core maintainer. ;)
Comment #17
webchickI 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. :)
Comment #18
mfer CreditAttribution: mfer commentedAdded documentation