Skip to content
Snippets Groups Projects
Commit 1b1fb73c authored by Angie Byron's avatar Angie Byron
Browse files

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

parent 89f12126
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -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));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment