diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 4fe0531abaa1521ddb4df7a91fedf08603cb5b55..6d842d0ba05a68122e72025dfe8ee25d58d483e8 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -6,6 +6,7 @@ ctools 6.x-1.0-dev #457376: Text fields need array defaults. This only broke in pgsql. Add a hook to allow other modules to cooperate a bit more easily with node page overriding. #472222: Prevent modules providing invalid user data from causing warnings in profile content. +#478438 by nickl: Allow passing items to the data() element. ctools 6.x-1.0-beta3 ================== diff --git a/includes/ajax.inc b/includes/ajax.inc index 4f8a4238f7a83d1b84ec93e79035cdca53998976..d3a9e2dae4af3ddd896620416726b7b85e97c8b9 100644 --- a/includes/ajax.inc +++ b/includes/ajax.inc @@ -58,6 +58,11 @@ * - settings * - argument: An array of settings to add to Drupal.settings via $.extend * + * - data + * - selector: The CSS selector. This can be any selector jquery uses in $(). + * - name: The name or key of the data attached to this selector. + * - value: The value of the data. Not just limited to strings can be any format. + * * Commands are usually created with a couple of helper functions, so they * look like this: * @@ -294,6 +299,28 @@ function ctools_ajax_command_settings($argument) { ); } +/** + * Create a data command for the AJAX responder. + * + * This will attach the name=value pair of data to the selector via + * jquery's data cache. + * + * @param $selector + * The CSS selector. This can be any selector jquery uses in $(). + * @param $name + * The name or key: of the data attached to this selector. + * @param $value + * The value of the data. Not just limited to strings can be any format. + */ +function ctools_ajax_command_data($selector, $name, $value) { + return array( + 'command' => 'data', + 'selector' => $selector, + 'name' => $name, + 'value' => $value, + ); +} + /** * Force a table to be restriped. * diff --git a/js/ajax-responder.js b/js/ajax-responder.js index 5dfa9b2fab585a40190654145b597dfbd832aaa9..3e2084e1de2ee6d7a3838bfcd3829cb459f80953 100644 --- a/js/ajax-responder.js +++ b/js/ajax-responder.js @@ -210,6 +210,10 @@ Drupal.CTools.AJAX.commands = { $.extend(Drupal.settings, data.argument); }, + data: function(data) { + $(data.selector).data(data.name, data.value); + }, + restripe: function(data) { // :even and :odd are reversed because jquery counts from 0 and // we count from 1, so we're out of sync.