diff --git a/misc/ajax.js b/misc/ajax.js index 9a85ee5e0ad..b1688e0d464 100644 --- a/misc/ajax.js +++ b/misc/ajax.js @@ -395,6 +395,13 @@ Drupal.ajax.prototype.commands = { alert(response.text, response.title); }, + /** + * Command to provide the jQuery css() function. + */ + css: function (ajax, response, status) { + $(response.selector).css(response.argument); + }, + /** * Command to set the settings that will be used for other commands in this response. */ diff --git a/modules/simpletest/tests/ajax.test b/modules/simpletest/tests/ajax.test index 580cd4addc3..13e566bbc18 100644 --- a/modules/simpletest/tests/ajax.test +++ b/modules/simpletest/tests/ajax.test @@ -112,7 +112,10 @@ class AJAXCommandsTestCase extends AJAXTestCase { $command = $commands[1]; $this->assertTrue($command['command'] == 'changed' && $command['selector'] == '#changed_div' && $command['asterisk'] == '#changed_div_mark_this', "'changed' AJAX command (with asterisk) issued with correct selector"); - // 'css' command will go here when it is implemented. + // Tests the 'css' command. + $commands = $this->drupalPostAJAX($form_path, $edit, 'css_command_example'); + $command = $commands[1]; + $this->assertTrue($command['command'] == 'css' && $command['selector'] == '#css_div' && $command['argument']['background-color'] == 'blue', "'css' AJAX command issued with correct selector"); // Tests the 'data' command. $commands = $this->drupalPostAJAX($form_path, $edit, 'data_command_example'); diff --git a/modules/simpletest/tests/ajax_forms_test.module b/modules/simpletest/tests/ajax_forms_test.module index a0dcfc0e0ea..176f0697d25 100644 --- a/modules/simpletest/tests/ajax_forms_test.module +++ b/modules/simpletest/tests/ajax_forms_test.module @@ -149,11 +149,9 @@ function ajax_forms_test_ajax_commands_form($form, &$form_state) { ); // Shows the AJAX 'css' command. - // @todo Note that this won't work until http://drupal.org/node/623320 lands. $form['css_command_example'] = array( - '#title' => t("AJAX CSS: Choose the color you'd like the '#box' div to be."), - '#type' => 'select', - '#options' => array('green' => 'green', 'blue' => 'blue'), + '#value' => t("Set the the '#box' div to be blue."), + '#type' => 'submit', '#ajax' => array( 'callback' => 'ajax_forms_test_advanced_commands_css_callback', ), @@ -289,7 +287,7 @@ function ajax_forms_test_advanced_commands_changed_asterisk_callback($form, $for */ function ajax_forms_test_advanced_commands_css_callback($form, $form_state) { $selector = '#css_div'; - $color = $form_state['values']['css_command_example']; + $color = 'blue'; $commands = array(); $commands[] = ajax_command_css($selector, array('background-color' => $color));