summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEarl Miles2009-06-12 23:55:45 (GMT)
committer Earl Miles2009-06-12 23:55:45 (GMT)
commit758ce4d2a7e5d344e8899556516d64f06d4ea9b2 (patch)
tree869116131a1ae522db7839a7f0a203d32c3d0580
parent8f9546390d1c5e07a15add6a9ad1939252401598 (diff)
#478438 by nickl: Allow passing items to the data() element.
-rw-r--r--CHANGELOG.txt1
-rw-r--r--includes/ajax.inc27
-rw-r--r--js/ajax-responder.js4
3 files changed, 32 insertions, 0 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 4fe0531..6d842d0 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 4f8a423..d3a9e2d 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:
*
@@ -295,6 +300,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.
*
* This is usually used after a table has been modifed by a replace or append
diff --git a/js/ajax-responder.js b/js/ajax-responder.js
index 5dfa9b2..3e2084e 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.