Commit 1b1fb73c authored by webchick's avatar webchick
Browse files

#623320 by rfay: Implement AJAX 'css' command in misc/ajax.js (with tests).

parent 89f12126
...@@ -395,6 +395,13 @@ Drupal.ajax.prototype.commands = { ...@@ -395,6 +395,13 @@ Drupal.ajax.prototype.commands = {
alert(response.text, response.title); 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. * Command to set the settings that will be used for other commands in this response.
*/ */
......
...@@ -112,7 +112,10 @@ class AJAXCommandsTestCase extends AJAXTestCase { ...@@ -112,7 +112,10 @@ class AJAXCommandsTestCase extends AJAXTestCase {
$command = $commands[1]; $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"); $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. // Tests the 'data' command.
$commands = $this->drupalPostAJAX($form_path, $edit, 'data_command_example'); $commands = $this->drupalPostAJAX($form_path, $edit, 'data_command_example');
......
...@@ -149,11 +149,9 @@ function ajax_forms_test_ajax_commands_form($form, &$form_state) { ...@@ -149,11 +149,9 @@ function ajax_forms_test_ajax_commands_form($form, &$form_state) {
); );
// Shows the AJAX 'css' command. // Shows the AJAX 'css' command.
// @todo Note that this won't work until http://drupal.org/node/623320 lands.
$form['css_command_example'] = array( $form['css_command_example'] = array(
'#title' => t("AJAX CSS: Choose the color you'd like the '#box' div to be."), '#value' => t("Set the the '#box' div to be blue."),
'#type' => 'select', '#type' => 'submit',
'#options' => array('green' => 'green', 'blue' => 'blue'),
'#ajax' => array( '#ajax' => array(
'callback' => 'ajax_forms_test_advanced_commands_css_callback', 'callback' => 'ajax_forms_test_advanced_commands_css_callback',
), ),
...@@ -289,7 +287,7 @@ function ajax_forms_test_advanced_commands_changed_asterisk_callback($form, $for ...@@ -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) { function ajax_forms_test_advanced_commands_css_callback($form, $form_state) {
$selector = '#css_div'; $selector = '#css_div';
$color = $form_state['values']['css_command_example']; $color = 'blue';
$commands = array(); $commands = array();
$commands[] = ajax_command_css($selector, array('background-color' => $color)); $commands[] = ajax_command_css($selector, array('background-color' => $color));
......
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