diff --git a/misc/ajax.js b/misc/ajax.js index c944ebb..5aecdf8 100644 --- a/misc/ajax.js +++ b/misc/ajax.js @@ -517,20 +517,6 @@ Drupal.ajax.prototype.commands = { var new_content_wrapped = $('
').html(response.data); var new_content = new_content_wrapped.contents(); - // For legacy reasons, the effects processing code assumes that new_content - // consists of a single top-level element. Also, it has not been - // sufficiently tested whether attachBehaviors() can be successfully called - // with a context object that includes top-level text nodes. However, to - // give developers full control of the HTML appearing in the page, and to - // enable Ajax content to be inserted in places where DIV elements are not - // allowed (e.g., within TABLE, TR, and SPAN parents), we check if the new - // content satisfies the requirement of a single top-level element, and - // only use the container DIV created above when it doesn't. For more - // information, please see http://drupal.org/node/736066. - if (new_content.length != 1 || new_content.get(0).nodeType != 1) { - new_content = new_content_wrapped; - } - // If removing content from the wrapper, detach behaviors first. switch (method) { case 'html': @@ -545,28 +531,43 @@ Drupal.ajax.prototype.commands = { // 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); - } - // Attach all JavaScript behaviors to the new content, if it was successfully // added to the page, this if statement allows #ajax['wrapper'] to be // optional. if (new_content.parents('html').length > 0) { // Apply any settings from the returned JSON if available. var settings = response.settings || ajax.settings || Drupal.settings; + + // For legacy reasons, the effects processing code assumes that new_content + // consists of a single top-level element. Also, it has not been + // sufficiently tested whether attachBehaviors() can be successfully called + // with a context object that includes top-level text nodes. However, to + // give developers full control of the HTML appearing in the page, and to + // enable Ajax content to be inserted in places where DIV elements are not + // allowed (e.g., within TABLE, TR, and SPAN parents), we check if the new + // content satisfies the requirement of a single top-level element, and + // only use the container DIV created above when it doesn't. For more + // information, please see http://drupal.org/node/736066. + if (new_content.length != 1 || new_content.get(0).nodeType != 1) { + new_content = new_content.parent(); + } + + // 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); + } + Drupal.attachBehaviors(new_content, settings); } },