Commit 319fc289 authored by webchick's avatar webchick

#595972 by katbailey, sun, TwoD, quicksketch, merlinofchaos, and dmitrig01:...

#595972 by katbailey, sun, TwoD, quicksketch, merlinofchaos, and dmitrig01: Allow AJAX settings command to extend Drupal.settings.
parent f334620b
...@@ -767,8 +767,9 @@ function ajax_command_css($selector, $argument) { ...@@ -767,8 +767,9 @@ function ajax_command_css($selector, $argument) {
/** /**
* Creates a Drupal AJAX 'settings' command. * Creates a Drupal AJAX 'settings' command.
* *
* The 'settings' command instructs the client to extend Drupal.settings with * The 'settings' command instructs the client either to use the given array as
* the given array. * 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() * This command is implemented by Drupal.ajax.prototype.commands.settings()
* defined in misc/ajax.js. * defined in misc/ajax.js.
...@@ -777,14 +778,20 @@ function ajax_command_css($selector, $argument) { ...@@ -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 * 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 * for all commands after this if they do not include their own settings
* array. * 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 * @return
* An array suitable for use with the ajax_render() function. * An array suitable for use with the ajax_render() function.
*/ */
function ajax_command_settings($argument) { function ajax_command_settings($argument, $merge = FALSE) {
return array( return array(
'command' => 'settings', 'command' => 'settings',
'settings' => $argument, 'settings' => $argument,
'merge' => $merge,
); );
} }
......
...@@ -406,7 +406,12 @@ Drupal.ajax.prototype.commands = { ...@@ -406,7 +406,12 @@ Drupal.ajax.prototype.commands = {
* Command to set the settings that will be used for other commands in this response. * Command to set the settings that will be used for other commands in this response.
*/ */
settings: function (ajax, response, status) { settings: function (ajax, response, status) {
ajax.settings = response.settings; if (response.merge) {
$.extend(true, Drupal.settings, response.settings);
}
else {
ajax.settings = response.settings;
}
}, },
/** /**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment