Index: includes/ajax.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/ajax.inc,v retrieving revision 1.25 diff -u -p -r1.25 ajax.inc --- includes/ajax.inc 27 Jan 2010 11:19:11 -0000 1.25 +++ includes/ajax.inc 28 Feb 2010 22:12:50 -0000 @@ -124,7 +124,7 @@ * selected automatically for the type of form widget being used, and * is only needed if you need to override the default behavior. * - #ajax['method']: The jQuery method to use to place the new HTML. - * Defaults to 'replace'. May be: 'replace', 'append', 'prepend', + * Defaults to 'replaceWith'. May be: 'replaceWith', 'append', 'prepend', * 'before', 'after', or 'html'. See the jQuery documentation for more * information on these methods. * - #ajax['progress']: Choose either a throbber or progress bar that is @@ -396,13 +396,16 @@ function ajax_deliver($page_callback_res } } else { - // Like normal page callbacks, simple AJAX callbacks can return html - // content, as a string or renderable array, to replace what was previously - // there in the wrapper. In this case, in addition to the content, we want - // to add the status messages, but inside the new wrapper, so that they get - // replaced on subsequent AJAX calls for the same wrapper. + // Like normal page callbacks, simple AJAX callbacks can return HTML + // content, as a string or render array. This HTML is inserted in some + // relationship to #ajax['wrapper'], as determined by which jQuery DOM + // manipulation method is used. The method used is specified by + // #ajax['method']. The default method is 'replaceWith', which completely + // replaces the old wrapper element and its content with the new HTML. $html = is_string($page_callback_result) ? $page_callback_result : drupal_render($page_callback_result); - $commands[] = ajax_command_replace(NULL, $html); + $commands[] = ajax_command_insert(NULL, $html); + // Add the status messages inside the new content's wrapper element, so that + // on subsequent AJAX requests, it is treated as old content. $commands[] = ajax_command_prepend(NULL, theme('status_messages')); } ajax_render($commands); @@ -481,7 +484,7 @@ function ajax_process_form($element, &$f 'selector' => '#' . $element['#id'], 'effect' => 'none', 'speed' => 'none', - 'method' => 'replace', + 'method' => 'replaceWith', 'progress' => array('type' => 'throbber'), 'formPath' => implode('/', $element['#array_parents']), ); @@ -548,6 +551,37 @@ function ajax_command_alert($text) { } /** + * Creates a Drupal AJAX 'insert' command using the method in #ajax['method']. + * + * This command instructs the client to use one of jQuery's DOM manipulation + * methods to insert the given HTML. The client will use the method specified in + * the #ajax['method'] variable of the element that triggered the request. + * + * This command is implemented by Drupal.ajax.prototype.commands.insert() + * defined in misc/ajax.js. + * + * @param $selector + * A jQuery selector string. If the command is a response to a request from + * an #ajax form element then this value can be NULL. + * @param $html + * The data to use with the jQuery method. + * @param $settings + * An optional array of settings that will be used for this command only. + * + * @return + * An array suitable for use with the ajax_render() function. + */ +function ajax_command_insert($selector, $html, $settings = NULL) { + return array( + 'command' => 'insert', + 'method' => NULL, + 'selector' => $selector, + 'data' => $html, + 'settings' => $settings, + ); +} + +/** * Creates a Drupal AJAX 'insert/replaceWith' command. * * The 'insert/replaceWith' command instructs the client to use jQuery's Index: misc/ajax.js =================================================================== RCS file: /cvs/drupal/drupal/misc/ajax.js,v retrieving revision 1.10 diff -u -p -r1.10 ajax.js --- misc/ajax.js 3 Feb 2010 08:23:12 -0000 1.10 +++ misc/ajax.js 28 Feb 2010 22:12:50 -0000 @@ -93,7 +93,7 @@ Drupal.ajax = function (base, element, e selector: '#' + base, effect: 'none', speed: 'slow', - method: 'replace', + method: 'replaceWith', progress: { type: 'bar', message: 'Please wait...' @@ -323,6 +323,12 @@ Drupal.ajax.prototype.commands = { var method = response.method || ajax.method; var effect = ajax.getEffect(response); + // 'replace' is deprecated in favor of 'replaceWith', but continue to + // support Drupal modules using the older method name. + if (method == 'replace') { + method = 'replaceWith'; + } + // Manually insert HTML into the jQuery object, using $() directly crashes // Safari with long string lengths. http://dev.jquery.com/ticket/3178 var new_content = $('
').html(response.data); Index: modules/field/field.form.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/field/field.form.inc,v retrieving revision 1.42 diff -u -p -r1.42 field.form.inc --- modules/field/field.form.inc 12 Feb 2010 05:38:09 -0000 1.42 +++ modules/field/field.form.inc 28 Feb 2010 22:12:51 -0000 @@ -220,7 +220,6 @@ function field_multiple_value_form($fiel '#ajax' => array( 'callback' => 'field_add_more_js', 'wrapper' => $wrapper_id, - 'method' => 'replace', 'effect' => 'fade', ), // The field_add_more_submit() and field_add_more_js() handlers will Index: modules/file/file.module =================================================================== RCS file: /cvs/drupal/drupal/modules/file/file.module,v retrieving revision 1.19 diff -u -p -r1.19 file.module --- modules/file/file.module 11 Feb 2010 17:44:47 -0000 1.19 +++ modules/file/file.module 28 Feb 2010 22:12:51 -0000 @@ -351,7 +351,6 @@ function file_managed_file_process($elem $ajax_settings = array( 'path' => 'file/ajax/' . implode('/', $element['#parents']) . '/' . $form['form_build_id']['#value'], 'wrapper' => $element['#id'] . '-ajax-wrapper', - 'method' => 'replace', 'effect' => 'fade', 'progress' => array( 'type' => $element['#progress_indicator'], Index: modules/poll/poll.module =================================================================== RCS file: /cvs/drupal/drupal/modules/poll/poll.module,v retrieving revision 1.338 diff -u -p -r1.338 poll.module --- modules/poll/poll.module 2 Feb 2010 07:39:21 -0000 1.338 +++ modules/poll/poll.module 28 Feb 2010 22:12:51 -0000 @@ -299,7 +299,6 @@ function poll_form($node, &$form_state) '#ajax' => array( 'callback' => 'poll_choice_js', 'wrapper' => 'poll-choices', - 'method' => 'replace', 'effect' => 'fade', ), );