Index: misc/ajax.js =================================================================== RCS file: /cvs/drupal/drupal/misc/ajax.js,v retrieving revision 1.17 diff -u -r1.17 ajax.js --- misc/ajax.js 16 May 2010 19:08:08 -0000 1.17 +++ misc/ajax.js 13 Jun 2010 00:42:59 -0000 @@ -321,13 +321,33 @@ insert: function (ajax, response, status) { // Get information from the response. If it is not there, default to // our presets. - var wrapper = response.selector ? $(response.selector) : $(ajax.wrapper); + var wrapper = $(response.selector || ajax.wrapper); var method = response.method || ajax.method; var effect = ajax.getEffect(response); - // Manually insert HTML into the jQuery object, using $() directly crashes - // Safari with long string lengths. http://dev.jquery.com/ticket/3178 + // Using $() directly does not work if response.data contains text nodes at + // the toplevel. var new_content = $('
').html(response.data); + var hidden_content = $('.ajax-new-content', new_content); + var needs_wrapper = false; + // Immediately hide the new content if we're using any effects. + if (effect.showEffect != 'show') { + if (!hidden_content.length) { + // Wrap new contents in a div if response.data contains text nodes at + // the toplevel. + if (new_content.contents().filter(function() { return this.nodeType == 3; }).length) { + needs_wrapper = true; + hidden_content = new_content; + } + else { + hidden_content = new_content.children(); + } + } + hidden_content.hide(); + } + if (!need_wrapper) { + new_content = new_content.contents(); + } // If removing content from the wrapper, detach behaviors first. switch (method) { @@ -343,20 +363,13 @@ // Add the new content to the page. wrapper[method](new_content); - // Immediately hide the new content if we're using any effects. - if (effect.showEffect != 'show') { - new_content.hide(); - } - - // Determine which effect to use and what content will receive the - // effect, then show the new content. - if ($('.ajax-new-content', new_content).length > 0) { - $('.ajax-new-content', new_content).hide(); - new_content.show(); - $('.ajax-new-content', new_content)[effect.showEffect](effect.showSpeed); - } - else if (effect.showEffect != 'show') { - new_content[effect.showEffect](effect.showSpeed); + // If we're using any effects apply it to the hidden content. + if (effect.showEffect != 'show' && hidden_content.length > 0) { + hidden_content[effect.showEffect](effect.showSpeed, function() { + if (needs_wrapper) { + hidden_content.unwrap(); + } + }); } // Attach all JavaScript behaviors to the new content, if it was successfully