summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAngie Byron2010-01-12 06:31:22 (GMT)
committerAngie Byron2010-01-12 06:31:22 (GMT)
commit319fc2895c5fdfad8fb11bb6c09dd8f1d15e042b (patch)
tree257640b701d6d33f6246beab1fc95b42a6288748
parentf334620be52804b85081a8b3f33a3d02155f89ee (diff)
#595972 by katbailey, sun, TwoD, quicksketch, merlinofchaos, and dmitrig01: Allow AJAX settings command to extend Drupal.settings.
-rw-r--r--includes/ajax.inc13
-rw-r--r--misc/ajax.js7
2 files changed, 16 insertions, 4 deletions
diff --git a/includes/ajax.inc b/includes/ajax.inc
index 93d9e8b..ed5db17 100644
--- a/includes/ajax.inc
+++ b/includes/ajax.inc
@@ -767,8 +767,9 @@ function ajax_command_css($selector, $argument) {
/**
* Creates a Drupal AJAX 'settings' command.
*
- * The 'settings' command instructs the client to extend Drupal.settings with
- * the given array.
+ * The 'settings' command instructs the client either to use the given array as
+ * the settings for ajax-loaded content or to extend Drupal.settings with the
+ * given array, depending on the value of the $merge parameter.
*
* This command is implemented by Drupal.ajax.prototype.commands.settings()
* defined in misc/ajax.js.
@@ -777,14 +778,20 @@ function ajax_command_css($selector, $argument) {
* An array of key/value pairs to add to the settings. This will be utilized
* for all commands after this if they do not include their own settings
* array.
+ * @param $merge
+ * Whether or not the passed settings in $argument should be merged into the
+ * global Drupal.settings on the page. By default (FALSE), the settings that
+ * are passed to Drupal.attachBehaviors will not include the global
+ * Drupal.settings.
*
* @return
* An array suitable for use with the ajax_render() function.
*/
-function ajax_command_settings($argument) {
+function ajax_command_settings($argument, $merge = FALSE) {
return array(
'command' => 'settings',
'settings' => $argument,
+ 'merge' => $merge,
);
}
diff --git a/misc/ajax.js b/misc/ajax.js
index d61af3e..1ded01c 100644
--- a/misc/ajax.js
+++ b/misc/ajax.js
@@ -406,7 +406,12 @@ Drupal.ajax.prototype.commands = {
* Command to set the settings that will be used for other commands in this response.
*/
settings: function (ajax, response, status) {
- ajax.settings = response.settings;
+ if (response.merge) {
+ $.extend(true, Drupal.settings, response.settings);
+ }
+ else {
+ ajax.settings = response.settings;
+ }
},
/**