Problem/Motivation
Drupal.ajax.insert javascript method can only insert returned markup into the page once. An ajax command such as the following:
ajax_command_replace('div.class', '<div class="class">Some Content</div>');
Will replace the first occurrence of div.class but remove all of the others.
Proposed resolution
This behaviour happens because in ajax.js a jQuery object is passed to the insert method, rather than the html. When this happens jQuery prevents the object from being inserted twice, but this is sometimes desired behaviour.
Rather than passing the jQuery object, pass the outerHTML.
Remaining tasks
Write patch.
User interface changes
None.
API changes
None.
Data model changes
None.
Comments
Comment #2
rlmumfordThis patch allows the replaceWith ajax command to work with multiple elements but breaks all effects because the new_content variable is no longer the object that is actually in the dom tree
Comment #3
rlmumfordThis patch fixes the effects and behaviours integrations broken by the last patch. The key portion of the patch is the following.
I did this this way as although some of the methods return the newly added jQuery objects, replaceWith returns the dom objects that were removed instead. This meant that something like
var new_elements = wrapper[method](new_content.prop('outerHTML'));was not going to work with behaviors and effects consistently.Comment #4
rlmumfordThis patch undoes the white space fixes that should not be included in this patch and makes sure that the new_element gets added to the list of new elements.